Show a patch for Mule-UCS to make it byte-compiled
[emacs.git] / lisp / thumbs.el
blob0fa448d4d7a1e5aa8f8e7fac78e6837938344704
1 ;;; thumbs.el --- Thumbnails previewer for images files
3 ;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
5 ;; Author: Jean-Philippe Theberge <jphiltheberge@videotron.ca>
6 ;; Keywords: Multimedia
8 ;; This file is part of GNU Emacs.
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.
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.
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., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
25 ;; Thanks: Alex Schroeder <alex@gnu.org> for maintaining the package at some time
26 ;; The peoples at #emacs@freenode.net for numerous help
27 ;; RMS for emacs and the GNU project.
30 ;;; Commentary:
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.
37 ;; The 'convert' program from 'ImageMagick'
38 ;; [URL:http://www.imagemagick.org/] is required.
40 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41 ;; CHANGELOG
43 ;; This is version 2.0
45 ;; USAGE
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.
54 ;;; History:
57 ;;; Code:
59 (require 'dired)
61 ;; CUSTOMIZATIONS
63 (defgroup thumbs nil
64 "Thumbnails previewer."
65 :version "22.1"
66 :group 'multimedia)
68 (defcustom thumbs-thumbsdir "~/.emacs-thumbs"
69 "*Directory to store thumbnails."
70 :type 'directory
71 :group 'thumbs)
73 (defcustom thumbs-geometry "100x100"
74 "*Size of thumbnails."
75 :type 'string
76 :group 'thumbs)
78 (defcustom thumbs-per-line 5
79 "*Number of thumbnails per line to show in directory."
80 :type 'integer
81 :group 'thumbs)
83 (defcustom thumbs-thumbsdir-max-size 50000000
84 "Max size for thumbnails directory.
85 When it reaches that size (in bytes), a warning is sent."
86 :type 'integer
87 :group 'thumbs)
89 (defcustom thumbs-conversion-program
90 (if (eq system-type 'windows-nt)
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)
99 (defcustom thumbs-setroot-command
100 "xloadimage -onroot -fullscreen *"
101 "Command to set the root window."
102 :type 'string
103 :group 'thumbs)
105 (defcustom thumbs-relief 5
106 "*Size of button-like border around thumbnails."
107 :type 'integer
108 :group 'thumbs)
110 (defcustom thumbs-margin 2
111 "*Size of the margin around thumbnails.
112 This is where you see the cursor."
113 :type 'integer
114 :group 'thumbs)
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)
123 (defcustom thumbs-image-resizing-step 10
124 "Step by which to resize image."
125 :type 'integer
126 :group 'thumbs)
128 (defcustom thumbs-temp-dir temporary-file-directory
129 "Temporary directory to use.
130 Defaults to `temporary-file-directory'. Leaving it to
131 this value can let another user see some of your images."
132 :type 'directory
133 :group 'thumbs)
135 (defcustom thumbs-temp-prefix "emacsthumbs"
136 "Prefix to add to temp files."
137 :type 'string
138 :group 'thumbs)
140 ;; Initialize some variable, for later use.
141 (defvar thumbs-current-tmp-filename nil
142 "Temporary filename of current image.")
143 (make-variable-buffer-local 'thumbs-current-tmp-filename)
145 (defvar thumbs-current-image-filename nil
146 "Filename of current image.")
147 (make-variable-buffer-local 'thumbs-current-image-filename)
149 (defvar thumbs-current-image-size nil
150 "Size of current image.")
152 (defvar thumbs-image-num nil
153 "Number of current image.")
154 (make-variable-buffer-local 'thumbs-image-num)
156 (defvar thumbs-current-dir nil
157 "Current directory.")
159 (defvar thumbs-markedL nil
160 "List of marked files.")
162 (defalias 'thumbs-gensym
163 (if (fboundp 'gensym)
164 'gensym
165 ;; Copied from cl-macs.el
166 (defvar thumbs-gensym-counter 0)
167 (lambda (&optional prefix)
168 "Generate a new uninterned symbol.
169 The name is made by appending a number to PREFIX, default \"G\"."
170 (let ((pfix (if (stringp prefix) prefix "G"))
171 (num (if (integerp prefix) prefix
172 (prog1 thumbs-gensym-counter
173 (setq thumbs-gensym-counter
174 (1+ thumbs-gensym-counter))))))
175 (make-symbol (format "%s%d" pfix num))))))
177 (defsubst thumbs-temp-dir ()
178 (file-name-as-directory (expand-file-name thumbs-temp-dir)))
180 (defun thumbs-temp-file ()
181 "Return a unique temporary filename for an image."
182 (format "%s%s-%s.jpg"
183 (thumbs-temp-dir)
184 thumbs-temp-prefix
185 (thumbs-gensym "T")))
187 (defun thumbs-thumbsdir ()
188 "Return the current thumbnails directory (from `thumbs-thumbsdir').
189 Create the thumbnails directory if it does not exist."
190 (let ((thumbs-thumbsdir (file-name-as-directory
191 (expand-file-name thumbs-thumbsdir))))
192 (unless (file-directory-p thumbs-thumbsdir)
193 (make-directory thumbs-thumbsdir)
194 (message "Creating thumbnails directory"))
195 thumbs-thumbsdir))
197 (defun thumbs-cleanup-thumbsdir ()
198 "Clean the thumbnails directory.
199 If the total size of all files in `thumbs-thumbsdir' is bigger than
200 `thumbs-thumbsdir-max-size', files are deleted until the max size is
201 reached."
202 (let* ((filesL
203 (sort
204 (mapcar
205 (lambda (f)
206 (let ((fattribsL (file-attributes f)))
207 `(,(nth 4 fattribsL) ,(nth 7 fattribsL) ,f)))
208 (directory-files (thumbs-thumbsdir) t (image-file-name-regexp)))
209 '(lambda (l1 l2) (time-less-p (car l1) (car l2)))))
210 (dirsize (apply '+ (mapcar (lambda (x) (cadr x)) filesL))))
211 (while (> dirsize thumbs-thumbsdir-max-size)
212 (progn
213 (message "Deleting file %s" (cadr (cdar filesL))))
214 (delete-file (cadr (cdar filesL)))
215 (setq dirsize (- dirsize (car (cdar filesL))))
216 (setq filesL (cdr filesL)))))
218 ;; Check the thumbsnail directory size and clean it if necessary.
219 (when thumbs-thumbsdir-auto-clean
220 (thumbs-cleanup-thumbsdir))
222 (defun thumbs-call-convert (filein fileout action
223 &optional arg output-format action-prefix)
224 "Call the convert program.
225 FILEIN is the input file,
226 FILEOUT is the output file,
227 ACTION is the command to send to convert.
228 Optional arguments are:
229 ARG any arguments to the ACTION command,
230 OUTPUT-FORMAT is the file format to output (default is jpeg),
231 ACTION-PREFIX is the symbol to place before the ACTION command
232 (defaults to '-' but can sometimes be '+')."
233 (let ((command (format "%s %s%s %s \"%s\" \"%s:%s\""
234 thumbs-conversion-program
235 (or action-prefix "-")
236 action
237 (or arg "")
238 filein
239 (or output-format "jpeg")
240 fileout)))
241 (shell-command command)))
243 (defun thumbs-increment-image-size-element (n d)
244 "Increment number N by D percent."
245 (round (+ n (/ (* d n) 100))))
247 (defun thumbs-decrement-image-size-element (n d)
248 "Decrement number N by D percent."
249 (round (- n (/ (* d n) 100))))
251 (defun thumbs-increment-image-size (s)
252 "Increment S (a cons of width x height)."
253 (cons
254 (thumbs-increment-image-size-element (car s)
255 thumbs-image-resizing-step)
256 (thumbs-increment-image-size-element (cdr s)
257 thumbs-image-resizing-step)))
259 (defun thumbs-decrement-image-size (s)
260 "Decrement S (a cons of width x height)."
261 (cons
262 (thumbs-decrement-image-size-element (car s)
263 thumbs-image-resizing-step)
264 (thumbs-decrement-image-size-element (cdr s)
265 thumbs-image-resizing-step)))
267 (defun thumbs-resize-image (&optional increment size)
268 "Resize image in current buffer.
269 If INCREMENT is set, make the image bigger, else smaller.
270 Or, alternatively, a SIZE may be specified."
271 (interactive)
272 ;; cleaning of old temp file
273 (condition-case nil
274 (apply 'delete-file
275 (directory-files
276 (thumbs-temp-dir) t
277 thumbs-temp-prefix))
278 (error nil))
279 (let ((buffer-read-only nil)
280 (x (if size
281 size
282 (if increment
283 (thumbs-increment-image-size
284 thumbs-current-image-size)
285 (thumbs-decrement-image-size
286 thumbs-current-image-size))))
287 (tmp (thumbs-temp-file)))
288 (erase-buffer)
289 (thumbs-call-convert thumbs-current-image-filename
290 tmp "sample"
291 (concat (number-to-string (car x)) "x"
292 (number-to-string (cdr x))))
293 (thumbs-insert-image tmp 'jpeg 0)
294 (setq thumbs-current-tmp-filename tmp)))
296 (defun thumbs-resize-interactive (width height)
297 "Resize image interactively to specified WIDTH and HEIGHT."
298 (interactive "nWidth: \nnHeight: ")
299 (thumbs-resize-image nil (cons width height)))
301 (defun thumbs-resize-image-size-down ()
302 "Resize image (smaller)."
303 (interactive)
304 (thumbs-resize-image nil))
306 (defun thumbs-resize-image-size-up ()
307 "Resize image (bigger)."
308 (interactive)
309 (thumbs-resize-image t))
311 (defun thumbs-thumbname (img)
312 "Return a thumbnail name for the image IMG."
313 (convert-standard-filename
314 (let ((filename (expand-file-name img)))
315 (format "%s%08x-%s.jpg"
316 (thumbs-thumbsdir)
317 (sxhash filename)
318 (subst-char-in-string
319 ?\s ?\_
320 (apply
321 'concat
322 (split-string filename "/")))))))
324 (defun thumbs-make-thumb (img)
325 "Create the thumbnail for IMG."
326 (let ((fn (expand-file-name img))
327 (tn (thumbs-thumbname img)))
328 (if (or (not (file-exists-p tn))
329 ;; This is not the right fix, but I don't understand
330 ;; the external program or why it produces a geometry
331 ;; unequal to the one requested -- rms.
332 ;;; (not (equal (thumbs-file-size tn) thumbs-geometry))
334 (thumbs-call-convert fn tn "sample" thumbs-geometry))
335 tn))
337 (defun thumbs-image-type (img)
338 "Return image type from filename IMG."
339 (cond ((string-match ".*\\.jpe?g\\'" img) 'jpeg)
340 ((string-match ".*\\.xpm\\'" img) 'xpm)
341 ((string-match ".*\\.xbm\\'" img) 'xbm)
342 ((string-match ".*\\.gif\\'" img) 'gif)
343 ((string-match ".*\\.bmp\\'" img) 'bmp)
344 ((string-match ".*\\.png\\'" img) 'png)
345 ((string-match ".*\\.tiff?\\'" img) 'tiff)))
347 (defun thumbs-file-size (img)
348 (let ((i (image-size (find-image `((:type ,(thumbs-image-type img) :file ,img))) t)))
349 (concat (number-to-string (round (car i)))
351 (number-to-string (round (cdr i))))))
353 ;;;###autoload
354 (defun thumbs-find-thumb (img)
355 "Display the thumbnail for IMG."
356 (interactive "f")
357 (find-file (thumbs-make-thumb img)))
359 (defun thumbs-insert-image (img type relief &optional marked)
360 "Insert image IMG at point.
361 TYPE and RELIEF will be used in constructing the image; see `image'
362 in the emacs-lisp manual for further documentation.
363 If MARKED is non-nil, the image is marked."
364 (let ((i `(image :type ,type
365 :file ,img
366 :relief ,relief
367 :conversion ,(if marked 'disabled)
368 :margin ,thumbs-margin)))
369 (insert-image i)
370 (set (make-local-variable 'thumbs-current-image-size)
371 (image-size i t))))
373 (defun thumbs-insert-thumb (img &optional marked)
374 "Insert the thumbnail for IMG at point.
375 If MARKED is non-nil, the image is marked."
376 (thumbs-insert-image
377 (thumbs-make-thumb img) 'jpeg thumbs-relief marked)
378 (put-text-property (1- (point)) (point)
379 'thumb-image-file img))
381 (defun thumbs-do-thumbs-insertion (L)
382 "Insert all thumbs in list L."
383 (let ((i 0))
384 (dolist (img L)
385 (thumbs-insert-thumb img
386 (member img thumbs-markedL))
387 (when (= 0 (mod (setq i (1+ i)) thumbs-per-line))
388 (newline)))
389 (unless (bobp) (newline))))
391 (defun thumbs-show-thumbs-list (L &optional buffer-name same-window)
392 (unless (and (display-images-p)
393 (image-type-available-p 'jpeg))
394 (error "Required image type is not supported in this Emacs session"))
395 (funcall (if same-window 'switch-to-buffer 'pop-to-buffer)
396 (or buffer-name "*THUMB-View*"))
397 (let ((inhibit-read-only t))
398 (erase-buffer)
399 (thumbs-mode)
400 (thumbs-do-thumbs-insertion L)
401 (goto-char (point-min))
402 (set (make-local-variable 'thumbs-current-dir) default-directory)))
404 ;;;###autoload
405 (defun thumbs-show-all-from-dir (dir &optional reg same-window)
406 "Make a preview buffer for all images in DIR.
407 Optional argument REG to select file matching a regexp,
408 and SAME-WINDOW to show thumbs in the same window."
409 (interactive "DDir: ")
410 (thumbs-show-thumbs-list
411 (directory-files dir t
412 (or reg (image-file-name-regexp)))
413 (concat "*Thumbs: " dir) same-window))
415 ;;;###autoload
416 (defun thumbs-dired-show-marked ()
417 "In dired, make a thumbs buffer with all marked files."
418 (interactive)
419 (thumbs-show-thumbs-list (dired-get-marked-files) nil t))
421 ;;;###autoload
422 (defun thumbs-dired-show-all ()
423 "In dired, make a thumbs buffer with all files in current directory."
424 (interactive)
425 (thumbs-show-all-from-dir default-directory nil t))
427 ;;;###autoload
428 (defalias 'thumbs 'thumbs-show-all-from-dir)
430 (defun thumbs-find-image (img &optional num otherwin)
431 (funcall
432 (if otherwin 'switch-to-buffer-other-window 'switch-to-buffer)
433 (concat "*Image: " (file-name-nondirectory img) " - "
434 (number-to-string (or num 0)) "*"))
435 (thumbs-view-image-mode)
436 (let ((inhibit-read-only t))
437 (setq thumbs-current-image-filename img
438 thumbs-current-tmp-filename nil
439 thumbs-image-num (or num 0))
440 (delete-region (point-min)(point-max))
441 (thumbs-insert-image img (thumbs-image-type img) 0)))
443 (defun thumbs-find-image-at-point (&optional img otherwin)
444 "Display image IMG for thumbnail at point.
445 Use another window if OTHERWIN is t."
446 (interactive)
447 (let* ((i (or img (thumbs-current-image))))
448 (thumbs-find-image i (point) otherwin)))
450 (defun thumbs-find-image-at-point-other-window ()
451 "Display image for thumbnail at point in the preview buffer.
452 Open another window."
453 (interactive)
454 (thumbs-find-image-at-point nil t))
456 (defun thumbs-mouse-find-image (event)
457 "Display image for thumbnail at mouse click EVENT."
458 (interactive "e")
459 (mouse-set-point event)
460 (thumbs-find-image-at-point))
462 (defun thumbs-call-setroot-command (img)
463 "Call the setroot program for IMG."
464 (run-hooks 'thumbs-before-setroot-hook)
465 (shell-command (replace-regexp-in-string
466 "\\*"
467 (shell-quote-argument (expand-file-name img))
468 thumbs-setroot-command nil t))
469 (run-hooks 'thumbs-after-setroot-hook))
471 (defun thumbs-set-image-at-point-to-root-window ()
472 "Set the image at point as the desktop wallpaper."
473 (interactive)
474 (thumbs-call-setroot-command
475 (thumbs-current-image)))
477 (defun thumbs-set-root ()
478 "Set the current image as root."
479 (interactive)
480 (thumbs-call-setroot-command
481 (or thumbs-current-tmp-filename
482 thumbs-current-image-filename)))
484 (defun thumbs-file-alist ()
485 "Make an alist of elements (POS . FILENAME) for all images in thumb buffer."
486 (save-excursion
487 (let (list)
488 (goto-char (point-min))
489 (while (not (eobp))
490 (if (thumbs-current-image)
491 (push (cons (point-marker)
492 (thumbs-current-image))
493 list))
494 (forward-char 1))
495 list)))
497 (defun thumbs-file-list ()
498 "Make a list of file names for all images in thumb buffer."
499 (save-excursion
500 (let (list)
501 (goto-char (point-min))
502 (while (not (eobp))
503 (if (thumbs-current-image)
504 (push (thumbs-current-image) list))
505 (forward-char 1))
506 (nreverse list))))
508 (defun thumbs-delete-images ()
509 "Delete the image at point (and its thumbnail) (or marked files if any)."
510 (interactive)
511 (let ((files (or thumbs-markedL (list (thumbs-current-image)))))
512 (if (yes-or-no-p (format "Really delete %d files? " (length files)))
513 (let ((thumbs-fileL (thumbs-file-alist))
514 (inhibit-read-only t))
515 (dolist (x files)
516 (let (failure)
517 (condition-case ()
518 (progn
519 (delete-file x)
520 (delete-file (thumbs-thumbname x)))
521 (file-error (setq failure t)))
522 (unless failure
523 (when (rassoc x thumbs-fileL)
524 (goto-char (car (rassoc x thumbs-fileL)))
525 (delete-region (point) (1+ (point))))
526 (setq thumbs-markedL
527 (delq x thumbs-markedL)))))))))
529 (defun thumbs-rename-images (newfile)
530 "Rename the image at point (and its thumbnail) (or marked files if any)."
531 (interactive "FRename to file or directory: ")
532 (let ((files (or thumbs-markedL (list (thumbs-current-image))))
533 failures)
534 (if (and (not (file-directory-p newfile))
535 thumbs-markedL)
536 (if (file-exists-p newfile)
537 (error "Renaming marked files to file name `%s'" newfile)
538 (make-directory newfile t)))
539 (if (yes-or-no-p (format "Really rename %d files? " (length files)))
540 (let ((thumbs-fileL (thumbs-file-alist))
541 (inhibit-read-only t))
542 (dolist (file files)
543 (let (failure)
544 (condition-case ()
545 (if (file-directory-p newfile)
546 (rename-file file
547 (expand-file-name
548 (file-name-nondirectory file)
549 newfile))
550 (rename-file file newfile))
551 (file-error (setq failure t)
552 (push file failures)))
553 (unless failure
554 (when (rassoc file thumbs-fileL)
555 (goto-char (car (rassoc file thumbs-fileL)))
556 (delete-region (point) (1+ (point))))
557 (setq thumbs-markedL
558 (delq file thumbs-markedL)))))))
559 (if failures
560 (display-warning 'file-error
561 (format "Rename failures for %s into %s"
562 failures newfile)
563 :error))))
565 (defun thumbs-kill-buffer ()
566 "Kill the current buffer."
567 (interactive)
568 (quit-window t (selected-window)))
570 (defun thumbs-show-image-num (num)
571 "Show the image with number NUM."
572 (let ((image-buffer (get-buffer-create "*Image*")))
573 (let ((i (thumbs-current-image)))
574 (with-current-buffer image-buffer
575 (thumbs-insert-image i (thumbs-image-type i) 0))
576 (setq thumbs-image-num num
577 thumbs-current-image-filename i))))
579 (defun thumbs-next-image ()
580 "Show the next image."
581 (interactive)
582 (let* ((i (1+ thumbs-image-num))
583 (list (thumbs-file-alist))
584 (l (caar list)))
585 (while (and (/= i thumbs-image-num) (not (assoc i list)))
586 (setq i (if (>= i l) 1 (1+ i))))
587 (thumbs-show-image-num i)))
589 (defun thumbs-previous-image ()
590 "Show the previous image."
591 (interactive)
592 (let* ((i (- thumbs-image-num 1))
593 (list (thumbs-file-alist))
594 (l (caar list)))
595 (while (and (/= i thumbs-image-num) (not (assoc i list)))
596 (setq i (if (<= i 1) l (1- i))))
597 (thumbs-show-image-num i)))
599 (defun thumbs-redraw-buffer ()
600 "Redraw the current thumbs buffer."
601 (let ((p (point))
602 (inhibit-read-only t)
603 (files (thumbs-file-list)))
604 (erase-buffer)
605 (thumbs-do-thumbs-insertion files)
606 (goto-char p)))
608 (defun thumbs-mark ()
609 "Mark the image at point."
610 (interactive)
611 (let ((elt (thumbs-current-image)))
612 (unless elt
613 (error "No image here"))
614 (push elt thumbs-markedL)
615 (let ((inhibit-read-only t))
616 (delete-char 1)
617 (thumbs-insert-thumb elt t)))
618 (when (eolp) (forward-char)))
620 (defun thumbs-unmark ()
621 "Unmark the image at point."
622 (interactive)
623 (let ((elt (thumbs-current-image)))
624 (unless elt
625 (error "No image here"))
626 (setq thumbs-markedL (delete elt thumbs-markedL))
627 (let ((inhibit-read-only t))
628 (delete-char 1)
629 (thumbs-insert-thumb elt nil)))
630 (when (eolp) (forward-char)))
632 ;; Image modification routines
634 (defun thumbs-modify-image (action &optional arg)
635 "Call convert to do ACTION on image with argument ARG.
636 ACTION and ARG should be a valid convert command."
637 (interactive "sAction: \nsValue: ")
638 ;; cleaning of old temp file
639 (mapc 'delete-file
640 (directory-files
641 (thumbs-temp-dir)
643 thumbs-temp-prefix))
644 (let ((buffer-read-only nil)
645 (tmp (thumbs-temp-file)))
646 (erase-buffer)
647 (thumbs-call-convert thumbs-current-image-filename
649 action
650 (or arg ""))
651 (thumbs-insert-image tmp 'jpeg 0)
652 (setq thumbs-current-tmp-filename tmp)))
654 (defun thumbs-emboss-image (emboss)
655 "Emboss the image with value EMBOSS."
656 (interactive "nEmboss value: ")
657 (if (or (< emboss 3) (> emboss 31) (zerop (% emboss 2)))
658 (error "Arg must be an odd number between 3 and 31"))
659 (thumbs-modify-image "emboss" (number-to-string emboss)))
661 (defun thumbs-monochrome-image ()
662 "Turn the image to monochrome."
663 (interactive)
664 (thumbs-modify-image "monochrome"))
666 (defun thumbs-negate-image ()
667 "Negate the image."
668 (interactive)
669 (thumbs-modify-image "negate"))
671 (defun thumbs-rotate-left ()
672 "Rotate the image 90 degrees counter-clockwise."
673 (interactive)
674 (thumbs-modify-image "rotate" "270"))
676 (defun thumbs-rotate-right ()
677 "Rotate the image 90 degrees clockwise."
678 (interactive)
679 (thumbs-modify-image "rotate" "90"))
681 (defun thumbs-current-image ()
682 "Return the name of the image file name at point."
683 (get-text-property (point) 'thumb-image-file))
685 (defun thumbs-forward-char ()
686 "Move forward one image."
687 (interactive)
688 (forward-char)
689 (while (and (not (eobp)) (not (thumbs-current-image)))
690 (forward-char))
691 (thumbs-show-name))
693 (defun thumbs-backward-char ()
694 "Move backward one image."
695 (interactive)
696 (forward-char -1)
697 (while (and (not (bobp)) (not (thumbs-current-image)))
698 (forward-char -1))
699 (thumbs-show-name))
701 (defun thumbs-forward-line ()
702 "Move down one line."
703 (interactive)
704 (forward-line 1)
705 (thumbs-show-name))
707 (defun thumbs-backward-line ()
708 "Move up one line."
709 (interactive)
710 (forward-line -1)
711 (thumbs-show-name))
713 (defun thumbs-show-name ()
714 "Show the name of the current file."
715 (interactive)
716 (let ((f (thumbs-current-image)))
717 (and f (message "%s [%s]" f (thumbs-file-size f)))))
719 (defun thumbs-save-current-image ()
720 "Save the current image."
721 (interactive)
722 (let ((f (or thumbs-current-tmp-filename
723 thumbs-current-image-filename))
724 (sa (read-from-minibuffer "Save image file as: "
725 thumbs-current-image-filename)))
726 (copy-file f sa)))
728 (defun thumbs-dired ()
729 "Use `dired' on the current thumbs directory."
730 (interactive)
731 (dired thumbs-current-dir))
733 ;; thumbs-mode
735 (defvar thumbs-mode-map
736 (let ((map (make-sparse-keymap)))
737 (define-key map [return] 'thumbs-find-image-at-point)
738 (define-key map [mouse-2] 'thumbs-mouse-find-image)
739 (define-key map [(meta return)] 'thumbs-find-image-at-point-other-window)
740 (define-key map [(control return)] 'thumbs-set-image-at-point-to-root-window)
741 (define-key map [delete] 'thumbs-delete-images)
742 (define-key map [right] 'thumbs-forward-char)
743 (define-key map [left] 'thumbs-backward-char)
744 (define-key map [up] 'thumbs-backward-line)
745 (define-key map [down] 'thumbs-forward-line)
746 (define-key map "d" 'thumbs-dired)
747 (define-key map "m" 'thumbs-mark)
748 (define-key map "u" 'thumbs-unmark)
749 (define-key map "R" 'thumbs-rename-images)
750 (define-key map "x" 'thumbs-delete-images)
751 (define-key map "s" 'thumbs-show-name)
752 (define-key map "q" 'thumbs-kill-buffer)
753 map)
754 "Keymap for `thumbs-mode'.")
756 (put 'thumbs-mode 'mode-class 'special)
757 (define-derived-mode thumbs-mode
758 fundamental-mode "thumbs"
759 "Preview images in a thumbnails buffer"
760 (setq buffer-read-only t)
761 (set (make-local-variable 'thumbs-markedL) nil))
763 (defvar thumbs-view-image-mode-map
764 (let ((map (make-sparse-keymap)))
765 (define-key map [prior] 'thumbs-previous-image)
766 (define-key map [next] 'thumbs-next-image)
767 (define-key map "-" 'thumbs-resize-image-size-down)
768 (define-key map "+" 'thumbs-resize-image-size-up)
769 (define-key map "<" 'thumbs-rotate-left)
770 (define-key map ">" 'thumbs-rotate-right)
771 (define-key map "e" 'thumbs-emboss-image)
772 (define-key map "r" 'thumbs-resize-interactive)
773 (define-key map "s" 'thumbs-save-current-image)
774 (define-key map "q" 'thumbs-kill-buffer)
775 (define-key map "w" 'thumbs-set-root)
776 map)
777 "Keymap for `thumbs-view-image-mode'.")
779 ;; thumbs-view-image-mode
780 (put 'thumbs-view-image-mode 'mode-class 'special)
781 (define-derived-mode thumbs-view-image-mode
782 fundamental-mode "image-view-mode"
783 (setq buffer-read-only t))
785 ;;;###autoload
786 (defun thumbs-dired-setroot ()
787 "In dired, call the setroot program on the image at point."
788 (interactive)
789 (thumbs-call-setroot-command (dired-get-filename)))
791 ;; Modif to dired mode map
792 (define-key dired-mode-map "\C-ta" 'thumbs-dired-show-all)
793 (define-key dired-mode-map "\C-tm" 'thumbs-dired-show-marked)
794 (define-key dired-mode-map "\C-tw" 'thumbs-dired-setroot)
796 (provide 'thumbs)
798 ;; arch-tag: f9ac1ef8-83fc-42c0-8069-1fae43fd2e5c
799 ;;; thumbs.el ends here