From: Lars Ingebrigtsen Date: Sat, 12 Dec 2020 11:48:53 +0000 (+0100) Subject: Preserve point in dired buffers in dired-*-find-file* commands X-Git-Tag: emacs-28.0.90~4763 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=6e84addc51f3817052d852b73f00057a9af5b9c8;p=emacs.git Preserve point in dired buffers in dired-*-find-file* commands * 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. --- diff --git a/lisp/dired.el b/lisp/dired.el index 6ad2497c9a9..baf99da7b48 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -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."