* extension for image view to go to next or previous image
@ 2011-04-08 1:49 chris
2011-04-08 6:34 ` Thierry Volpiatto
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: chris @ 2011-04-08 1:49 UTC (permalink / raw)
To: help-gnu-emacs
Hi there,
I am frequently viewing images in emacs that are part of a sequence,
therefore I am missing a way to go the next or previous image. I was
wondering if this is possible somehow already? Or maybe somebody can
show me how to do this with elisp? The filenames for these images are
chosen in a way that sorting by name brings them in the right order,
also usually the directory that contains them is open in a dired
buffer, so if necessary, maybe one could retrieve the position of the
current image and then simply get the name of the next image from
there?
Any help would be greatly appreciated,
Chris
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: extension for image view to go to next or previous image
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
` (2 subsequent siblings)
3 siblings, 0 replies; 11+ messages in thread
From: Thierry Volpiatto @ 2011-04-08 6:34 UTC (permalink / raw)
To: help-gnu-emacs
chris <cwittern@gmail.com> writes:
> Hi there,
>
> I am frequently viewing images in emacs that are part of a sequence,
> therefore I am missing a way to go the next or previous image. I was
> wondering if this is possible somehow already? Or maybe somebody can
> show me how to do this with elisp? The filenames for these images are
> chosen in a way that sorting by name brings them in the right order,
> also usually the directory that contains them is open in a dired
> buffer, so if necessary, maybe one could retrieve the position of the
> current image and then simply get the name of the next image from
> there?
>
> Any help would be greatly appreciated,
You can use iterators to do that.
You can find some of my iterators functions actually in ioccur.el,
the iterator package on emacswiki is no more updated/maintained.
http://mercurial.intuxication.org/hg/ioccur
Use it like this:
--8<---------------cut here---------------start------------->8---
ELISP> (setq A (ioccur-iter-list '("img1.jpg" "img2.jpg" "img3.jpg" "img4.jpg" "img5.jpg")))
ELISP> (ioccur-iter-next A)
"img1.jpg"
ELISP> (ioccur-iter-next A)
"img2.jpg"
ELISP> (ioccur-iter-next A)
"img3.jpg"
--8<---------------cut here---------------end--------------->8---
When you want to go back, create a new iterator from the last element to
beginning of sequence.
To go forward again, same recreate an iterator etc...
You can also create infinite iterators.
(See ioccur-iter-circular)
--
A+ Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997
^ permalink raw reply [flat|nested] 11+ messages in thread
* RE: extension for image view to go to next or previous image
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>
[not found] ` <mailman.20.1302244507.25447.help-gnu-emacs@gnu.org>
3 siblings, 0 replies; 11+ messages in thread
From: Drew Adams @ 2011-04-08 13:55 UTC (permalink / raw)
To: 'chris', help-gnu-emacs
> I am frequently viewing images in emacs that are part of a sequence,
> therefore I am missing a way to go the next or previous image. I was
> wondering if this is possible somehow already? Or maybe somebody can
> show me how to do this with elisp? The filenames for these images are
> chosen in a way that sorting by name brings them in the right order,
> also usually the directory that contains them is open in a dired
> buffer, so if necessary, maybe one could retrieve the position of the
> current image and then simply get the name of the next image from
> there?
>
> Any help would be greatly appreciated,
Here are a couple of ways I would do it - there are no doubt other ways.
Essentially, you just need a way to cycle among files.
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.
To cycle among files matching `foo' as a substring, do the same thing, but
either cycle using `next'/`prior' or hit `S-TAB' to initiate apropos completion
before using `up'/`down' to cycle.
You can use `S-SPC' to add other patterns to match, regardless of order - e.g.
`C-x C-f foo S-TAB S-SPC bar S-SPC toto' matches file names with `foo', `bar',
and `toto', in any order. You can use a regexp for any of the match patterns.
If you hit `TAB' or `S-TAB' you see the file names, in *Completions*, that match
what you type. By default, for image files you see thumbnail images next to the
file names there. You can hit `C-x t' to show only file names or only
thumbnails: `C-x t' cycles among the 3 image-candidate display types.
2. Use `image-dired'. Use `right'/`left' + `RET' in the thumbnails buffer to
cycle among images.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: extension for image view to go to next or previous image
[not found] ` <mailman.9.1302270960.11168.help-gnu-emacs@gnu.org>
@ 2011-04-08 23:07 ` chris
2011-04-09 0:28 ` Drew Adams
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: chris @ 2011-04-08 23:07 UTC (permalink / raw)
To: help-gnu-emacs
Thank you Drew, I tried your suggestions.
On Apr 8, 10:55 pm, "Drew Adams" <drew.ad...@oracle.com> wrote:
> Here are a couple of ways I would do it - there are no doubt other ways.
> Essentially, you just need a way to cycle among files.
Yeah in a way this is true, but what I had in mind was a bit of lisp
code that would allow me to press 'n' (or SPC) on an image and then
see the next one, 'p' would get me the previous one.
>
> 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.
> 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.
All the best,
Chris
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: extension for image view to go to next or previous image
[not found] ` <mailman.20.1302244507.25447.help-gnu-emacs@gnu.org>
@ 2011-04-08 23:11 ` chris
2011-04-09 5:39 ` Thierry Volpiatto
0 siblings, 1 reply; 11+ messages in thread
From: chris @ 2011-04-08 23:11 UTC (permalink / raw)
To: help-gnu-emacs
Dear Thierry,
On Apr 8, 3:34 pm, Thierry Volpiatto <thierry.volpia...@gmail.com>
wrote:
>
> You can use iterators to do that.
I never had heard of it iterators in elisp, but they look useful. But
it is a pity they can only go in one direction. Anyway, I will check
out ioccur.
I still think that maybe finding a way to "remote control" dired would
be the easiest solution, than I would simply have the dired buffer in
the background and get the info about which file comes next or
previous from there.
But I am still stuck at how to practically do that...
All the best,
Chris
^ permalink raw reply [flat|nested] 11+ messages in thread
* RE: extension for image view to go to next or previous image
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 5:32 ` Thierry Volpiatto
2 siblings, 0 replies; 11+ messages in thread
From: Drew Adams @ 2011-04-09 0:28 UTC (permalink / raw)
To: 'chris', help-gnu-emacs
> 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.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: extension for image view to go to next or previous image
[not found] ` <mailman.12.1302309090.11006.help-gnu-emacs@gnu.org>
@ 2011-04-09 1:24 ` chris
2011-04-09 4:03 ` rusi
1 sibling, 0 replies; 11+ messages in thread
From: chris @ 2011-04-09 1:24 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: extension for image view to go to next or previous image
[not found] ` <mailman.12.1302309090.11006.help-gnu-emacs@gnu.org>
2011-04-09 1:24 ` chris
@ 2011-04-09 4:03 ` rusi
2011-04-09 15:06 ` Drew Adams
1 sibling, 1 reply; 11+ messages in thread
From: rusi @ 2011-04-09 4:03 UTC (permalink / raw)
To: help-gnu-emacs
On Apr 9, 5:28 am, "Drew Adams" <drew.ad...@oracle.com> wrote:
> > 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
Of late Ive been having clashes between icicles and org-mode (C-c =
and other things related to tables spreadsheets etc). I generally
shut off icicles and proceed. But this reminds me is there a page
like the above for org vs icicles keybinding clashes?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: extension for image view to go to next or previous image
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 5:32 ` Thierry Volpiatto
2 siblings, 0 replies; 11+ messages in thread
From: Thierry Volpiatto @ 2011-04-09 5:32 UTC (permalink / raw)
To: help-gnu-emacs
chris <cwittern@gmail.com> writes:
> Thank you Drew, I tried your suggestions.
>
> On Apr 8, 10:55 pm, "Drew Adams" <drew.ad...@oracle.com> wrote:
>> Here are a couple of ways I would do it - there are no doubt other ways.
>> Essentially, you just need a way to cycle among files.
>
> Yeah in a way this is true, but what I had in mind was a bit of lisp
> code that would allow me to press 'n' (or SPC) on an image and then
> see the next one, 'p' would get me the previous one.
>
>>
>> 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.
>
>> 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.
See also anything-find-files which can be turned in an image browser
with possibility to rotate images on the fly and is very simple to use.
http://repo.or.cz/w/anything-config.git
You will find anything.pdf in doc directory with explanation.
--
A+ Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: extension for image view to go to next or previous image
2011-04-08 23:11 ` chris
@ 2011-04-09 5:39 ` Thierry Volpiatto
0 siblings, 0 replies; 11+ messages in thread
From: Thierry Volpiatto @ 2011-04-09 5:39 UTC (permalink / raw)
To: help-gnu-emacs
chris <cwittern@gmail.com> writes:
> Dear Thierry,
>
>
> On Apr 8, 3:34 pm, Thierry Volpiatto <thierry.volpia...@gmail.com>
> wrote:
>>
>> You can use iterators to do that.
>
> I never had heard of it iterators in elisp, but they look useful. But
> it is a pity they can only go in one direction.
They go in two directions, see the circular functions.
>Anyway, I will check
> out ioccur.
>
> I still think that maybe finding a way to "remote control" dired would
> be the easiest solution, than I would simply have the dired buffer in
> the background and get the info about which file comes next or
> previous from there.
anything-find-files can be seen as a virtual dired and does this.
--
A+ Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997
^ permalink raw reply [flat|nested] 11+ messages in thread
* RE: extension for image view to go to next or previous image
2011-04-09 4:03 ` rusi
@ 2011-04-09 15:06 ` Drew Adams
0 siblings, 0 replies; 11+ messages in thread
From: Drew Adams @ 2011-04-09 15:06 UTC (permalink / raw)
To: 'rusi', help-gnu-emacs
> > http://www.emacswiki.org/emacs/Icicles_-_Ido_and_IswitchB
>
> Of late Ive been having clashes between icicles and org-mode (C-c =
> and other things related to tables spreadsheets etc). I generally
> shut off icicles and proceed. But this reminds me is there a page
> like the above for org vs icicles keybinding clashes?
1. The page cited above is not about keybinding clashes.
2. Keys such as `C-c =' are reserved for minor modes. From `(elisp) Key Binding
Conventions': "Sequences consisting of `C-c' followed by any other punctuation
character [other than { } < > : and ;] are allocated for minor modes."
`icicle-mode' is a minor mode. There is nothing abnormal about two minor modes
defining a key such as `C-c =' differently.
3. If Org defines `C-c =' as a major- (not just a minor-) mode key binding
(which it seems to: `org-table-eval-formula') then that is perhaps a bit
ill-advised, but it is not verboten.
Again, from the same Elisp manual page, same paragraph: "Using them [keys such
as `C-c ='] in a _major_ mode is not absolutely prohibited, but if you do that,
the major mode binding may be shadowed from time to time by minor modes."
IOW, a major mode that goes ahead and does this should expect that the key will
be shadowed by minor modes.
4. What is important is that any library you use provide you (a) a
straightforward way to change or remove such key bindings and (b) good doc about
them.
4a. Icicles gives you a user option that lets you easily change or remove such
key bindings: `icicle-top-level-key-bindings'. You do not even need to know any
Lisp to do this.
For example, it is trivial to either remove this entry from
`icicle-top-level-key-bindings' or assign a different key to the same command:
[INS] [DEL] <== Click DEL to remove the key binding
Key: C-c = <== Or type a different key name, to change key
Command: icicle-imenu
4b. This is all clearly documented. There is even a screenshot of the Customize
interface for `icicle-top-level-key-bindings' (second URL) - `C-c =' is the 3rd
binding shown in the screenshot.
http://www.emacswiki.org/emacs/Icicles_-_Customizing_Key_Bindings
http://www.emacswiki.org/emacs/Icicles_-_Key_Bindings
If you are toggling Icicle mode off and on just because of such a key binding,
then you owe it to yourself, I suggest, to look at the doc to learn about
Icicles keys and how to change them.
5. If you think you see a bug, doc or code, then send a _specific recipe_,
starting with emacs -Q: `M-x icicle-send-bug-report'.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2011-04-09 15:06 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).