diff options
| author | Christian Wittern | 2013-01-19 23:22:38 +0800 |
|---|---|---|
| committer | Chong Yidong | 2013-01-19 23:22:38 +0800 |
| commit | 20de6ab6a5567351df9f28d74052bad04877ef08 (patch) | |
| tree | 59487edd420cc81b99da4e7c8c669e263285e5e7 | |
| parent | 21cd50b803cb63b66f81db0a18dbaac6d7269348 (diff) | |
| download | emacs-20de6ab6a5567351df9f28d74052bad04877ef08.tar.gz emacs-20de6ab6a5567351df9f28d74052bad04877ef08.zip | |
* 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.
Fixes: debbugs:8453
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/image-mode.el | 48 |
3 files changed, 61 insertions, 0 deletions
| @@ -110,6 +110,11 @@ amounts of data into the ERC input. | |||
| 110 | *** Removed icomplete-show-key-bindings. | 110 | *** Removed icomplete-show-key-bindings. |
| 111 | 111 | ||
| 112 | ** Image mode | 112 | ** Image mode |
| 113 | |||
| 114 | *** New commands `n' (`image-next-file') and `p' (`image-previous-file') | ||
| 115 | visit the next image file and the previous image file in the same | ||
| 116 | directory, respectively. | ||
| 117 | |||
| 113 | --- | 118 | --- |
| 114 | *** The command `image-mode-fit-frame' deletes other windows. | 119 | *** The command `image-mode-fit-frame' deletes other windows. |
| 115 | When toggling, it restores the frame's previous window configuration. | 120 | When toggling, it restores the frame's previous window configuration. |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f63e9ecafe8..8d0a61525d9 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2013-01-19 Christian Wittern <cwittern@gmail.com> (tiny change) | ||
| 2 | Chong Yidong <cyd@gnu.org> | ||
| 3 | |||
| 4 | * image-mode.el (image-next-file, image-previous-file): New | ||
| 5 | commands (Bug#8453). | ||
| 6 | (image-mode-map): Bind them to n and p. | ||
| 7 | (image-mode--images-in-directory): New helper function. | ||
| 8 | |||
| 1 | 2013-01-19 Chong Yidong <cyd@gnu.org> | 9 | 2013-01-19 Chong Yidong <cyd@gnu.org> |
| 2 | 10 | ||
| 3 | * image-mode.el (image-mode-fit-frame): Add a frame argument. | 11 | * image-mode.el (image-mode-fit-frame): Add a frame argument. |
diff --git a/lisp/image-mode.el b/lisp/image-mode.el index bbb72335aa3..6a13d528037 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el | |||
| @@ -339,6 +339,8 @@ call." | |||
| 339 | (define-key map (kbd "SPC") 'image-scroll-up) | 339 | (define-key map (kbd "SPC") 'image-scroll-up) |
| 340 | (define-key map (kbd "DEL") 'image-scroll-down) | 340 | (define-key map (kbd "DEL") 'image-scroll-down) |
| 341 | (define-key map (kbd "RET") 'image-toggle-animation) | 341 | (define-key map (kbd "RET") 'image-toggle-animation) |
| 342 | (define-key map "n" 'image-next-file) | ||
| 343 | (define-key map "p" 'image-previous-file) | ||
| 342 | (define-key map [remap forward-char] 'image-forward-hscroll) | 344 | (define-key map [remap forward-char] 'image-forward-hscroll) |
| 343 | (define-key map [remap backward-char] 'image-backward-hscroll) | 345 | (define-key map [remap backward-char] 'image-backward-hscroll) |
| 344 | (define-key map [remap right-char] 'image-forward-hscroll) | 346 | (define-key map [remap right-char] 'image-forward-hscroll) |
| @@ -618,6 +620,52 @@ Otherwise it plays once, then stops." | |||
| 618 | (if image-animate-loop t))))))))) | 620 | (if image-animate-loop t))))))))) |
| 619 | 621 | ||
| 620 | 622 | ||
| 623 | ;;; Switching to the next/previous image | ||
| 624 | |||
| 625 | (defun image-next-file (&optional n) | ||
| 626 | "Visit the next image in the same directory as the current image file. | ||
| 627 | With optional argument N, visit the Nth image file after the | ||
| 628 | current one, in cyclic alphabetical order. | ||
| 629 | |||
| 630 | This command visits the specified file via `find-alternate-file', | ||
| 631 | replacing the current Image mode buffer." | ||
| 632 | (interactive "p") | ||
| 633 | (unless (derived-mode-p 'image-mode) | ||
| 634 | (error "The buffer is not in Image mode")) | ||
| 635 | (unless buffer-file-name | ||
| 636 | (error "The current image is not associated with a file")) | ||
| 637 | (let* ((file (file-name-nondirectory buffer-file-name)) | ||
| 638 | (images (image-mode--images-in-directory file)) | ||
| 639 | (idx 0)) | ||
| 640 | (catch 'image-visit-next-file | ||
| 641 | (dolist (f images) | ||
| 642 | (if (string= f file) | ||
| 643 | (throw 'image-visit-next-file (1+ idx))) | ||
| 644 | (setq idx (1+ idx)))) | ||
| 645 | (setq idx (mod (+ idx (or n 1)) (length images))) | ||
| 646 | (find-alternate-file (nth idx images)))) | ||
| 647 | |||
| 648 | (defun image-previous-file (&optional n) | ||
| 649 | "Visit the preceding image in the same directory as the current file. | ||
| 650 | With optional argument N, visit the Nth image file preceding the | ||
| 651 | current one, in cyclic alphabetical order. | ||
| 652 | |||
| 653 | This command visits the specified file via `find-alternate-file', | ||
| 654 | replacing the current Image mode buffer." | ||
| 655 | (interactive "p") | ||
| 656 | (image-next-file (- n))) | ||
| 657 | |||
| 658 | (defun image-mode--images-in-directory (file) | ||
| 659 | (let* ((dir (file-name-directory buffer-file-name)) | ||
| 660 | (files (directory-files dir nil | ||
| 661 | (image-file-name-regexp) t))) | ||
| 662 | ;; Add the current file to the list of images if necessary, in | ||
| 663 | ;; case it does not match `image-file-name-regexp'. | ||
| 664 | (unless (member file files) | ||
| 665 | (push file files)) | ||
| 666 | (sort files 'string-lessp))) | ||
| 667 | |||
| 668 | |||
| 621 | ;;; Support for bookmark.el | 669 | ;;; Support for bookmark.el |
| 622 | (declare-function bookmark-make-record-default | 670 | (declare-function bookmark-make-record-default |
| 623 | "bookmark" (&optional no-file no-context posn)) | 671 | "bookmark" (&optional no-file no-context posn)) |