3

When I click with mouse-1 in dired it will open a new frame with the selected file. When I press return on the same file it will open the file in the same frame. How can I synchronize this behavior? I.e. I want mouse-1 to behave the same as return.

Furthermore I have the following problem. The mouse-1 down event seems to work fine, but the up event seems to be registered as mouse-2:

<down-mouse-1> at that spot runs the command mouse-drag-region, which is an interactive compiled Lisp function
in `mouse.el'.

It is bound to <down-mouse-1>.

(mouse-drag-region START-EVENT)

Set the region to the text that the mouse is dragged over.
Highlight the drag area as you move the mouse.
This must be bound to a button-down mouse event.
In Transient Mark mode, the highlighting remains as long as the mark
remains active.  Otherwise, it remains until the next input event.

If the click is in the echo area, display the `*Messages*' buffer.

----------------- up-event ----------------

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

It is bound to <mouse-2>.

(dired-mouse-find-file-other-window EVENT)

In Dired, visit the file or directory name you click on.

[back]
3

Bind mouse-1 to the command you want:

(define-key dired-mode-map [mouse-1] 'dired-find-file)

Or bind it to a command that is like dired-mouse-find-file-other-window but uses the same window.

(defun dired-mouse-find-file (event)
  "In Dired, visit the file or directory name you click on."
  (interactive "e")
  (let (window pos file)
    (save-excursion
      (setq window (posn-window (event-end event))
            pos (posn-point (event-end event)))
      (if (not (windowp window))
      (error "No file chosen"))
      (set-buffer (window-buffer window))
      (goto-char pos)
      (setq file (dired-get-file-for-visit)))
    (if (file-directory-p file)
    (or (and (cdr dired-subdir-alist)
             (dired-goto-subdir file))
        (progn
          (select-window window)
          (dired-other-window file)))
      (select-window window)
      (find-file-window (file-name-sans-versions file t)))))

(define-key dired-mode-map [mouse-1] 'dired-mouse-find-file)
  • This would be a nice solution, except that it does not work... When I hit C-h k in dired and mouse-1 click a file, it says: <mouse-2> at that spot runs the command dired-mouse-find-file-other-window, which is an interactive compiled Lisp function in `dired.el'. – Arne Mar 10 '16 at 22:07
  • Why it thinks it has a mouse-2 up event, is beyond my imagination! – Arne Mar 10 '16 at 22:07
  • Ok, if I change the dried-mode-map to use mouse-2 and change find-file-window to find-file, it works. – Arne Mar 10 '16 at 22:26
  • Second update: clicking on a file works fine, clicking on a directory opens it in a new frame... glancing at the code, I do not yet see why. – Arne Mar 10 '16 at 22:32
  • Third update: using dired-find-file instead of the above dired-mouse-find-file works fine. Thanks! – Arne Mar 10 '16 at 22:41

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.