aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Roberts2006-01-20 04:43:02 +0000
committerNick Roberts2006-01-20 04:43:02 +0000
commitc897e76f7bd2ff28f6b6ca5f6e2ef9f7517e327e (patch)
treeb9b15464656d70fcfc5ce8626f81e2f07551f6e9
parent11f78f040c34fee9853a0973c29d7730d3c52e2c (diff)
downloademacs-c897e76f7bd2ff28f6b6ca5f6e2ef9f7517e327e.tar.gz
emacs-c897e76f7bd2ff28f6b6ca5f6e2ef9f7517e327e.zip
(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.
-rw-r--r--lisp/thumbs.el76
1 files changed, 44 insertions, 32 deletions
diff --git a/lisp/thumbs.el b/lisp/thumbs.el
index 2a8f6b217d4..df37e50c99c 100644
--- a/lisp/thumbs.el
+++ b/lisp/thumbs.el
@@ -153,6 +153,10 @@ this value can let another user see some of your images."
153 "Number of current image.") 153 "Number of current image.")
154(make-variable-buffer-local 'thumbs-image-num) 154(make-variable-buffer-local 'thumbs-image-num)
155 155
156(defvar thumbs-buffer nil
157 "Name of buffer containing thumbnails associated with image.")
158(make-variable-buffer-local 'thumbs-buffer)
159
156(defvar thumbs-current-dir nil 160(defvar thumbs-current-dir nil
157 "Current directory.") 161 "Current directory.")
158 162
@@ -429,17 +433,22 @@ and SAME-WINDOW to show thumbs in the same window."
429(defalias 'thumbs 'thumbs-show-all-from-dir) 433(defalias 'thumbs 'thumbs-show-all-from-dir)
430 434
431(defun thumbs-find-image (img &optional num otherwin) 435(defun thumbs-find-image (img &optional num otherwin)
432 (funcall 436 (let ((buffer (current-buffer)))
433 (if otherwin 'switch-to-buffer-other-window 'switch-to-buffer) 437 (funcall
434 (concat "*Image: " (file-name-nondirectory img) " - " 438 (if otherwin 'switch-to-buffer-other-window 'switch-to-buffer)
435 (number-to-string (or num 0)) "*")) 439 "*Image*")
436 (thumbs-view-image-mode) 440 (thumbs-view-image-mode)
437 (let ((inhibit-read-only t)) 441 (setq mode-name
438 (setq thumbs-current-image-filename img 442 (concat "image-view-mode: " (file-name-nondirectory img)
439 thumbs-current-tmp-filename nil 443 " - " (number-to-string num)))
440 thumbs-image-num (or num 0)) 444 (setq thumbs-buffer buffer)
441 (delete-region (point-min)(point-max)) 445 (let ((inhibit-read-only t))
442 (thumbs-insert-image img (thumbs-image-type img) 0))) 446 (setq thumbs-current-image-filename img
447 thumbs-current-tmp-filename nil
448 thumbs-image-num (or num 0))
449 (delete-region (point-min)(point-max))
450 (save-excursion
451 (thumbs-insert-image img (thumbs-image-type img) 0)))))
443 452
444(defun thumbs-find-image-at-point (&optional img otherwin) 453(defun thumbs-find-image-at-point (&optional img otherwin)
445 "Display image IMG for thumbnail at point. 454 "Display image IMG for thumbnail at point.
@@ -484,16 +493,17 @@ Open another window."
484 493
485(defun thumbs-file-alist () 494(defun thumbs-file-alist ()
486 "Make an alist of elements (POS . FILENAME) for all images in thumb buffer." 495 "Make an alist of elements (POS . FILENAME) for all images in thumb buffer."
487 (save-excursion 496 (with-current-buffer thumbs-buffer
488 (let (list) 497 (save-excursion
489 (goto-char (point-min)) 498 (let (list)
490 (while (not (eobp)) 499 (goto-char (point-min))
491 (if (thumbs-current-image) 500 (while (not (eobp))
492 (push (cons (point-marker) 501 (if (thumbs-current-image)
493 (thumbs-current-image)) 502 (push (cons (point-marker)
494 list)) 503 (thumbs-current-image))
495 (forward-char 1)) 504 list))
496 list))) 505 (forward-char 1))
506 (nreverse list)))))
497 507
498(defun thumbs-file-list () 508(defun thumbs-file-list ()
499 "Make a list of file names for all images in thumb buffer." 509 "Make a list of file names for all images in thumb buffer."
@@ -571,30 +581,32 @@ Open another window."
571(defun thumbs-show-image-num (num) 581(defun thumbs-show-image-num (num)
572 "Show the image with number NUM." 582 "Show the image with number NUM."
573 (let ((image-buffer (get-buffer-create "*Image*"))) 583 (let ((image-buffer (get-buffer-create "*Image*")))
574 (let ((i (thumbs-current-image))) 584 (let ((img (cdr (nth (1- num) (thumbs-file-alist)))))
575 (with-current-buffer image-buffer 585 (with-current-buffer image-buffer
576 (thumbs-insert-image i (thumbs-image-type i) 0)) 586 (setq mode-name
587 (concat "image-view-mode: " (file-name-nondirectory img)
588 " - " (number-to-string num)))
589 (let ((inhibit-read-only t))
590 (erase-buffer)
591 (thumbs-insert-image img (thumbs-image-type img) 0)
592 (goto-char (point-min))))
577 (setq thumbs-image-num num 593 (setq thumbs-image-num num
578 thumbs-current-image-filename i)))) 594 thumbs-current-image-filename img))))
579 595
580(defun thumbs-next-image () 596(defun thumbs-next-image ()
581 "Show the next image." 597 "Show the next image."
582 (interactive) 598 (interactive)
583 (let* ((i (1+ thumbs-image-num)) 599 (let* ((i (1+ thumbs-image-num))
584 (list (thumbs-file-alist)) 600 (number (length (thumbs-file-alist))))
585 (l (caar list))) 601 (if (= i number) (setq i 1))
586 (while (and (/= i thumbs-image-num) (not (assoc i list)))
587 (setq i (if (>= i l) 1 (1+ i))))
588 (thumbs-show-image-num i))) 602 (thumbs-show-image-num i)))
589 603
590(defun thumbs-previous-image () 604(defun thumbs-previous-image ()
591 "Show the previous image." 605 "Show the previous image."
592 (interactive) 606 (interactive)
593 (let* ((i (- thumbs-image-num 1)) 607 (let* ((i (- thumbs-image-num 1))
594 (list (thumbs-file-alist)) 608 (number (length (thumbs-file-alist))))
595 (l (caar list))) 609 (if (= i 0) (setq i (1- number)))
596 (while (and (/= i thumbs-image-num) (not (assoc i list)))
597 (setq i (if (<= i 1) l (1- i))))
598 (thumbs-show-image-num i))) 610 (thumbs-show-image-num i)))
599 611
600(defun thumbs-redraw-buffer () 612(defun thumbs-redraw-buffer ()