emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/thumbs.el


From: Nick Roberts
Subject: [Emacs-diffs] Changes to emacs/lisp/thumbs.el
Date: Tue, 24 Jan 2006 20:54:23 +0000

Index: emacs/lisp/thumbs.el
diff -u emacs/lisp/thumbs.el:1.25 emacs/lisp/thumbs.el:1.26
--- emacs/lisp/thumbs.el:1.25   Mon Jan 23 23:16:58 2006
+++ emacs/lisp/thumbs.el        Tue Jan 24 20:54:23 2006
@@ -3,6 +3,7 @@
 ;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
 
 ;; Author: Jean-Philippe Theberge <address@hidden>
+;; Maintainer: FSF
 ;; Keywords: Multimedia
 
 ;; This file is part of GNU Emacs.
@@ -127,7 +128,7 @@
   :group 'thumbs)
 
 (defcustom thumbs-image-resizing-step 10
-  "Step by which to resize image."
+  "Step by which to resize image as a percentage."
   :type 'integer
   :group 'thumbs)
 
@@ -255,73 +256,45 @@
                         fileout)))
     (call-process shell-file-name nil nil nil "-c" command)))
 
-(defun thumbs-increment-image-size-element (n d)
-  "Increment number N by D percent."
-  (round (+ n (/ (* d n) 100))))
-
-(defun thumbs-decrement-image-size-element (n d)
-  "Decrement number N by D percent."
-  (round (- n (/ (* d n) 100))))
-
-(defun thumbs-increment-image-size (s)
-  "Increment S (a cons of width x height)."
-  (cons
-   (thumbs-increment-image-size-element (car s)
-                                       thumbs-image-resizing-step)
-   (thumbs-increment-image-size-element (cdr s)
-                                       thumbs-image-resizing-step)))
-
-(defun thumbs-decrement-image-size (s)
-  "Decrement S (a cons of width x height)."
-  (cons
-   (thumbs-decrement-image-size-element (car s)
-                                       thumbs-image-resizing-step)
-   (thumbs-decrement-image-size-element (cdr s)
-                                       thumbs-image-resizing-step)))
+(defun thumbs-new-image-size (s increment)
+  "New image (a cons of width x height)."
+  (let ((d (* increment thumbs-image-resizing-step)))
+    (cons
+     (round (+ (car s) (/ (* d (car s)) 100)))
+     (round (+ (cdr s) (/ (* d (cdr s)) 100))))))
 
