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