all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#8453: enhancement to image mode
@ 2011-04-09  1:29 Christian Wittern
  2011-04-10  3:27 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Christian Wittern @ 2011-04-09  1:29 UTC (permalink / raw)
  To: 8453

Hello, I am trying to send this through the send bug report function, I hope
it works.

With the help of Drew Adams on gnu.emacs.help, I added the following to
image-mode, which allows one to visit the following or previous image, which
is useful if images are in a series, such as in pages of books.  If this is
deemed useful, I would like to have this added to emacs.

(require 'image-mode)
(define-key image-mode-map "n" 'next-image)
(define-key image-mode-map "p" 'previous-image)

(defun next-image (arg)
  "when visitng an image, go to the next image in the same
directory of the same type. No argument or nil will move to the
following image in ascending order, t will move to the previous
one.  Thanks to Drew Adams for help with this on gnu.emacs.help"
  (interactive "P")
  (unless (and (buffer-file-name) (eq major-mode 'image-mode))
    (error "Not visiting a file in image mode"))
  (let* ((files   (directory-files
		   (file-name-directory (buffer-file-name)) nil
		   (file-name-extension (buffer-file-name)) ))
         (len     (length files))
         (this    (file-name-nondirectory (buffer-file-name)))
         (idx     0))
    (catch 'next-image
      (dolist (file  files)
        (when (string= this file) (throw 'next-image (1+ idx)))
        (setq idx  (1+ idx))))
    (setq idx  (+ idx (if arg -1 1)))
    (when (< idx 0) (setq idx (1- len)))
    (when (>= idx len) (setq idx 0))
    (find-file (elt files idx))))

(defun previous-image (arg)
  "when visitng an image, go to the next image in the same
directory of the same type. No argument or nil will move to the
following image in ascending order, t will move to the previous
one.  Thanks to Drew Adams for help with this on gnu.emacs.help"
  (interactive "P")
  (next-image t))


-- 
 Christian Wittern





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-01-19 15:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-09  1:29 bug#8453: enhancement to image mode Christian Wittern
2011-04-10  3:27 ` Stefan Monnier
2013-01-19 15:23   ` Chong Yidong

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.