bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#27435: patch for dired-mouse-find-file-other-window


From: Tak Kunihiro
Subject: bug#27435: patch for dired-mouse-find-file-other-window
Date: Mon, 28 Aug 2017 09:22:35 +0900

Thank you for the comments.

>>> But you could have the same effect by rebinding mouse-2 to another
>>> function.  We just need to add such a function, which should work like
>>> dired-mouse-find-file-other-window, but visit the file in the same
>>> window.  That sounds like a better alternative for this use case,
>>> because customizing a function-valued variable is trickier for users
>>> than rebinding keys.
>> 
>> Then the new function `dired-mouse-find-file-this-window' will look
>> very similar to `dired-mouse-find-file-other-window' but two lines.
>> Is that OK?
> 
> We could factor out the common part into a new function, and then make
> those two functions call it.

> FWIW: Conventionally, we add `-other-window' or `-other-frame'

> to the same-window command name, which lacks any such suffix.
> IOW, typically we do not use `-this-window'.
> 
> FWIW2: Dired+ has had such a same-window mouse command since
> 1999 (if not before).  There is also an `-other-frame' version.


With the suggestions, I created two functions.

 - dired-mouse-find-file (new, this inherits common part)
 - dired-mouse-find-file-other-window
 - dired-mouse-find-file-other-frame (new)

I attach the patch.  This does not change the default behavior.

diff --git a/dired.252.el b/dired.el
index 39dc29e..3a4bbce 100644
--- a/dired.252.el
+++ b/dired.el
@@ -2117,9 +2117,12 @@ directory in another window."
 ;; Don't override the setting from .emacs.
 ;;;###autoload (put 'dired-find-alternate-file 'disabled t)
 
-(defun dired-mouse-find-file-other-window (event)
-  "In Dired, visit the file or directory name you click on."
+(defun dired-mouse-find-file (event &optional find-file-func find-dir-func)
+  "In Dired, visit the file or directory name you click on.
+FIND-FILE-FUNC and FIND-DIR-FUNC specify functions to visit the file and 
directory, respectively."
   (interactive "e")
+  (or find-file-func (setq find-file-func 'find-file))
+  (or find-dir-func (setq find-file-func 'find-alternate-file))
   (let (window pos file)
     (save-excursion
       (setq window (posn-window (event-end event))
@@ -2134,9 +2137,19 @@ directory in another window."
                  (dired-goto-subdir file))
             (progn
               (select-window window)
-             (dired-other-window file)))
+              (funcall find-dir-func file)))
       (select-window window)
-      (find-file-other-window (file-name-sans-versions file t)))))
+      (funcall 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 other window."
+  (interactive "e")
+  (dired-mouse-find-file event 'find-file-other-window 'dired-other-window))
+
+(defun dired-mouse-find-file-other-frame (event)
+  "In Dired, visit the file or directory name you click on other frame."
+  (interactive "e")
+  (dired-mouse-find-file event 'find-file-other-frame 'dired-other-frame))
 
 (defun dired-view-file ()
   "In Dired, examine a file in view mode, returning to Dired when done.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]