3

I am currently using the diredp-toggle-find-file-reuse-dir feature of Dired+ so that selecting a directory in a dired buffer opens the directory in the current buffer as described here. However, it seems that I only get this "re-use" functionality with <S-down-mouse-2>. Pressing <down-mouse-1> still causes directories to be opened in their own buffer.

I tried doing the (seemingly) obvious thing of setting the key binding directly

(define-key dired-mode-map [down-mouse-1] 'diredp-mouse-find-file-reuse-dir)

but I got strange behavior that basically looked as though I had clicked twice.

What do I need to do so that a single mouse click reuses the current dired buffer when opening a directory?

3
(define-key dired-mode-map (kbd "<mouse-2>") 'diredp-mouse-find-file)

If you did C-h k and then clicked mouse-1 on a file or directory it would have told you:

<down-mouse-1> at that spot runs the command mouse-drag-region, which...

<mouse-2> at that spot runs the command dired-mouse-find-file-other-window, which is an interactive Lisp function in dired+.el.

It is bound to <mouse-2>.

(It talks about mouse-2 because that is the binding. But by default option mouse-1-click-follows-link is non-nil. So your mouse-1 acts like mouse-2 on a link. That's vanilla Emacs. And no, the help is not as helpful as it should be.)

Dired+ chooses to have the mouse open stuff in another window, by default. The key binding above will change that. (There are other ways to accomplish the same thing.)


I rolled back your edit. In general, it should be mouse-2 that you bind here, not mouse-1. Links work with mouse-2 clicks. They can additionally work with mouse-1 clicks, if option mouse-1-click-follows-link is non-nil, which it is by default. But the proper key binding is for mouse-2, and the proper way to extend this to mouse-1 is to use the option.

(FWIW, I turn off mouse-1-click-follows-link, because I prefer the original Emacs behavior of mouse-2 (only) for links. I want mouse-1 to always act like mouse-1, even on links. I don't want to have to wait a moment, just to set point in the middle of a link.)

  • Is there a reason that the setup function for reuse-dir doesn't do this automatically in dired+? It seems to be the advertised functionality. – nispio May 10 '16 at 22:41
  • Why <mouse-2>? That's not what I'm asking for, and not what I want. – nispio May 10 '16 at 22:43
  • See my explanation. If you use non-nil mouse-1-click-follows-link (the default) then it is the option that makes mouse-1 follow links. If you are very unusual (;-)) then you can of course bind mouse-1 here and not have mouse-2 also have the same behavior. My answer is for everyone, and it should also answer your problem. Unless you really want mouse-2 to do something different, just bind mouse-2 here and let the option extend the link-following behavior, as usual, to mouse-1 also. – Drew May 10 '16 at 22:50
  • The answer to your first comment is that it does what it says. C-M-R (diredp-toggle-find-file-reuse-dir) acts only on dired-find-file, and diredp-mouse-find-file. It does not act on -other-window commands (e.g. dired-mouse-find-file-other-window). – Drew May 10 '16 at 22:55
  • I've updated the doc string of diredp-toggle-find-file-reuse-dir to try to make this more clear. – Drew May 10 '16 at 23:58
0

Existing answer didn't work for me. I had to look other solutions. Emacs: Dired Customization By Xah LeeThis page helped me.

(require 'dired)
(put 'dired-find-alternate-file 'disabled nil)
(define-key dired-mode-map (kbd "<mouse-2>") 'dired-find-alternate-file)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.