all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: chris <cwittern@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: extension for image view to go to next or previous image
Date: Fri, 8 Apr 2011 18:24:56 -0700 (PDT)	[thread overview]
Message-ID: <f70daf9c-ad96-4d7e-bcde-1a1eaf0133e2@f11g2000vbx.googlegroups.com> (raw)
In-Reply-To: mailman.12.1302309090.11006.help-gnu-emacs@gnu.org

Dear Drew,

This is absolutely excellent.  Here is my version, based on your code,
which is actually a bit simpler, since I only want to look at images
of the same type.

(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))


Many thanks for your help!!!

Chris



  parent reply	other threads:[~2011-04-09  1:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-08  1:49 extension for image view to go to next or previous image chris
2011-04-08  6:34 ` Thierry Volpiatto
2011-04-08 13:55 ` Drew Adams
     [not found] ` <mailman.9.1302270960.11168.help-gnu-emacs@gnu.org>
2011-04-08 23:07   ` chris
2011-04-09  0:28     ` Drew Adams
     [not found]     ` <mailman.12.1302309090.11006.help-gnu-emacs@gnu.org>
2011-04-09  1:24       ` chris [this message]
2011-04-09  4:03       ` rusi
2011-04-09 15:06         ` Drew Adams
2011-04-09  5:32     ` Thierry Volpiatto
     [not found] ` <mailman.20.1302244507.25447.help-gnu-emacs@gnu.org>
2011-04-08 23:11   ` chris
2011-04-09  5:39     ` Thierry Volpiatto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f70daf9c-ad96-4d7e-bcde-1a1eaf0133e2@f11g2000vbx.googlegroups.com \
    --to=cwittern@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.