aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuanma Barranquero2005-06-09 01:41:23 +0000
committerJuanma Barranquero2005-06-09 01:41:23 +0000
commitf271d3c7bd8c99f1ca5544ec5b7dc97cab1e7d79 (patch)
treef26336809f1b641cd958deb26ce80b12d20866a0
parentb7aae902ed6d45976a249e44e296df9a97737c16 (diff)
downloademacs-f271d3c7bd8c99f1ca5544ec5b7dc97cab1e7d79.tar.gz
emacs-f271d3c7bd8c99f1ca5544ec5b7dc97cab1e7d79.zip
Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
loading. (thumbs-conversion-program): Use `eq' to check the system type, not `equal'. (thumbs-temp-dir): Set to `temporary-file-directory', not "/tmp". Fix docstring. (thumbs-thumbsdir): New function to return the thumbnails directory, creating it if needed. (thumbs-cleanup-thumbsdir, thumbs-thumbname): Use it. (thumbs-temp-file): Delete variable and make it into a function. (thumbs-resize-image, thumbs-modify-image): Use it. (thumbs-kill-buffer): Simplify. (thumbs-gensym): Defalias or duplicate CL `gensym'. (thumbs-resize-image, thumbs-resize-interactive): Fix typos in docstrings.
-rw-r--r--lisp/ChangeLog18
-rw-r--r--lisp/thumbs.el88
2 files changed, 61 insertions, 45 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a0a5c227413..9fad13c8bcb 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,21 @@
12005-06-09 Juanma Barranquero <lekktu@gmail.com>
2
3 * thumbs.el: Don't set `auto-image-file-mode'. Do not create the
4 thumbnails directory on loading.
5 (thumbs-conversion-program): Use `eq' to check the system type,
6 not `equal'.
7 (thumbs-temp-dir): Initialize to `temporary-file-directory',
8 not "/tmp". Fix docstring.
9 (thumbs-thumbsdir): New function to return the thumbnails
10 directory, creating it if needed.
11 (thumbs-cleanup-thumbsdir, thumbs-thumbname): Use it.
12 (thumbs-temp-file): Delete variable and make it into a function.
13 (thumbs-resize-image, thumbs-modify-image): Use it.
14 (thumbs-kill-buffer): Simplify.
15 (thumbs-gensym): Defalias or duplicate CL `gensym'.
16 (thumbs-resize-image, thumbs-resize-interactive): Fix typos in
17 docstrings.
18
12005-06-09 Kim F. Storm <storm@cua.dk> 192005-06-09 Kim F. Storm <storm@cua.dk>
2 20
3 * subr.el (save-match-data): Add RESEAT arg `evaporate' to 21 * subr.el (save-match-data): Add RESEAT arg `evaporate' to
diff --git a/lisp/thumbs.el b/lisp/thumbs.el
index c335b259c35..0fa44a3b8ee 100644
--- a/lisp/thumbs.el
+++ b/lisp/thumbs.el
@@ -65,8 +65,7 @@
65 :version "22.1" 65 :version "22.1"
66 :group 'multimedia) 66 :group 'multimedia)
67 67
68(defcustom thumbs-thumbsdir 68(defcustom thumbs-thumbsdir "~/.emacs-thumbs"
69 (expand-file-name "~/.emacs-thumbs")
70 "*Directory to store thumbnails." 69 "*Directory to store thumbnails."
71 :type 'directory 70 :type 'directory
72 :group 'thumbs) 71 :group 'thumbs)
@@ -88,7 +87,7 @@ When it reaches that size (in bytes), a warning is sent."
88 :group 'thumbs) 87 :group 'thumbs)
89 88
90(defcustom thumbs-conversion-program 89(defcustom thumbs-conversion-program
91 (if (equal 'windows-nt system-type) 90 (if (eq system-type 'windows-nt)
92 "convert.exe" 91 "convert.exe"
93 (or (executable-find "convert") 92 (or (executable-find "convert")
94 "/usr/X11R6/bin/convert")) 93 "/usr/X11R6/bin/convert"))
@@ -126,11 +125,10 @@ than `thumbs-thumbsdir-max-size'."
126 :type 'string 125 :type 'string
127 :group 'thumbs) 126 :group 'thumbs)
128 127
129(defcustom thumbs-temp-dir 128(defcustom thumbs-temp-dir temporary-file-directory
130 "/tmp/"
131 "Temporary directory to use. 129 "Temporary directory to use.
132Leaving it to default '/tmp/' can let another user 130Defaults to `temporary-file-directory'. Leaving it to
133see some of your images." 131this value can let another user see some of your images."
134 :type 'directory 132 :type 'directory
135 :group 'thumbs) 133 :group 'thumbs)
136 134
@@ -140,10 +138,6 @@ see some of your images."
140 :group 'thumbs) 138 :group 'thumbs)
141 139
142;; Initialize some variable, for later use. 140;; Initialize some variable, for later use.
143(defvar thumbs-temp-file
144 (concat thumbs-temp-dir thumbs-temp-prefix)
145 "Temporary filename for images.")
146
147(defvar thumbs-current-tmp-filename 141(defvar thumbs-current-tmp-filename
148 nil 142 nil
149 "Temporary filename of current image.") 143 "Temporary filename of current image.")
@@ -163,28 +157,36 @@ see some of your images."
163 nil 157 nil
164 "List of marked files.") 158 "List of marked files.")
165 159
166;; Make sure auto-image-file-mode is ON. 160(defalias 'thumbs-gensym
167(auto-image-file-mode t) 161 (if (fboundp 'gensym)
168 162 'gensym
169;; Create the thumbs directory if it does not exists. 163 ;; Copied from cl-macs.el
170(setq thumbs-thumbsdir (expand-file-name thumbs-thumbsdir)) 164 (defvar thumbs-gensym-counter 0)
171 165 (lambda (&optional prefix)
172(when (not (file-directory-p thumbs-thumbsdir)) 166 "Generate a new uninterned symbol.
173 (progn 167The name is made by appending a number to PREFIX, default \"G\"."
174 (make-directory thumbs-thumbsdir) 168 (let ((pfix (if (stringp prefix) prefix "G"))
175 (message "Creating thumbnails directory"))) 169 (num (if (integerp prefix) prefix
176 170 (prog1 thumbs-gensym-counter
177(defvar thumbs-gensym-counter 0) 171 (setq thumbs-gensym-counter
178 172 (1+ thumbs-gensym-counter))))))
179(defun thumbs-gensym (&optional arg) 173 (make-symbol (format "%s%d" pfix num))))))
180 "Generate a new uninterned symbol. 174
181The name is made by appending a number to PREFIX, default \"Thumbs\"." 175(defun thumbs-temp-file ()
182 (let ((prefix (if (stringp arg) arg "Thumbs")) 176 "Return a unique temporary filename for an image."
183 (num (if (integerp arg) arg 177 (format "%s%s-%s.jpg"
184 (prog1 178 (expand-file-name thumbs-temp-dir)
185 thumbs-gensym-counter 179 thumbs-temp-prefix
186 (setq thumbs-gensym-counter (1+ thumbs-gensym-counter)))))) 180 (thumbs-gensym "T")))
187 (make-symbol (format "%s%d" prefix num)))) 181
182(defun thumbs-thumbsdir ()
183 "Return the current thumbnails directory (from `thumbs-thumbsdir').
184Create the thumbnails directory if it does not exist."
185 (let ((thumbs-thumbsdir (expand-file-name thumbs-thumbsdir)))
186 (unless (file-directory-p thumbs-thumbsdir)
187 (make-directory thumbs-thumbsdir)
188 (message "Creating thumbnails directory"))
189 thumbs-thumbsdir))
188 190
189(defun thumbs-cleanup-thumbsdir () 191(defun thumbs-cleanup-thumbsdir ()
190 "Clean the thumbnails directory. 192 "Clean the thumbnails directory.
@@ -197,8 +199,8 @@ reached."
197 (lambda (f) 199 (lambda (f)
198 (let ((fattribsL (file-attributes f))) 200 (let ((fattribsL (file-attributes f)))
199 `(,(nth 4 fattribsL) ,(nth 7 fattribsL) ,f))) 201 `(,(nth 4 fattribsL) ,(nth 7 fattribsL) ,f)))
200 (directory-files thumbs-thumbsdir t (image-file-name-regexp))) 202 (directory-files (thumbs-thumbsdir) t (image-file-name-regexp)))
201 '(lambda (l1 l2) (time-less-p (car l1)(car l2))))) 203 '(lambda (l1 l2) (time-less-p (car l1) (car l2)))))
202 (dirsize (apply '+ (mapcar (lambda (x) (cadr x)) filesL)))) 204 (dirsize (apply '+ (mapcar (lambda (x) (cadr x)) filesL))))
203 (while (> dirsize thumbs-thumbsdir-max-size) 205 (while (> dirsize thumbs-thumbsdir-max-size)
204 (progn 206 (progn
@@ -258,7 +260,7 @@ ACTION-PREFIX is the symbol to place before the ACTION command
258 260
259(defun thumbs-resize-image (&optional increment size) 261(defun thumbs-resize-image (&optional increment size)
260 "Resize image in current buffer. 262 "Resize image in current buffer.
261if INCREMENT is set, make the image bigger, else smaller. 263If INCREMENT is set, make the image bigger, else smaller.
262Or, alternatively, a SIZE may be specified." 264Or, alternatively, a SIZE may be specified."
263 (interactive) 265 (interactive)
264 ;; cleaning of old temp file 266 ;; cleaning of old temp file
@@ -276,7 +278,7 @@ Or, alternatively, a SIZE may be specified."
276 thumbs-current-image-size) 278 thumbs-current-image-size)
277 (thumbs-decrement-image-size 279 (thumbs-decrement-image-size
278 thumbs-current-image-size)))) 280 thumbs-current-image-size))))
279 (tmp (format "%s%s.jpg" thumbs-temp-file (thumbs-gensym)))) 281 (tmp (thumbs-temp-file)))
280 (erase-buffer) 282 (erase-buffer)
281 (thumbs-call-convert thumbs-current-image-filename 283 (thumbs-call-convert thumbs-current-image-filename
282 tmp "sample" 284 tmp "sample"
@@ -286,7 +288,7 @@ Or, alternatively, a SIZE may be specified."
286 (setq thumbs-current-tmp-filename tmp))) 288 (setq thumbs-current-tmp-filename tmp)))
287 289
288(defun thumbs-resize-interactive (width height) 290(defun thumbs-resize-interactive (width height)
289 "Resize Image interactively to specified WIDTH and HEIGHT." 291 "Resize image interactively to specified WIDTH and HEIGHT."
290 (interactive "nWidth: \nnHeight: ") 292 (interactive "nWidth: \nnHeight: ")
291 (thumbs-resize-image nil (cons width height))) 293 (thumbs-resize-image nil (cons width height)))
292 294
@@ -305,7 +307,7 @@ Or, alternatively, a SIZE may be specified."
305 (convert-standard-filename 307 (convert-standard-filename
306 (let ((filename (expand-file-name img))) 308 (let ((filename (expand-file-name img)))
307 (format "%s/%08x-%s.jpg" 309 (format "%s/%08x-%s.jpg"
308 thumbs-thumbsdir 310 (thumbs-thumbsdir)
309 (sxhash filename) 311 (sxhash filename)
310 (subst-char-in-string 312 (subst-char-in-string
311 ?\s ?\_ 313 ?\s ?\_
@@ -562,11 +564,7 @@ Open another window."
562(defun thumbs-kill-buffer () 564(defun thumbs-kill-buffer ()
563 "Kill the current buffer." 565 "Kill the current buffer."
564 (interactive) 566 (interactive)
565 (let ((buffer (current-buffer))) 567 (quit-window t (selected-window)))
566 (condition-case nil
567 (delete-window (selected-window))
568 (error nil))
569 (kill-buffer buffer)))
570 568
571(defun thumbs-show-image-num (num) 569(defun thumbs-show-image-num (num)
572 "Show the image with number NUM." 570 "Show the image with number NUM."
@@ -643,7 +641,7 @@ ACTION and ARG should be a valid convert command."
643 t 641 t
644 thumbs-temp-prefix)) 642 thumbs-temp-prefix))
645 (let ((buffer-read-only nil) 643 (let ((buffer-read-only nil)
646 (tmp (format "%s%s.jpg" thumbs-temp-file (thumbs-gensym)))) 644 (tmp (thumbs-temp-file)))
647 (erase-buffer) 645 (erase-buffer)
648 (thumbs-call-convert thumbs-current-image-filename 646 (thumbs-call-convert thumbs-current-image-filename
649 tmp 647 tmp