-(defun thumbs-resize-image (&optional increment size)
+(defun thumbs-resize-image-1 (&optional increment size)
   "Resize image in current buffer.
-If INCREMENT is set, make the image bigger, else smaller.
-Or, alternatively, a SIZE may be specified."
-  (interactive)
-  ;; cleaning of old temp file
-  (condition-case nil
-    (apply 'delete-file
-          (directory-files
-           (thumbs-temp-dir) t
-           thumbs-temp-prefix))
-    (error nil))
-  (let ((buffer-read-only nil)
-       (x (if size
-              size
-            (if increment
-                (thumbs-increment-image-size
-                 thumbs-current-image-size)
-              (thumbs-decrement-image-size
-               thumbs-current-image-size))))
-       (tmp (thumbs-temp-file)))
+If SIZE is specified use it.  Otherwise make the image larger or
+smaller according to whether INCREMENT is 1 or -1."
+  (let* ((buffer-read-only nil)
+        (old thumbs-current-tmp-filename)
+        (x (or size
+               (thumbs-new-image-size thumbs-current-image-size increment)))
+        (tmp (thumbs-temp-file)))
     (erase-buffer)
-    (thumbs-call-convert thumbs-current-image-filename
+    (thumbs-call-convert (or old thumbs-current-image-filename)
                         tmp "sample"
                         (concat (number-to-string (car x)) "x"
                                 (number-to-string (cdr x))))
-    (thumbs-insert-image tmp 'jpeg 0)
+    (save-excursion
+      (thumbs-insert-image tmp 'jpeg 0))
     (setq thumbs-current-tmp-filename tmp)))
 
-(defun thumbs-resize-interactive (width height)
+(defun thumbs-resize-image (width height)
   "Resize image interactively to specified WIDTH and HEIGHT."
   (interactive "nWidth: \nnHeight: ")
-  (thumbs-resize-image nil (cons width height)))
+  (thumbs-resize-image-1 nil (cons width height)))
 
-(defun thumbs-resize-image-size-down ()
+(defun thumbs-shrink-image ()
   "Resize image (smaller)."
   (interactive)
-  (thumbs-resize-image nil))
+  (thumbs-resize-image-1 -1))
 
-(defun thumbs-resize-image-size-up ()
+(defun thumbs-enlarge-image ()
   "Resize image (bigger)."
   (interactive)
-  (thumbs-resize-image t))
+  (thumbs-resize-image-1 1))
 
 (defun thumbs-thumbname (img)
   "Return a thumbnail name for the image IMG."
@@ -418,6 +391,7 @@
   (let ((inhibit-read-only t))
     (erase-buffer)
     (thumbs-mode)
+    (setq thumbs-buffer (current-buffer))
     (if dir (setq default-directory dir))
     (thumbs-do-thumbs-insertion list)
     (goto-char (point-min))
@@ -649,7 +623,8 @@
     (push elt thumbs-marked-list)
     (let ((inhibit-read-only t))
       (delete-char 1)
-      (thumbs-insert-thumb elt t)))
+      (save-excursion
+       (thumbs-insert-thumb elt t))))
   (when (eolp) (forward-char)))
 
 (defun thumbs-unmark ()
@@ -661,29 +636,31 @@
     (setq thumbs-marked-list (delete elt thumbs-marked-list))
     (let ((inhibit-read-only t))
       (delete-char 1)
-      (thumbs-insert-thumb elt nil)))
+      (save-excursion
+       (thumbs-insert-thumb elt nil))))
   (when (eolp) (forward-char)))
 
+
+;; cleaning of old temp files
+(mapc 'delete-file
+      (directory-files (thumbs-temp-dir) t thumbs-temp-prefix))
+
 ;; Image modification routines
 
 (defun thumbs-modify-image (action &optional arg)
   "Call convert to do ACTION on image with argument ARG.
 ACTION and ARG should be a valid convert command."
   (interactive "sAction: \nsValue: ")
-  ;; cleaning of old temp file
-  (mapc 'delete-file
-       (directory-files
-        (thumbs-temp-dir)
-        t
-        thumbs-temp-prefix))
-  (let ((buffer-read-only nil)
-       (tmp (thumbs-temp-file)))
+  (let* ((buffer-read-only nil)
+        (old thumbs-current-tmp-filename)
+        (tmp (thumbs-temp-file)))
     (erase-buffer)
-    (thumbs-call-convert thumbs-current-image-filename
+    (thumbs-call-convert (or old thumbs-current-image-filename)
                         tmp
                         action
                         (or arg ""))
-    (thumbs-insert-image tmp 'jpeg 0)
+    (save-excursion
+      (thumbs-insert-image tmp 'jpeg 0))
     (setq thumbs-current-tmp-filename tmp)))
 
 (defun thumbs-emboss-image (emboss)
@@ -808,12 +785,12 @@
     (define-key map [prior] 'thumbs-previous-image)
     (define-key map [next] 'thumbs-next-image)
     (define-key map "^" 'thumbs-display-thumbs-buffer)
-    (define-key map "-" 'thumbs-resize-image-size-down)
-    (define-key map "+" 'thumbs-resize-image-size-up)
+    (define-key map "-" 'thumbs-shrink-image)
+    (define-key map "+" 'thumbs-enlarge-image)
     (define-key map "<" 'thumbs-rotate-left)
     (define-key map ">" 'thumbs-rotate-right)
     (define-key map "e" 'thumbs-emboss-image)
-    (define-key map "r" 'thumbs-resize-interactive)
+    (define-key map "r" 'thumbs-resize-image)
     (define-key map "s" 'thumbs-save-current-image)
     (define-key map "q" 'thumbs-kill-buffer)
     (define-key map "w" 'thumbs-set-root)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]