changeset 68289:be0164ac55f8

(thumbs-buffer): New variable. Make it buffer local. (thumbs-find-image): Move image name and number from buffer name to mode name. Set thumbs-buffer. Preserve point so that large images remain visible. (thumbs-file-alist): Construct list in thumbs-buffer and reverse order. (thumbs-show-image-num): Get image from thumbs-file-alist. Set mode name. (thumbs-next-image, thumbs-previous-image): Make them work.
author Nick Roberts <nickrob@snap.net.nz>
date Fri, 20 Jan 2006 04:43:02 +0000
parents aaff37b9a54d
children 598f2fa3c1cf
files lisp/thumbs.el
diffstat 1 files changed, 44 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/thumbs.el	Fri Jan 20 04:42:06 2006 +0000
+++ b/lisp/thumbs.el	Fri Jan 20 04:43:02 2006 +0000
@@ -153,6 +153,10 @@
   "Number of current image.")
 (make-variable-buffer-local 'thumbs-image-num)
 
+(defvar thumbs-buffer nil
+  "Name of buffer containing thumbnails associated with image.")
+(make-variable-buffer-local 'thumbs-buffer)
+
 (defvar thumbs-current-dir nil
   "Current directory.")
 
@@ -429,17 +433,22 @@
 (defalias 'thumbs 'thumbs-show-all-from-dir)
 
 (defun thumbs-find-image (img &optional num otherwin)
-  (funcall
-   (if otherwin 'switch-to-buffer-other-window 'switch-to-buffer)
-   (concat "*Image: " (file-name-nondirectory img) " - "
-	   (number-to-string (or num 0)) "*"))
-  (thumbs-view-image-mode)
-  (let ((inhibit-read-only t))
-    (setq thumbs-current-image-filename img
-	  thumbs-current-tmp-filename nil
-	  thumbs-image-num (or num 0))
-    (delete-region (point-min)(point-max))
-    (thumbs-insert-image img (thumbs-image-type img) 0)))
+  (let ((buffer (current-buffer)))
+    (funcall
+     (if otherwin 'switch-to-buffer-other-window 'switch-to-buffer)
+     "*Image*")
+    (thumbs-view-image-mode)
+    (setq mode-name
+	  (concat "image-view-mode: " (file-name-nondirectory img)
+		  " - " (number-to-string num)))
+    (setq thumbs-buffer buffer)
+    (let ((inhibit-read-only t))
+      (setq thumbs-current-image-filename img
+	    thumbs-current-tmp-filename nil
+	    thumbs-image-num (or num 0))
+      (delete-region (point-min)(point-max))
+      (save-excursion
+	(thumbs-insert-image img (thumbs-image-type img) 0)))))
 
 (defun thumbs-find-image-at-point (&optional img otherwin)
   "Display image IMG for thumbnail at point.
@@ -484,16 +493,17 @@
 
 (defun thumbs-file-alist ()
   "Make an alist of elements (POS . FILENAME) for all images in thumb buffer."
-  (save-excursion
-    (let (list)
-      (goto-char (point-min))
-      (while (not (eobp))
-	(if (thumbs-current-image)
-	    (push (cons (point-marker)
-			(thumbs-current-image))
-		  list))
-	(forward-char 1))
-      list)))
+  (with-current-buffer thumbs-buffer
+    (save-excursion
+      (let (list)
+	(goto-char (point-min))
+	(while (not (eobp))
+	  (if (thumbs-current-image)
+	      (push (cons (point-marker)
+			  (thumbs-current-image))
+		    list))
+	  (forward-char 1))
+	(nreverse list)))))
 
 (defun thumbs-file-list ()
   "Make a list of file names for all images in thumb buffer."
@@ -571,30 +581,32 @@
 (defun thumbs-show-image-num (num)
   "Show the image with number NUM."
   (let ((image-buffer (get-buffer-create "*Image*")))
-    (let ((i (thumbs-current-image)))
+    (let ((img (cdr (nth (1- num) (thumbs-file-alist)))))
       (with-current-buffer image-buffer
-	(thumbs-insert-image i (thumbs-image-type i) 0))
+	(setq mode-name
+	      (concat "image-view-mode: " (file-name-nondirectory img)
+		      " - " (number-to-string num)))
+	(let ((inhibit-read-only t))
+	  (erase-buffer)
+	  (thumbs-insert-image img (thumbs-image-type img) 0)
+	  (goto-char (point-min))))
       (setq thumbs-image-num num
-	    thumbs-current-image-filename i))))
+	    thumbs-current-image-filename img))))
 
 (defun thumbs-next-image ()
   "Show the next image."
   (interactive)
   (let* ((i (1+ thumbs-image-num))
-	 (list (thumbs-file-alist))
-	 (l (caar list)))
-    (while (and (/= i thumbs-image-num) (not (assoc i list)))
-      (setq i (if (>= i l) 1 (1+ i))))
+	 (number (length (thumbs-file-alist))))
+    (if (= i number) (setq i 1))
     (thumbs-show-image-num i)))
 
 (defun thumbs-previous-image ()
   "Show the previous image."
   (interactive)
   (let* ((i (- thumbs-image-num 1))
-	 (list (thumbs-file-alist))
-	 (l (caar list)))
-    (while (and (/= i thumbs-image-num) (not (assoc i list)))
-      (setq i (if (<= i 1) l (1- i))))
+	 (number (length (thumbs-file-alist))))
+    (if (= i 0) (setq i (1- number)))
     (thumbs-show-image-num i)))
 
 (defun thumbs-redraw-buffer ()