For me, C-h f dired-toggle-marks
describes the command and has a link to its source code (definition). Do you not see a link to file dired.el
from C-h f
? If you see it, does it take you to the definition? In case it doesn't, this the definition (in Emacs 24.5, for example):
(defun dired-toggle-marks ()
"Toggle marks: marked files become unmarked, and vice versa.
Files marked with other flags (such as `D') are not affected.
`.' and `..' are never toggled.
As always, hidden subdirs are not affected."
(interactive)
(save-excursion
(goto-char (point-min))
(let ((inhibit-read-only t))
(while (not (eobp))
(or (dired-between-files)
(looking-at-p dired-re-dot)
;; use subst instead of insdel because it does not move
;; the gap and thus should be faster and because
;; other characters are left alone automatically
(apply 'subst-char-in-region
(point) (1+ (point))
(if (eq ?\040 (following-char)) ; SPC
(list ?\040 dired-marker-char)
(list dired-marker-char ?\040))))
(forward-line 1)))))
Does that give you what you need?
As for why there is no command to toggle the mark status for only the current file/dir, the answer is probably that no one has felt the need for it.
Are you looking for such a function for use in code, or are you looking for it as a command, to use it interactively? For the latter, you can see whether the file/dir is marked or not, so you know whether you want to mark or unmark it.
Or is it that you want to reduce the two key bindings m
and u
to a single one?
Note that the keys m
and u
are more general than just marking and unmarking the current line's file/dir. They act on the next N lines. It's probably because of this generality, and the fact that you can see whether you want to mark or unmark the current line, that there is no toggle-mark-only-here
command.
I suppose that a command that toggles marking the current or next N lines could be useful, but I'm guessing that people haven't felt the need for it. In any case, that should be easy for you to define, now that you have the source for dired-toggle-marks
. (You could alternatively start with the code for dired-mark
and `dired-unmark.)
I'm guessing you don't really need the code that does what you want as an answer here, and that you will enjoy writing it. But if not, please say so and I (or someone else) will post some code for it here.
Something related, which might be of interest:
With Dired+ clicking mouse-3
brings up a menu of actions for the file/dir of the current line. If that is unmarked then you'll see menu-item Mark, and if it is marked then you'll see item Unmark. In other words, the menu item name is toggled, along with its action.