Mercurial > emacs
annotate lisp/thumbs.el @ 56408:80c108035a10
Regenerated.
author | Bill Wohler <wohler@newt.com> |
---|---|
date | Tue, 13 Jul 2004 03:45:02 +0000 |
parents | c5c73c8c2b3e |
children | ff141f26a0cb 4c90ffeb71c5 |
rev | line source |
---|---|
54186 | 1 ;;; thumbs.el --- Thumbnails previewer for images files |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
2 |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
3 ;; Copyright 2004 Free Software Foundation, Inc |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
4 |
54186 | 5 ;; Author: Jean-Philippe Theberge <jphiltheberge@videotron.ca> |
6 ;; Keywords: Multimedia | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
24 ;; |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
25 ;; Thanks: Alex Schroeder <alex@gnu.org> for maintaining the package at some time |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
26 ;; The peoples at #emacs@freenode.net for numerous help |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
27 ;; RMS for emacs and the GNU project. |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
28 ;; |
54186 | 29 |
30 ;;; Commentary: | |
31 | |
32 ;; This package create two new mode: thumbs-mode and | |
33 ;; thumbs-view-image-mode. It is used for images browsing and viewing | |
34 ;; from within emacs. Minimal image manipulation functions are also | |
35 ;; available via external programs. | |
36 ;; | |
37 ;; The 'convert' program from 'ImageMagick' | |
38 ;; [URL:http://www.imagemagick.org/] is required. | |
39 ;; | |
40 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
41 ;; CHANGELOG | |
42 ;; | |
43 ;; This is version 2.0 | |
44 ;; | |
45 ;; USAGE | |
46 ;; | |
47 ;; Type M-x thumbs RET DIR RET to view the directory DIR in Thumbs mode. | |
48 ;; That should be a directory containing image files. | |
49 ;; from dired, C-t m enter in thumbs-mode with all marked files | |
50 ;; C-t a enter in thumbs-mode with all files in current-directory | |
51 ;; In thumbs-mode, pressing <return> on a image will bring you in image view mode | |
52 ;; for that image. C-h m will give you a list of available keybinding. | |
53 | |
54 ;;; History: | |
55206
c2c29cafaa74
(time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54193
diff
changeset
|
55 ;; |
54186 | 56 |
57 ;;; Code: | |
58 | |
59 (require 'dired) | |
60 | |
61 ;; CUSTOMIZATIONS | |
62 | |
63 (defgroup thumbs nil | |
64 "Thumbnails previewer." | |
65 :group 'multimedia) | |
66 | |
67 (defcustom thumbs-thumbsdir | |
68 (expand-file-name "~/.emacs-thumbs") | |
69 "*Directory to store thumbnails." | |
70 :type 'directory | |
71 :group 'thumbs) | |
72 | |
73 (defcustom thumbs-geometry "100x100" | |
74 "*Size of thumbnails." | |
75 :type 'string | |
76 :group 'thumbs) | |
77 | |
78 (defcustom thumbs-per-line 5 | |
79 "*Number of thumbnails per line to show in directory." | |
80 :type 'string | |
81 :group 'thumbs) | |
82 | |
83 (defcustom thumbs-thumbsdir-max-size 50000000 | |
84 "Max size for thumbnails directory. | |
85 When it reach that size (in bytes), a warning is send." | |
86 :type 'string | |
87 :group 'thumbs) | |
88 | |
89 (defcustom thumbs-conversion-program | |
90 (if (equal 'windows-nt system-type) | |
91 "convert.exe" | |
92 (or (executable-find "convert") | |
93 "/usr/X11R6/bin/convert")) | |
94 "*Name of conversion program for thumbnails generation. | |
95 It must be 'convert'." | |
96 :type 'string | |
97 :group 'thumbs) | |
98 | |
99 (defcustom thumbs-setroot-command | |
100 "xloadimage -onroot -fullscreen *" | |
101 "Command to set the root window." | |
102 :type 'string | |
103 :group 'thumbs) | |
104 | |
105 (defcustom thumbs-relief 5 | |
106 "*Size of button-like border around thumbnails." | |
107 :type 'string | |
108 :group 'thumbs) | |
109 | |
110 (defcustom thumbs-margin 2 | |
111 "*Size of the margin around thumbnails. | |
112 This is where you see the cursor." | |
113 :type 'string | |
114 :group 'thumbs) | |
115 | |
116 (defcustom thumbs-thumbsdir-auto-clean t | |
117 "If set, delete older file in the thumbnails directory. | |
118 Deletion is done at load time when the directory size is bigger | |
119 than 'thumbs-thumbsdir-max-size'." | |
120 :type 'boolean | |
121 :group 'thumbs) | |
122 | |
123 (defcustom thumbs-image-resizing-step 10 | |
124 "Step by wich to resize image." | |
125 :type 'string | |
126 :group 'thumbs) | |
127 | |
128 (defcustom thumbs-temp-dir | |
129 "/tmp/" | |
130 "Temporary directory to use. | |
131 Leaving it to default '/tmp/' can let another user | |
132 see some of your images." | |
133 :type 'directory | |
134 :group 'thumbs) | |
135 | |
136 (defcustom thumbs-temp-prefix "emacsthumbs" | |
137 "Prefix to add to temp files." | |
138 :type 'string | |
139 :group 'thumbs) | |
140 | |
141 ;; Initialize some variable, for later use. | |
55206
c2c29cafaa74
(time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54193
diff
changeset
|
142 (defvar thumbs-temp-file |
c2c29cafaa74
(time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54193
diff
changeset
|
143 (concat thumbs-temp-dir thumbs-temp-prefix) |
54186 | 144 "Temporary filesname for images.") |
145 | |
55206
c2c29cafaa74
(time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54193
diff
changeset
|
146 (defvar thumbs-current-tmp-filename |
c2c29cafaa74
(time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54193
diff
changeset
|
147 nil |
54186 | 148 "Temporary filename of current image.") |
55206
c2c29cafaa74
(time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54193
diff
changeset
|
149 (defvar thumbs-current-image-filename |
54186 | 150 nil |
151 "Filename of current image.") | |
55206
c2c29cafaa74
(time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54193
diff
changeset
|
152 (defvar thumbs-current-image-size |
54186 | 153 nil |
154 "Size of current image.") | |
55206
c2c29cafaa74
(time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54193
diff
changeset
|
155 (defvar thumbs-image-num |
54186 | 156 nil |
157 "Number of current image.") | |
55206
c2c29cafaa74
(time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54193
diff
changeset
|
158 (defvar thumbs-current-dir |
54186 | 159 nil |
160 "Current directory.") | |
55206
c2c29cafaa74
(time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54193
diff
changeset
|
161 (defvar thumbs-markedL |
54186 | 162 nil |
163 "List of marked files.") | |
164 | |
165 ;; Make sure auto-image-file-mode is ON. | |
166 (auto-image-file-mode t) | |
167 | |
168 ;; Create the thumbs directory if it does not exists. | |
169 (setq thumbs-thumbsdir (expand-file-name thumbs-thumbsdir)) | |
170 | |
171 (when (not (file-directory-p thumbs-thumbsdir)) | |
172 (progn | |
173 (make-directory thumbs-thumbsdir) | |
174 (message "Creating thumbnails directory"))) | |
175 | |
176 (defvar thumbs-gensym-counter 0) | |
177 | |
178 (defun thumbs-gensym (&optional arg) | |
179 "Generate a new uninterned symbol. | |
180 The name is made by appending a number to PREFIX, default \"Thumbs\"." | |
181 (let ((prefix (if (stringp arg) arg "Thumbs")) | |
182 (num (if (integerp arg) arg | |
55206
c2c29cafaa74
(time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54193
diff
changeset
|
183 (prog1 |
54186 | 184 thumbs-gensym-counter |
185 (setq thumbs-gensym-counter (1+ thumbs-gensym-counter)))))) | |
186 (make-symbol (format "%s%d" prefix num)))) | |
187 | |
188 (defun thumbs-cleanup-thumbsdir () | |
189 "Clean the thumbnails directory. | |
190 If the total size of all files in 'thumbs-thumbsdir' is bigger than | |
191 'thumbs-thumbsdir-max-size', files are deleted until the max size is | |
192 reached." | |
193 (let* ((filesL | |
194 (sort | |
195 (mapcar | |
196 (lambda (f) | |
197 (let ((fattribsL (file-attributes f))) | |
198 `(,(nth 4 fattribsL) ,(nth 7 fattribsL) ,f))) | |
199 (directory-files thumbs-thumbsdir t (image-file-name-regexp))) | |
200 '(lambda (l1 l2) (time-less-p (car l1)(car l2))))) | |
201 (dirsize (apply '+ (mapcar (lambda (x) (cadr x)) filesL)))) | |
202 (while (> dirsize thumbs-thumbsdir-max-size) | |
203 (progn | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
204 (message "Deleting file %s" (cadr (cdar filesL)))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
205 (delete-file (cadr (cdar filesL))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
206 (setq dirsize (- dirsize (car (cdar filesL)))) |
54186 | 207 (setq filesL (cdr filesL))))) |
208 | |
209 ;; Check the thumbsnail directory size and clean it if necessary. | |
210 (when thumbs-thumbsdir-auto-clean | |
211 (thumbs-cleanup-thumbsdir)) | |
212 | |
213 (defun thumbs-call-convert (filein fileout action | |
214 &optional arg output-format action-prefix) | |
215 "Call the convert program. | |
216 FILEIN is the input file, | |
217 FILEOUT is the output file, | |
218 ACTION is the command to send to convert. | |
219 Optional argument are: | |
220 ARG any arguments to the ACTION command, | |
221 OUTPUT-FORMAT is the file format to output, default is jpeg | |
222 ACTION-PREFIX is the symbol to place before the ACTION command | |
223 (default to '-' but can sometime be '+')." | |
224 (let ((command (format "%s %s%s %s \"%s\" \"%s:%s\"" | |
225 thumbs-conversion-program | |
226 (or action-prefix "-") | |
227 action | |
228 (or arg "") | |
229 filein | |
230 (or output-format "jpeg") | |
231 fileout))) | |
232 (shell-command command))) | |
233 | |
234 (defun thumbs-increment-image-size-element (n d) | |
235 "Increment number N by D percent." | |
236 (round (+ n (/ (* d n) 100)))) | |
237 | |
238 (defun thumbs-decrement-image-size-element (n d) | |
239 "Decrement number N by D percent." | |
240 (round (- n (/ (* d n) 100)))) | |
241 | |
242 (defun thumbs-increment-image-size (s) | |
243 "Increment S (a cons of width x heigh)." | |
244 (cons | |
245 (thumbs-increment-image-size-element (car s) | |
246 thumbs-image-resizing-step) | |
247 (thumbs-increment-image-size-element (cdr s) | |
248 thumbs-image-resizing-step))) | |
55206
c2c29cafaa74
(time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54193
diff
changeset
|
249 |
54186 | 250 (defun thumbs-decrement-image-size (s) |
251 "Decrement S (a cons of width x heigh)." | |
252 (cons | |
253 (thumbs-decrement-image-size-element (car s) | |
254 thumbs-image-resizing-step) | |
255 (thumbs-decrement-image-size-element (cdr s) | |
256 thumbs-image-resizing-step))) | |
257 | |
258 (defun thumbs-resize-image (&optional increment size) | |
259 "Resize image in current buffer. | |
260 if INCREMENT is set, make the image bigger, else smaller. | |
261 Or, alternatively, a SIZE may be specified." | |
262 (interactive) | |
263 ;; cleaning of old temp file | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
264 (condition-case nil |
54186 | 265 (apply 'delete-file |
266 (directory-files | |
267 thumbs-temp-dir t | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
268 thumbs-temp-prefix)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
269 (error nil)) |
54186 | 270 (let ((buffer-read-only nil) |
271 (x (if size | |
272 size | |
273 (if increment | |
274 (thumbs-increment-image-size | |
275 thumbs-current-image-size) | |
276 (thumbs-decrement-image-size | |
277 thumbs-current-image-size)))) | |
278 (tmp (format "%s%s.jpg" thumbs-temp-file (thumbs-gensym)))) | |
279 (erase-buffer) | |
280 (thumbs-call-convert thumbs-current-image-filename | |
281 tmp "sample" | |
282 (concat (number-to-string (car x)) "x" | |
283 (number-to-string (cdr x)))) | |
284 (thumbs-insert-image tmp 'jpeg 0) | |
285 (setq thumbs-current-tmp-filename tmp))) | |
286 | |
287 (defun thumbs-resize-interactive (width height) | |
288 "Resize Image interactively to specified WIDTH and HEIGHT." | |
289 (interactive "nWidth: \nnHeight: ") | |
290 (thumbs-resize-image nil (cons width height))) | |
55206
c2c29cafaa74
(time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54193
diff
changeset
|
291 |
54186 | 292 (defun thumbs-resize-image-size-down () |
293 "Resize image (smaller)." | |
294 (interactive) | |
295 (thumbs-resize-image nil)) | |
296 | |
297 (defun thumbs-resize-image-size-up () | |
298 "Resize image (bigger)." | |
299 (interactive) | |
300 (thumbs-resize-image t)) | |
301 | |
302 (defun thumbs-thumbname (img) | |
303 "Return a thumbnail name for the image IMG." | |
304 (concat thumbs-thumbsdir "/" | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
305 (subst-char-in-string |
54186 | 306 ?\ ?\_ |
307 (apply | |
308 'concat | |
309 (split-string | |
310 (expand-file-name img) "/"))))) | |
311 | |
312 (defun thumbs-make-thumb (img) | |
313 "Create the thumbnail for IMG." | |
314 (let* ((fn (expand-file-name img)) | |
315 (tn (thumbs-thumbname img))) | |
316 (if (or (not (file-exists-p tn)) | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
317 ;; This is not the right fix, but I don't understand |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
318 ;; the external program or why it produces a geometry |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
319 ;; unequal to the one requested -- rms. |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
320 ;;; (not (equal (thumbs-file-size tn) thumbs-geometry)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
321 ) |
54186 | 322 (thumbs-call-convert fn tn "sample" thumbs-geometry)) |
323 tn)) | |
55206
c2c29cafaa74
(time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54193
diff
changeset
|
324 |
54186 | 325 (defun thumbs-image-type (img) |
326 "Return image type from filename IMG." | |
327 (cond ((string-match ".*\\.jpe?g\\'" img) 'jpeg) | |
328 ((string-match ".*\\.xpm\\'" img) 'xpm) | |
329 ((string-match ".*\\.xbm\\'" img) 'xbm) | |
330 ((string-match ".*\\.gif\\'" img) 'gif) | |
331 ((string-match ".*\\.bmp\\'" img) 'bmp) | |
332 ((string-match ".*\\.png\\'" img) 'png) | |
333 ((string-match ".*\\.tiff?\\'" img) 'tiff))) | |
334 | |
335 (defun thumbs-file-size (img) | |
336 (let ((i (image-size (find-image `((:type ,(thumbs-image-type img) :file ,img))) t))) | |
337 (concat (number-to-string (round (car i))) | |
338 "x" | |
339 (number-to-string (round (cdr i)))))) | |
55206
c2c29cafaa74
(time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54193
diff
changeset
|
340 |
54186 | 341 ;;;###autoload |
342 (defun thumbs-find-thumb (img) | |
343 "Display the thumbnail for IMG." | |
344 (interactive "f") | |
345 (find-file (thumbs-make-thumb img))) | |
346 | |
347 (defun thumbs-insert-image (img type relief &optional marked) | |
348 "Insert image IMG at point. | |
349 TYPE and RELIEF will be used in constructing the image; see `image' | |
350 in the emacs-lisp manual for further documentation. | |
351 if MARKED is non-nil, the image is marked." | |
352 (let ((i `(image :type ,type | |
353 :file ,img | |
354 :relief ,relief | |
355 :conversion ,(if marked 'disabled) | |
356 :margin ,thumbs-margin))) | |
357 (insert-image i) | |
358 (setq thumbs-current-image-size | |
359 (image-size i t)))) | |
360 | |
361 (defun thumbs-insert-thumb (img &optional marked) | |
362 "Insert the thumbnail for IMG at point. | |
363 if MARKED is non-nil, the image is marked" | |
364 (thumbs-insert-image | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
365 (thumbs-make-thumb img) 'jpeg thumbs-relief marked) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
366 (put-text-property (1- (point)) (point) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
367 'thumb-image-file img)) |
54186 | 368 |
369 (defun thumbs-do-thumbs-insertion (L) | |
370 "Insert all thumbs in list L." | |
371 (let ((i 0)) | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
372 (dolist (img L) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
373 (thumbs-insert-thumb img |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
374 (member img thumbs-markedL)) |
54186 | 375 (when (= 0 (mod (setq i (1+ i)) thumbs-per-line)) |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
376 (newline))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
377 (unless (bobp) (newline)))) |
54186 | 378 |
379 (defun thumbs-show-thumbs-list (L &optional buffer-name same-window) | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
380 (when (not (display-images-p)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
381 (error "Images are not supported in this Emacs session")) |
54186 | 382 (funcall (if same-window 'switch-to-buffer 'pop-to-buffer) |
383 (or buffer-name "*THUMB-View*")) | |
384 (let ((inhibit-read-only t)) | |
385 (erase-buffer) | |
386 (thumbs-mode) | |
387 (thumbs-do-thumbs-insertion L) | |
388 (goto-char (point-min)) | |
389 (setq thumbs-current-dir default-directory) | |
390 (make-variable-buffer-local 'thumbs-current-dir))) | |
391 | |
392 ;;;###autoload | |
393 (defun thumbs-show-all-from-dir (dir &optional reg same-window) | |
394 "Make a preview buffer for all images in DIR. | |
395 Optional argument REG to select file matching a regexp, | |
396 and SAME-WINDOW to show thumbs in the same window." | |
397 (interactive "DDir: ") | |
398 (thumbs-show-thumbs-list | |
399 (directory-files dir t | |
400 (or reg (image-file-name-regexp))) | |
401 (concat "*Thumbs: " dir) same-window)) | |
402 | |
403 ;;;###autoload | |
404 (defun thumbs-dired-show-marked () | |
405 "In Dired, make a thumbs buffer with all marked files." | |
406 (interactive) | |
407 (thumbs-show-thumbs-list (dired-get-marked-files) nil t)) | |
408 | |
409 ;;;###autoload | |
410 (defun thumbs-dired-show-all () | |
411 "In dired, make a thumbs buffer with all files in current directory." | |
412 (interactive) | |
413 (thumbs-show-all-from-dir default-directory nil t)) | |
414 | |
415 ;;;###autoload | |
416 (defalias 'thumbs 'thumbs-show-all-from-dir) | |
417 | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
418 (defun thumbs-find-image (img &optional num otherwin) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
419 (funcall |
54186 | 420 (if otherwin 'switch-to-buffer-other-window 'switch-to-buffer) |
421 (concat "*Image: " (file-name-nondirectory img) " - " | |
422 (number-to-string (or num 0)) "*")) | |
423 (thumbs-view-image-mode) | |
424 (let ((inhibit-read-only t)) | |
425 (setq thumbs-current-image-filename img | |
426 thumbs-current-tmp-filename nil | |
427 thumbs-image-num (or num 0)) | |
428 (make-variable-buffer-local 'thumbs-current-image-filename) | |
429 (make-variable-buffer-local 'thumbs-current-tmp-filename) | |
430 (make-variable-buffer-local 'thumbs-current-image-size) | |
431 (make-variable-buffer-local 'thumbs-image-num) | |
432 (delete-region (point-min)(point-max)) | |
433 (thumbs-insert-image img (thumbs-image-type img) 0))) | |
434 | |
435 (defun thumbs-find-image-at-point (&optional img otherwin) | |
436 "Display image IMG for thumbnail at point. | |
437 use another window it OTHERWIN is t." | |
438 (interactive) | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
439 (let* ((i (or img (thumbs-current-image)))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
440 (thumbs-find-image i (point) otherwin))) |
54186 | 441 |
442 (defun thumbs-find-image-at-point-other-window () | |
443 "Display image for thumbnail at point in the preview buffer. | |
444 Open another window." | |
445 (interactive) | |
446 (thumbs-find-image-at-point nil t)) | |
447 | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
448 (defun thumbs-mouse-find-image (event) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
449 "Display image for thumbnail at mouse click EVENT." |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
450 (interactive "e") |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
451 (mouse-set-point event) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
452 (thumbs-find-image-at-point)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
453 |
54186 | 454 (defun thumbs-call-setroot-command (img) |
455 "Call the setroot program for IMG." | |
456 (run-hooks 'thumbs-before-setroot-hook) | |
457 (shell-command (replace-regexp-in-string | |
458 "\\*" | |
459 (shell-quote-argument (expand-file-name img)) | |
460 thumbs-setroot-command nil t)) | |
461 (run-hooks 'thumbs-after-setroot-hook)) | |
55206
c2c29cafaa74
(time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54193
diff
changeset
|
462 |
54186 | 463 (defun thumbs-set-image-at-point-to-root-window () |
464 "Set the image at point as the desktop wallpaper." | |
465 (interactive) | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
466 (thumbs-call-setroot-command |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
467 (thumbs-current-image))) |
54186 | 468 |
469 (defun thumbs-set-root () | |
470 "Set the current image as root." | |
471 (interactive) | |
472 (thumbs-call-setroot-command | |
473 (or thumbs-current-tmp-filename | |
474 thumbs-current-image-filename))) | |
475 | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
476 (defun thumbs-file-alist () |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
477 "Make an alist of elements (POS . FILENAME) for all images in thumb buffer." |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
478 (save-excursion |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
479 (let (list) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
480 (goto-char (point-min)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
481 (while (not (eobp)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
482 (if (thumbs-current-image) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
483 (push (cons (point-marker) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
484 (thumbs-current-image)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
485 list)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
486 (forward-char 1)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
487 list))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
488 |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
489 (defun thumbs-file-list () |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
490 "Make a list of file names for all images in thumb buffer." |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
491 (save-excursion |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
492 (let (list) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
493 (goto-char (point-min)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
494 (while (not (eobp)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
495 (if (thumbs-current-image) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
496 (push (thumbs-current-image) list)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
497 (forward-char 1)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
498 (nreverse list)))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
499 |
54186 | 500 (defun thumbs-delete-images () |
501 "Delete the image at point (and it's thumbnail) (or marked files if any)." | |
502 (interactive) | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
503 (let ((files (or thumbs-markedL (list (thumbs-current-image))))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
504 (if (yes-or-no-p (format "Really delete %d files? " (length files))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
505 (let ((thumbs-fileL (thumbs-file-alist)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
506 (inhibit-read-only t)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
507 (dolist (x files) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
508 (let (failure) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
509 (condition-case () |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
510 (progn |
54186 | 511 (delete-file x) |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
512 (delete-file (thumbs-thumbname x))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
513 (file-error (setq failure t))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
514 (unless failure |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
515 (when (rassoc x thumbs-fileL) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
516 (goto-char (car (rassoc x thumbs-fileL))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
517 (delete-region (point) (1+ (point)))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
518 (setq thumbs-markedL |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
519 (delq x thumbs-markedL))))))))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
520 |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
521 (defun thumbs-rename-images (newfile) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
522 "Rename the image at point (and it's thumbnail) (or marked files if any)." |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
523 (interactive "FRename to file or directory: ") |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
524 (let ((files (or thumbs-markedL (list (thumbs-current-image)))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
525 failures) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
526 (if (and (not (file-directory-p newfile)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
527 thumbs-markedL) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
528 (if (file-exists-p newfile) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
529 (error "Renaming marked files to file name `%s'" newfile) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
530 (make-directory newfile t))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
531 (if (yes-or-no-p (format "Really rename %d files? " (length files))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
532 (let ((thumbs-fileL (thumbs-file-alist)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
533 (inhibit-read-only t)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
534 (dolist (file files) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
535 (let (failure) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
536 (condition-case () |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
537 (if (file-directory-p newfile) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
538 (rename-file file |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
539 (expand-file-name |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
540 (file-name-nondirectory file) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
541 newfile)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
542 (rename-file file newfile)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
543 (file-error (setq failure t) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
544 (push file failures))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
545 (unless failure |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
546 (when (rassoc file thumbs-fileL) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
547 (goto-char (car (rassoc file thumbs-fileL))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
548 (delete-region (point) (1+ (point)))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
549 (setq thumbs-markedL |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
550 (delq file thumbs-markedL))))))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
551 (if failures |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
552 (display-warning 'file-error |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
553 (format "Rename failures for %s into %s" |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
554 failures newfile) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
555 :error)))) |
54186 | 556 |
557 (defun thumbs-kill-buffer () | |
558 "Kill the current buffer." | |
559 (interactive) | |
560 (let ((buffer (current-buffer))) | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
561 (condition-case nil |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
562 (delete-window (selected-window)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
563 (error nil)) |
54186 | 564 (kill-buffer buffer))) |
565 | |
566 (defun thumbs-show-image-num (num) | |
567 "Show the image with number NUM." | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
568 (let ((image-buffer (get-buffer-create "*Image*"))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
569 (let ((i (thumbs-current-image))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
570 (with-current-buffer image-buffer |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
571 (thumbs-insert-image i (thumbs-image-type i) 0)) |
55213
a911edb6dadf
(thumbs-delete-images): Fix formatting of prompt.
John Paul Wallington <jpw@pobox.com>
parents:
55206
diff
changeset
|
572 (setq thumbs-image-num num |
a911edb6dadf
(thumbs-delete-images): Fix formatting of prompt.
John Paul Wallington <jpw@pobox.com>
parents:
55206
diff
changeset
|
573 thumbs-current-image-filename i)))) |
54186 | 574 |
575 (defun thumbs-next-image () | |
576 "Show next image." | |
577 (interactive) | |
578 (let* ((i (1+ thumbs-image-num)) | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
579 (list (thumbs-file-alist)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
580 (l (caar list))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
581 (while (and (/= i thumbs-image-num) (not (assoc i list))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
582 (setq i (if (>= i l) 1 (1+ i)))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
583 (thumbs-show-image-num i))) |
54186 | 584 |
585 (defun thumbs-previous-image () | |
586 "Show the previous image." | |
587 (interactive) | |
588 (let* ((i (- thumbs-image-num 1)) | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
589 (list (thumbs-file-alist)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
590 (l (caar list))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
591 (while (and (/= i thumbs-image-num) (not (assoc i list))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
592 (setq i (if (<= i 1) l (1- i)))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
593 (thumbs-show-image-num i))) |
54186 | 594 |
595 (defun thumbs-redraw-buffer () | |
596 "Redraw the current thumbs buffer." | |
597 (let ((p (point)) | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
598 (inhibit-read-only t) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
599 (files (thumbs-file-list))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
600 (erase-buffer) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
601 (thumbs-do-thumbs-insertion files) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
602 (goto-char p))) |
55206
c2c29cafaa74
(time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54193
diff
changeset
|
603 |
54186 | 604 (defun thumbs-mark () |
605 "Mark the image at point." | |
606 (interactive) | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
607 (let ((elt (thumbs-current-image))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
608 (unless elt |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
609 (error "No image here")) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
610 (push elt thumbs-markedL) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
611 (let ((inhibit-read-only t)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
612 (delete-char 1) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
613 (thumbs-insert-thumb elt t))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
614 (when (eolp) (forward-char))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
615 |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
616 (defun thumbs-unmark () |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
617 "Unmark the image at point." |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
618 (interactive) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
619 (let ((elt (thumbs-current-image))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
620 (unless elt |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
621 (error "No image here")) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
622 (setq thumbs-markedL (delete elt thumbs-markedL)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
623 (let ((inhibit-read-only t)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
624 (delete-char 1) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
625 (thumbs-insert-thumb elt nil))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
626 (when (eolp) (forward-char))) |
55206
c2c29cafaa74
(time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54193
diff
changeset
|
627 |
54186 | 628 ;; Image modification routines |
629 | |
630 (defun thumbs-modify-image (action &optional arg) | |
631 "Call convert to do ACTION on image with argument ARG. | |
632 ACTION and ARG should be legal convert command." | |
633 (interactive "sAction: \nsValue: ") | |
634 ;; cleaning of old temp file | |
635 (mapc 'delete-file | |
636 (directory-files | |
637 thumbs-temp-dir | |
638 t | |
639 thumbs-temp-prefix)) | |
640 (let ((buffer-read-only nil) | |
641 (tmp (format "%s%s.jpg" thumbs-temp-file (thumbs-gensym)))) | |
642 (erase-buffer) | |
643 (thumbs-call-convert thumbs-current-image-filename | |
644 tmp | |
645 action | |
646 (or arg "")) | |
647 (thumbs-insert-image tmp 'jpeg 0) | |
648 (setq thumbs-current-tmp-filename tmp))) | |
649 | |
650 (defun thumbs-emboss-image (emboss) | |
651 "Emboss the image with value EMBOSS." | |
652 (interactive "nEmboss value: ") | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
653 (if (or (< emboss 3) (> emboss 31) (zerop (% emboss 2))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
654 (error "Arg must be an odd number between 3 and 31")) |
54186 | 655 (thumbs-modify-image "emboss" (number-to-string emboss))) |
656 | |
657 (defun thumbs-monochrome-image () | |
658 "Turn the image to monochrome." | |
659 (interactive) | |
660 (thumbs-modify-image "monochrome")) | |
661 | |
662 (defun thumbs-negate-image () | |
663 "Negate the image." | |
664 (interactive) | |
665 (thumbs-modify-image "negate")) | |
666 | |
667 (defun thumbs-rotate-left () | |
668 "Rotate the image 90 degrees counter-clockwise." | |
669 (interactive) | |
670 (thumbs-modify-image "rotate" "270")) | |
671 | |
672 (defun thumbs-rotate-right () | |
673 "Rotate the image 90 degrees clockwise." | |
674 (interactive) | |
675 (thumbs-modify-image "rotate" "90")) | |
676 | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
677 (defun thumbs-current-image () |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
678 "Return the name of the image file name at point." |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
679 (get-text-property (point) 'thumb-image-file)) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
680 |
54186 | 681 (defun thumbs-forward-char () |
682 "Move forward one image." | |
683 (interactive) | |
684 (forward-char) | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
685 (while (and (not (eobp)) (not (thumbs-current-image))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
686 (forward-char)) |
54186 | 687 (thumbs-show-name)) |
688 | |
689 (defun thumbs-backward-char () | |
690 "Move backward one image." | |
691 (interactive) | |
692 (forward-char -1) | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
693 (while (and (not (bobp)) (not (thumbs-current-image))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
694 (forward-char -1)) |
54186 | 695 (thumbs-show-name)) |
696 | |
697 (defun thumbs-forward-line () | |
698 "Move down one line." | |
699 (interactive) | |
700 (forward-line 1) | |
701 (thumbs-show-name)) | |
702 | |
703 (defun thumbs-backward-line () | |
704 "Move up one line." | |
705 (interactive) | |
706 (forward-line -1) | |
707 (thumbs-show-name)) | |
708 | |
709 (defun thumbs-show-name () | |
710 "Show the name of the current file." | |
711 (interactive) | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
712 (let ((f (thumbs-current-image))) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
713 (and f (message "%s [%s]" f (thumbs-file-size f))))) |
54186 | 714 |
715 (defun thumbs-save-current-image () | |
716 "Save the current image." | |
717 (interactive) | |
718 (let ((f (or thumbs-current-tmp-filename | |
719 thumbs-current-image-filename)) | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
720 (sa (read-from-minibuffer "Save image file as: " |
54186 | 721 thumbs-current-image-filename))) |
722 (copy-file f sa))) | |
723 | |
724 (defun thumbs-dired () | |
725 "Use `dired' on the current thumbs directory." | |
726 (interactive) | |
727 (dired thumbs-current-dir)) | |
728 | |
729 ;; thumbs-mode | |
730 | |
731 (defvar thumbs-mode-map | |
732 (let ((map (make-sparse-keymap))) | |
733 (define-key map [return] 'thumbs-find-image-at-point) | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
734 (define-key map [mouse-2] 'thumbs-mouse-find-image) |
54186 | 735 (define-key map [(meta return)] 'thumbs-find-image-at-point-other-window) |
736 (define-key map [(control return)] 'thumbs-set-image-at-point-to-root-window) | |
737 (define-key map [delete] 'thumbs-delete-images) | |
738 (define-key map [right] 'thumbs-forward-char) | |
739 (define-key map [left] 'thumbs-backward-char) | |
740 (define-key map [up] 'thumbs-backward-line) | |
741 (define-key map [down] 'thumbs-forward-line) | |
742 (define-key map "d" 'thumbs-dired) | |
743 (define-key map "m" 'thumbs-mark) | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
744 (define-key map "u" 'thumbs-unmark) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
745 (define-key map "R" 'thumbs-rename-images) |
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
746 (define-key map "x" 'thumbs-delete-images) |
54186 | 747 (define-key map "s" 'thumbs-show-name) |
748 (define-key map "q" 'thumbs-kill-buffer) | |
749 map) | |
750 "Keymap for `thumbs-mode'.") | |
751 | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
752 (put 'thumbs-mode 'mode-class 'special) |
54186 | 753 (define-derived-mode thumbs-mode |
754 fundamental-mode "thumbs" | |
755 "Preview images in a thumbnails buffer" | |
756 (make-variable-buffer-local 'thumbs-markedL) | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
757 (setq buffer-read-only t) |
54186 | 758 (setq thumbs-markedL nil)) |
759 | |
760 (defvar thumbs-view-image-mode-map | |
761 (let ((map (make-sparse-keymap))) | |
762 (define-key map [prior] 'thumbs-previous-image) | |
763 (define-key map [next] 'thumbs-next-image) | |
764 (define-key map "-" 'thumbs-resize-image-size-down) | |
765 (define-key map "+" 'thumbs-resize-image-size-up) | |
766 (define-key map "<" 'thumbs-rotate-left) | |
767 (define-key map ">" 'thumbs-rotate-right) | |
768 (define-key map "e" 'thumbs-emboss-image) | |
769 (define-key map "r" 'thumbs-resize-interactive) | |
770 (define-key map "s" 'thumbs-save-current-image) | |
771 (define-key map "q" 'thumbs-kill-buffer) | |
772 (define-key map "w" 'thunbs-set-root) | |
773 map) | |
774 "Keymap for `thumbs-view-image-mode'.") | |
775 | |
776 ;; thumbs-view-image-mode | |
55827
c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents:
55221
diff
changeset
|
777 (put 'thumbs-view-image-mode 'mode-class 'special) |
54186 | 778 (define-derived-mode thumbs-view-image-mode |
779 fundamental-mode "image-view-mode") | |
780 | |
781 ;;;###autoload | |
782 (defun thumbs-dired-setroot () | |
783 "In dired, Call the setroot program on the image at point." | |
784 (interactive) | |
785 (thumbs-call-setroot-command (dired-get-filename))) | |
786 | |
787 ;; Modif to dired mode map | |
788 (define-key dired-mode-map "\C-ta" 'thumbs-dired-show-all) | |
789 (define-key dired-mode-map "\C-tm" 'thumbs-dired-show-marked) | |
790 (define-key dired-mode-map "\C-tw" 'thumbs-dired-setroot) | |
791 | |
792 (provide 'thumbs) | |
793 | |
794 ;;; thumbs.el ends here | |
795 | |
796 | |
54193 | 797 ;;; arch-tag: f9ac1ef8-83fc-42c0-8069-1fae43fd2e5c |