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