]> git.eshelyaron.com Git - emacs.git/commitdiff
Move point in the dired buffer with `n'/`p' in an image-mode buffer
authorLars Ingebrigtsen <larsi@gnus.org>
Wed, 9 Oct 2019 05:00:34 +0000 (07:00 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Wed, 9 Oct 2019 05:00:39 +0000 (07:00 +0200)
* 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.

lisp/image-mode.el

index a869907669ce1273d8941ad239b36e8cb4a98c7a..342102568ca4cbf2c8348a661f1dbbe5b3e1d6ca 100644 (file)
@@ -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.