help-gnu-emacs
[Top][All Lists]
Advanced

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

RE: extension for image view to go to next or previous image


From: Drew Adams
Subject: RE: extension for image view to go to next or previous image
Date: Fri, 8 Apr 2011 17:28:00 -0700

> what I had in mind was ... to press 'n' (or SPC) on an
> image and then see the next one, 'p' would get me the
> previous one.

Ah, you didn't say that.

In that case, you probably need to bind `n' and `p' in `image-mode-map'.  You
just need commands that visit the next/previous file in sequence, then bind `n'
and `p' to them.  Shouldn't be hard.  Iterate over `directory-files' (e.g.
filtered by `image-file-name-regexp'), and call `find-file'.

Might be a reasonable addition to the default `image-mode-map' bindings.  After
you create the commands, think about submitting such bindings as an enhancement
via `M-x send-emacs-bug-report'.

Something like this, perhaps (you can improve it, certainly):

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

(defun next-image (arg)
  "..."
  (interactive "P")
  (unless (and (buffer-file-name) (eq major-mode 'image-mode))
    (error "Not visiting a file in image mode"))
  (let* ((regexp  (image-file-name-regexp))
         (files   (directory-files default-directory nil regexp))
         (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)
  "..."
  (interactive "P")
  (next-image t))

> > 1. Use Icicles.  `C-x C-f', then cycle using `up'/`down'.  
> >    When a file is an image file the image is displayed.
> >    To cycle among only files `foo*', type `foo' then cycle.
> 
> Hmm, I tried to use icicles, but it seems to fight with ido, which I
> am using. If they can't figure it out, I am with ido.  But at the
> moment, I am not sure this is the route I want to take.

http://www.emacswiki.org/emacs/Icicles_-_Ido_and_IswitchB

> > 2. Use `image-dired'. Use `right'/`left' + `RET' in the 
> >    thumbnails buffer to cycle among images.
> 
> I also looked at image-dired, but that seems to be a different use
> case.  If there was a way to make the thumbnails larger, it might be
> useful in some ways, but not for my main purpose.

image-dired-thumb-size, `image-dired-thumb-width', and
`image-dired-thumb-height' should let you control the size.




reply via email to

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