From: Lars Ingebrigtsen Date: Wed, 9 Oct 2019 05:00:34 +0000 (+0200) Subject: Move point in the dired buffer with `n'/`p' in an image-mode buffer X-Git-Tag: emacs-27.0.90~1204 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e8dd6c9d832faf8445fccbc65f05a5e6e6d48ba7;p=emacs.git Move point in the dired buffer with `n'/`p' in an image-mode buffer * lisp/image-mode.el (image-next-file): If the image is in a dired buffer, then move point in that buffer when advancing (bug#21752). This makes it easier to select images. --- diff --git a/lisp/image-mode.el b/lisp/image-mode.el index a869907669c..342102568ca 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el @@ -982,7 +982,19 @@ replacing the current Image mode buffer." (throw 'image-visit-next-file (1+ idx))) (setq idx (1+ idx)))) (setq idx (mod (+ idx (or n 1)) (length images))) - (find-alternate-file (nth idx images)))) + (let ((image (nth idx images)) + (dir (file-name-directory buffer-file-name))) + (find-alternate-file image) + ;; If we have dired buffer(s) open to where this image is, then + ;; place point on it. + (dolist (buffer (buffer-list)) + (with-current-buffer buffer + (when (and (derived-mode-p 'dired-mode) + (equal (file-truename dir) + (file-truename default-directory))) + (save-window-excursion + (switch-to-buffer (current-buffer) t t) + (dired-goto-file (expand-file-name image dir))))))))) (defun image-previous-file (&optional n) "Visit the preceding image in the same directory as the current file.