emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r111558: * image-mode.el (image-next-


From: Chong Yidong
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r111558: * image-mode.el (image-next-file, image-previous-file): New commands.
Date: Sat, 19 Jan 2013 23:22:38 +0800
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 111558
fixes bug: http://debbugs.gnu.org/8453
author: Christian Wittern <address@hidden>
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Sat 2013-01-19 23:22:38 +0800
message:
  * image-mode.el (image-next-file, image-previous-file): New commands.
  (image-mode-map): Bind them to n and p.
  (image-mode--images-in-directory): New helper function.
modified:
  etc/NEWS
  lisp/ChangeLog
  lisp/image-mode.el
=== modified file 'etc/NEWS'
--- a/etc/NEWS  2013-01-19 10:34:07 +0000
+++ b/etc/NEWS  2013-01-19 15:22:38 +0000
@@ -110,6 +110,11 @@
 *** Removed icomplete-show-key-bindings.
 
 ** Image mode
+
+*** New commands `n' (`image-next-file') and `p' (`image-previous-file')
+visit the next image file and the previous image file in the same
+directory, respectively.
+
 ---
 *** The command `image-mode-fit-frame' deletes other windows.
 When toggling, it restores the frame's previous window configuration.

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-01-19 10:34:07 +0000
+++ b/lisp/ChangeLog    2013-01-19 15:22:38 +0000
@@ -1,3 +1,11 @@
+2013-01-19  Christian Wittern  <address@hidden>  (tiny change)
+           Chong Yidong  <address@hidden>
+
+       * image-mode.el (image-next-file, image-previous-file): New
+       commands (Bug#8453).
+       (image-mode-map): Bind them to n and p.
+       (image-mode--images-in-directory): New helper function.
+
 2013-01-19  Chong Yidong  <address@hidden>
 
        * image-mode.el (image-mode-fit-frame): Add a frame argument.

=== modified file 'lisp/image-mode.el'
--- a/lisp/image-mode.el        2013-01-19 10:34:07 +0000
+++ b/lisp/image-mode.el        2013-01-19 15:22:38 +0000
@@ -339,6 +339,8 @@
     (define-key map (kbd "SPC")       'image-scroll-up)
     (define-key map (kbd "DEL")       'image-scroll-down)
     (define-key map (kbd "RET")       'image-toggle-animation)
+    (define-key map "n" 'image-next-file)
+    (define-key map "p" 'image-previous-file)
     (define-key map [remap forward-char] 'image-forward-hscroll)
     (define-key map [remap backward-char] 'image-backward-hscroll)
     (define-key map [remap right-char] 'image-forward-hscroll)
@@ -618,6 +620,52 @@
                           (if image-animate-loop t)))))))))
 
 
+;;; Switching to the next/previous image
+
+(defun image-next-file (&optional n)
+  "Visit the next image in the same directory as the current image file.
+With optional argument N, visit the Nth image file after the
+current one, in cyclic alphabetical order.
+
+This command visits the specified file via `find-alternate-file',
+replacing the current Image mode buffer."
+  (interactive "p")
+  (unless (derived-mode-p 'image-mode)
+    (error "The buffer is not in Image mode"))
+  (unless buffer-file-name
+    (error "The current image is not associated with a file"))
+  (let* ((file (file-name-nondirectory buffer-file-name))
+        (images (image-mode--images-in-directory file))
+        (idx 0))
+    (catch 'image-visit-next-file
+      (dolist (f images)
+       (if (string= f file)
+           (throw 'image-visit-next-file (1+ idx)))
+       (setq idx (1+ idx))))
+    (setq idx (mod (+ idx (or n 1)) (length images)))
+    (find-alternate-file (nth idx images))))
+
+(defun image-previous-file (&optional n)
+  "Visit the preceding image in the same directory as the current file.
+With optional argument N, visit the Nth image file preceding the
+current one, in cyclic alphabetical order.
+
+This command visits the specified file via `find-alternate-file',
+replacing the current Image mode buffer."
+  (interactive "p")
+  (image-next-file (- n)))
+
+(defun image-mode--images-in-directory (file)
+  (let* ((dir (file-name-directory buffer-file-name))
+        (files (directory-files dir nil
+                                (image-file-name-regexp) t)))
+    ;; Add the current file to the list of images if necessary, in
+    ;; case it does not match `image-file-name-regexp'.
+    (unless (member file files)
+      (push file files))
+    (sort files 'string-lessp)))
+
+
 ;;; Support for bookmark.el
 (declare-function bookmark-make-record-default
                   "bookmark" (&optional no-file no-context posn))


reply via email to

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