notes from /dev/null

by Charles Choi 최민수


Calming Mouse Interaction in Dired

07 Apr 2026  Charles Choi

Conventional file managers have conditioned me to expect that a single left-button mouse click (<mouse-1>) will select a file (or directory) and double-click will open it. This is not the default behavior of Dired, where a single click is an open action. I find this far too twitchy for my taste.

This post shows how to make Dired mouse interaction align with a conventional file manager where:

  • Single-click on a file or directory will move the point to it, making it the implicit target for any subsequent Dired command.

  • Left double-click on file or directory will open it.

  • Selecting multiple files is emulated using Dired marking, in this case using the binding M-<mouse-1> to toggle marking a file.

The first two points above can be addressed with the global variable mouse-1-click-follows-link. Dired uses this variable to control its mouse behavior, but we don’t want to change it everywhere, just for Dired buffers. This can be implemented by setting mouse-1-click-follows-link locally as a hook to dired-mode-hook:

1
2
3
4
(add-hook
 'dired-mode-hook
 (lambda ()
   (setq-local mouse-1-click-follows-link 'double)))

To address multiple file selection, we can define a function cc/dired-mouse-toggle-mark and bind it to M-<mouse-1>.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
(defun cc/dired-mouse-toggle-mark ()
  "Toggle mark of a Dired item via mouse."
  (interactive)
  (unless (use-region-p)
    (mouse-set-point last-input-event)
    (if (char-equal (char-after (line-beginning-position)) dired-marker-char)
        (call-interactively #'dired-unmark)
      (call-interactively #'dired-mark))))

(keymap-set dired-mode-map "M-<mouse-1>" #'cc/dired-mouse-toggle-mark)

Coupled with Anju support for a Dired specific context menu and many basic file manager operations can be done in Dired via mouse with minimal fuss.

emacs   anju

 

AboutMastodonBlueskyGitHub

Feeds & Tags
Get Scrim for macOSGet Captee for macOS

Powered by Pelican