changeset 63155:911109216331

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.
author Juanma Barranquero <lekktu@gmail.com>
date Thu, 09 Jun 2005 01:39:40 +0000
parents ef765645a5cf
children 356a4e78a1e4
files lisp/thumbs.el
diffstat 1 files changed, 41 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/thumbs.el	Wed Jun 08 23:04:27 2005 +0000
+++ b/lisp/thumbs.el	Thu Jun 09 01:39:40 2005 +0000
@@ -65,8 +65,7 @@
   :version "22.1"
   :group 'multimedia)
 
-(defcustom thumbs-thumbsdir
-  (expand-file-name "~/.emacs-thumbs")
+(defcustom thumbs-thumbsdir "~/.emacs-thumbs"
   "*Directory to store thumbnails."
   :type 'directory
   :group 'thumbs)
@@ -88,7 +87,7 @@
   :group 'thumbs)
 
 (defcustom thumbs-conversion-program
-  (if (equal 'windows-nt system-type)
+  (if (eq system-type 'windows-nt)
       "convert.exe"
     (or (executable-find "convert")
 	"/usr/X11R6/bin/convert"))
@@ -126,11 +125,10 @@
   :type 'string
   :group 'thumbs)
 
-(defcustom thumbs-temp-dir
-  "/tmp/"
+(defcustom thumbs-temp-dir temporary-file-directory
   "Temporary directory to use.
-Leaving it to default '/tmp/' can let another user
-see some of your images."
+Defaults to `temporary-file-directory'.  Leaving it to
+this value can let another user see some of your images."
   :type 'directory
   :group 'thumbs)
 
@@ -140,10 +138,6 @@
   :group 'thumbs)
 
 ;; Initialize some variable, for later use.
-(defvar thumbs-temp-file
-  (concat thumbs-temp-dir thumbs-temp-prefix)
-  "Temporary filename for images.")
-
 (defvar thumbs-current-tmp-filename
   nil
   "Temporary filename of current image.")
@@ -163,28 +157,36 @@
   nil
   "List of marked files.")
 
-;; Make sure auto-image-file-mode is ON.
-(auto-image-file-mode t)
-
-;; Create the thumbs directory if it does not exists.
-(setq thumbs-thumbsdir (expand-file-name thumbs-thumbsdir))
-
-(when (not (file-directory-p thumbs-thumbsdir))
-  (progn
-    (make-directory thumbs-thumbsdir)
-    (message "Creating thumbnails directory")))
+(defalias 'thumbs-gensym
+    (if (fboundp 'gensym)
+        'gensym
+      ;; Copied from cl-macs.el
+      (defvar thumbs-gensym-counter 0)
+      (lambda (&optional prefix)
+	"Generate a new uninterned symbol.
+The name is made by appending a number to PREFIX, default \"G\"."
+	(let ((pfix (if (stringp prefix) prefix "G"))
+	      (num (if (integerp prefix) prefix
+		     (prog1 thumbs-gensym-counter
+		       (setq thumbs-gensym-counter
+			     (1+ thumbs-gensym-counter))))))
+	  (make-symbol (format "%s%d" pfix num))))))
 
-(defvar thumbs-gensym-counter 0)
+(defun thumbs-temp-file ()
+  "Return a unique temporary filename for an image."
+  (format "%s%s-%s.jpg"
+          (expand-file-name thumbs-temp-dir)
+          thumbs-temp-prefix
+          (thumbs-gensym "T")))
 
-(defun thumbs-gensym (&optional arg)
-  "Generate a new uninterned symbol.
-The name is made by appending a number to PREFIX, default \"Thumbs\"."
-  (let ((prefix (if (stringp arg) arg "Thumbs"))
-	(num (if (integerp arg) arg
-	       (prog1
-		   thumbs-gensym-counter
-		 (setq thumbs-gensym-counter (1+ thumbs-gensym-counter))))))
-    (make-symbol (format "%s%d" prefix num))))
+(defun thumbs-thumbsdir ()
+  "Return the current thumbnails directory (from `thumbs-thumbsdir').
+Create the thumbnails directory if it does not exist."
+  (let ((thumbs-thumbsdir (expand-file-name thumbs-thumbsdir)))
+    (unless (file-directory-p thumbs-thumbsdir)
+      (make-directory thumbs-thumbsdir)
+      (message "Creating thumbnails directory"))
+    thumbs-thumbsdir))
 
 (defun thumbs-cleanup-thumbsdir ()
   "Clean the thumbnails directory.
@@ -197,8 +199,8 @@
 	    (lambda (f)
 	      (let ((fattribsL (file-attributes f)))
 		`(,(nth 4 fattribsL) ,(nth 7 fattribsL) ,f)))
-	    (directory-files thumbs-thumbsdir t (image-file-name-regexp)))
-	   '(lambda (l1 l2) (time-less-p (car l1)(car l2)))))
+	    (directory-files (thumbs-thumbsdir) t (image-file-name-regexp)))
+	   '(lambda (l1 l2) (time-less-p (car l1) (car l2)))))
 	 (dirsize (apply '+ (mapcar (lambda (x) (cadr x)) filesL))))
     (while (> dirsize thumbs-thumbsdir-max-size)
       (progn
@@ -258,7 +260,7 @@
 
 (defun thumbs-resize-image (&optional increment size)
   "Resize image in current buffer.
-if INCREMENT is set, make the image bigger, else smaller.
+If INCREMENT is set, make the image bigger, else smaller.
 Or, alternatively, a SIZE may be specified."
   (interactive)
   ;; cleaning of old temp file
@@ -276,7 +278,7 @@
 		  thumbs-current-image-size)
 	       (thumbs-decrement-image-size
 		thumbs-current-image-size))))
-	(tmp (format "%s%s.jpg" thumbs-temp-file (thumbs-gensym))))
+	(tmp (thumbs-temp-file)))
     (erase-buffer)
     (thumbs-call-convert thumbs-current-image-filename
 			 tmp "sample"
@@ -286,7 +288,7 @@
     (setq thumbs-current-tmp-filename tmp)))
 
 (defun thumbs-resize-interactive (width height)
-  "Resize Image interactively to specified WIDTH and HEIGHT."
+  "Resize image interactively to specified WIDTH and HEIGHT."
   (interactive "nWidth: \nnHeight: ")
   (thumbs-resize-image nil (cons width height)))
 
@@ -305,7 +307,7 @@
   (convert-standard-filename
    (let ((filename (expand-file-name img)))
      (format "%s/%08x-%s.jpg"
-             thumbs-thumbsdir
+             (thumbs-thumbsdir)
              (sxhash filename)
              (subst-char-in-string
               ?\s ?\_
@@ -562,11 +564,7 @@
 (defun thumbs-kill-buffer ()
   "Kill the current buffer."
   (interactive)
-  (let ((buffer (current-buffer)))
-    (condition-case nil
-	(delete-window (selected-window))
-      (error nil))
-    (kill-buffer buffer)))
+  (quit-window t (selected-window)))
 
 (defun thumbs-show-image-num (num)
   "Show the image with number NUM."
@@ -643,7 +641,7 @@
 	 t
 	 thumbs-temp-prefix))
   (let ((buffer-read-only nil)
-	(tmp (format "%s%s.jpg" thumbs-temp-file (thumbs-gensym))))
+	(tmp (thumbs-temp-file)))
     (erase-buffer)
     (thumbs-call-convert thumbs-current-image-filename
 			 tmp