]> git.eshelyaron.com Git - emacs.git/commitdiff
Preserve point in dired buffers in dired-*-find-file* commands
authorLars Ingebrigtsen <larsi@gnus.org>
Sat, 12 Dec 2020 11:48:53 +0000 (12:48 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Sat, 12 Dec 2020 11:48:53 +0000 (12:48 +0100)
* lisp/dired.el (dired--find-file): New function (bug#28949).
(dired-find-file): Use it.
(dired-mouse-find-file): Ditto.
(dired-find-file-other-window): Ditto.

lisp/dired.el

index 6ad2497c9a93faa5ea96b47ba74dd16c7c6fd429..baf99da7b48203406e1bee1e0e027dae9e130f41 100644 (file)
@@ -2501,6 +2501,10 @@ directory in another window."
 (defun dired-find-file ()
   "In Dired, visit the file or directory named on this line."
   (interactive)
+  (dired--find-file #'find-file (dired-get-file-for-visit)))
+
+(defun dired--find-file (find-file-function file)
+  "Call FIND-FILE-FUNCTION on FILE, but bind some relevant variables."
   ;; Bind `find-file-run-dired' so that the command works on directories
   ;; too, independent of the user's setting.
   (let ((find-file-run-dired t)
@@ -2513,7 +2517,7 @@ directory in another window."
          (if dired-auto-revert-buffer
              nil
            switch-to-buffer-preserve-window-point)))
-    (find-file (dired-get-file-for-visit))))
+    (funcall find-file-function file)))
 
 (defun dired-find-alternate-file ()
   "In Dired, visit file or directory on current line via `find-alternate-file'.
@@ -2549,7 +2553,7 @@ respectively."
              (select-window window)
               (funcall find-dir-func file)))
       (select-window window)
-      (funcall find-file-func (file-name-sans-versions file t)))))
+      (dired--find-file find-file-func (file-name-sans-versions file t)))))
 
 (defun dired-mouse-find-file-other-window (event)
   "In Dired, visit the file or directory name you click on in another window."
@@ -2576,7 +2580,7 @@ Otherwise, display it in another buffer."
 (defun dired-find-file-other-window ()
   "In Dired, visit this file or directory in another window."
   (interactive)
-  (find-file-other-window (dired-get-file-for-visit)))
+  (dired--find-file #'find-file-other-window (dired-get-file-for-visit)))
 
 (defun dired-display-file ()
   "In Dired, display this file or directory in another window."