1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

Do interactive tagging for dired commands

* lisp/dired-aux.el (dired-diff, dired-backup-diff)
(dired-compare-directories, dired-do-chmod, dired-do-chgrp)
(dired-do-chown, dired-do-touch, dired-do-print, dired-clean-directory)
(dired-do-async-shell-command, dired-do-shell-command, dired-kill-line)
(dired-do-kill-lines, dired-do-compress-to, dired-do-compress)
(dired-do-byte-compile, dired-do-load, dired-do-redisplay)
(dired-reset-subdir-switches, dired-create-directory)
(dired-create-empty-file, dired-do-copy, dired-do-symlink)
(dired-do-relsymlink, dired-do-hardlink, dired-do-rename)
(dired-do-rename-regexp, dired-do-copy-regexp, dired-do-hardlink-regexp)
(dired-do-symlink-regexp, dired-do-relsymlink-regexp, dired-upcase)
(dired-downcase, dired-maybe-insert-subdir, dired-insert-subdir)
(dired-kill-tree, dired-prev-subdir, dired-mark-subdir-files)
(dired-kill-subdir, dired-tree-up, dired-tree-down, dired-hide-subdir)
(dired-hide-all, dired-isearch-filenames, dired-isearch-filenames-regexp)
(dired-do-isearch, dired-do-isearch-regexp, dired-do-search)
(dired-do-query-replace-regexp, dired-do-find-regexp)
(dired-do-find-regexp-and-replace, dired-show-file-type)
(dired-vc-next-action):
* lisp/dired-x.el (dired-mark-extension, dired-mark-suffix)
(dired-flag-extension, dired-clean-patch, dired-clean-tex)
(dired-very-clean-tex, dired-mark-omitted, dired-omit-expunge)
(dired-mark-unmarked-files, dired-do-find-marked-files, dired-vm)
(dired-rmail, dired-do-run-mail, dired-mark-sexp,
dired-x-bind-find-file):
* lisp/dired.el (dired-mouse-drag, dired-undo, dired-toggle-read-only)
(dired-next-line, dired-previous-line, dired-next-dirline)
(dired-prev-dirline, dired-up-directory, dired-get-file-for-visit)
(dired-find-file, dired-find-alternate-file, dired-mouse-find-file)
(dired-mouse-find-file-other-window, dired-mouse-find-file-other-frame)
(dired-view-file, dired-find-file-other-window, dired-display-file)
(dired-copy-filename-as-kill, dired-next-subdir)
(dired-build-subdir-alist, dired-goto-file, dired-do-flagged-delete)
(dired-do-delete, dired-next-marked-file, dired-prev-marked-file)
(dired-mark, dired-unmark, dired-flag-file-deletion)
(dired-unmark-backward, dired-toggle-marks, dired-mark-files-regexp)
(dired-number-of-marked-files, dired-mark-files-containing-regexp)
(dired-flag-files-regexp, dired-mark-symlinks, dired-mark-directories)
(dired-mark-executables, dired-flag-auto-save-files)
(dired-flag-garbage-files, dired-flag-backup-files, dired-change-marks)
(dired-unmark-all-marks, dired-unmark-all-files)
(dired-sort-toggle-or-edit, dired-mark-for-click)
(dired-enable-click-to-select-mode): Tag commands as applicable only
for dired-mode.
This commit is contained in:
Visuwesh 2023-10-29 20:21:57 +05:30 committed by Eli Zaretskii
parent bb64e3a798
commit 1c70458519
3 changed files with 132 additions and 114 deletions

View file

@ -1823,7 +1823,7 @@ see `dired-use-ls-dired' for more details.")
"Begin a drag-and-drop operation for the file at EVENT.
If there are marked files and that file is marked, drag every
other marked file as well. Otherwise, unmark all files."
(interactive "e")
(interactive "e" dired-mode)
(when mark-active
(deactivate-mark))
(let* ((modifiers (event-modifiers event))
@ -2662,7 +2662,7 @@ Keybindings:
"Undo in a Dired buffer.
This doesn't recover lost files, it just undoes changes in the buffer itself.
You can use it to recover marks, killed lines or subdirs."
(interactive)
(interactive nil dired-mode)
(let ((inhibit-read-only t))
(undo))
(dired-build-subdir-alist)
@ -2674,7 +2674,7 @@ Actual changes in files cannot be undone by Emacs."))
If the current buffer can be edited with Wdired, (i.e. the major
mode is `dired-mode'), call `wdired-change-to-wdired-mode'.
Otherwise, toggle `read-only-mode'."
(interactive)
(interactive nil dired-mode)
(unless (file-exists-p default-directory)
(user-error "The current directory no longer exists"))
(when (and (not (file-writable-p default-directory))
@ -2703,7 +2703,7 @@ to move; the default is one line.
Whether to skip empty lines and how to move from last line
is controlled by `dired-movement-style'."
(interactive "^p")
(interactive "^p" dired-mode)
(if dired-movement-style
(let ((old-position (progn
;; It's always true that we should move
@ -2750,12 +2750,12 @@ to move; the default is one line.
Whether to skip empty lines and how to move from first line
is controlled by `dired-movement-style'."
(interactive "^p")
(interactive "^p" dired-mode)
(dired-next-line (- (or arg 1))))
(defun dired-next-dirline (arg &optional opoint)
"Goto ARGth next directory file line."
(interactive "p")
(interactive "p" dired-mode)
(or opoint (setq opoint (point)))
(if (if (> arg 0)
(re-search-forward dired-re-dir nil t arg)
@ -2767,7 +2767,7 @@ is controlled by `dired-movement-style'."
(defun dired-prev-dirline (arg)
"Goto ARGth previous directory file line."
(interactive "p")
(interactive "p" dired-mode)
(dired-next-dirline (- arg)))
(defun dired-up-directory (&optional other-window)
@ -2776,7 +2776,7 @@ Find the parent directory either in this buffer or another buffer.
Creates a buffer if necessary.
If OTHER-WINDOW (the optional prefix arg), display the parent
directory in another window."
(interactive "P")
(interactive "P" dired-mode)
(let* ((dir (dired-current-directory))
(up (file-name-directory (directory-file-name dir))))
(or (dired-goto-file (directory-file-name dir))
@ -2791,7 +2791,7 @@ directory in another window."
(defun dired-get-file-for-visit ()
"Get the current line's file name, with an error if file does not exist."
(interactive)
(interactive nil dired-mode)
;; We pass t for second arg so that we don't get error for `.' and `..'.
(let ((raw (dired-get-filename nil t))
file-name)
@ -2811,7 +2811,7 @@ directory in another window."
#'dired-find-file "23.2")
(defun dired-find-file ()
"In Dired, visit the file or directory named on this line."
(interactive)
(interactive nil dired-mode)
(dired--find-possibly-alternative-file (dired-get-file-for-visit)))
(defun dired--find-possibly-alternative-file (file)
@ -2843,7 +2843,7 @@ directory in another window."
(defun dired-find-alternate-file ()
"In Dired, visit file or directory on current line via `find-alternate-file'.
This kills the Dired buffer, then visits the current line's file or directory."
(interactive)
(interactive nil dired-mode)
(set-buffer-modified-p nil)
(find-alternate-file (dired-get-file-for-visit)))
;; Don't override the setting from .emacs.
@ -2857,7 +2857,7 @@ omitted or nil, these arguments default to `find-file' and `dired',
respectively. If `dired-kill-when-opening-new-dired-buffer' is
non-nil, FIND-DIR-FUNC defaults to `find-alternate-file' instead,
so that the original Dired buffer is not kept."
(interactive "e")
(interactive "e" dired-mode)
(or find-file-func (setq find-file-func 'find-file))
(let (window pos file)
(save-excursion
@ -2885,19 +2885,19 @@ so that the original Dired buffer is not kept."
(defun dired-mouse-find-file-other-window (event)
"In Dired, visit the file or directory name you click on in another window."
(interactive "e")
(interactive "e" dired-mode)
(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 in another frame."
(interactive "e")
(interactive "e" dired-mode)
(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.
When file is a directory, show it in this buffer if it is inserted.
Otherwise, display it in another buffer."
(interactive)
(interactive nil dired-mode)
(let ((file (dired-get-file-for-visit)))
(if (file-directory-p file)
(or (and (cdr dired-subdir-alist)
@ -2907,12 +2907,12 @@ Otherwise, display it in another buffer."
(defun dired-find-file-other-window ()
"In Dired, visit this file or directory in another window."
(interactive)
(interactive nil dired-mode)
(dired--find-file #'find-file-other-window (dired-get-file-for-visit)))
(defun dired-display-file ()
"In Dired, display this file or directory in another window."
(interactive)
(interactive nil dired-mode)
(display-buffer (find-file-noselect (dired-get-file-for-visit))
t))
@ -3249,7 +3249,7 @@ If on a subdir headerline, use absolute subdirname instead;
prefix arg and marked files are ignored in this case.
You can then feed the file name(s) to other commands with \\[yank]."
(interactive "P")
(interactive "P" dired-mode)
(let* ((files
(or (ensure-list (dired-get-subdir))
(if arg
@ -3435,7 +3435,7 @@ As a side effect, killed dired buffers for DIR are removed from
;; Use 0 arg to go to this directory's header line.
;; NO-SKIP prevents moving to end of header line, returning whatever
;; position was found in dired-subdir-alist.
(interactive "p")
(interactive "p" dired-mode)
(let ((this-dir (dired-current-directory))
pos index)
;; nth with negative arg does not return nil but the first element
@ -3456,7 +3456,7 @@ As a side effect, killed dired buffers for DIR are removed from
Returns the new value of the alist.
If optional arg SWITCHES is non-nil, use its value
instead of `dired-actual-switches'."
(interactive)
(interactive nil dired-mode)
(dired-clear-alist)
(save-excursion
(let* ((count 0)
@ -3560,7 +3560,8 @@ instead of `dired-actual-switches'."
(list (expand-file-name
(read-file-name "Goto file: "
(dired-current-directory))))
(push-mark)))
(push-mark))
dired-mode)
(unless (file-name-absolute-p file)
(error "File name `%s' is not absolute" file))
(setq file (directory-file-name file)) ; does no harm if not a directory
@ -3759,7 +3760,7 @@ If NOMESSAGE is non-nil, we don't display any message
if there are no flagged files.
`dired-recursive-deletes' controls whether deletion of
non-empty directories is allowed."
(interactive)
(interactive nil dired-mode)
(let* ((dired-marker-char dired-del-marker)
(regexp (dired-marker-regexp))
case-fold-search markers)
@ -3789,7 +3790,7 @@ non-empty directories is allowed."
non-empty directories is allowed."
;; This is more consistent with the file marking feature than
;; dired-do-flagged-delete.
(interactive "P")
(interactive "P" dired-mode)
(let (markers)
(dired-internal-do-deletions
(nreverse
@ -4093,7 +4094,7 @@ marked file is found after this line.
Optional argument OPOINT specifies the buffer position to
return to if no ARGth marked file is found; it defaults to
the position where this command was invoked."
(interactive "p\np")
(interactive "p\np" dired-mode)
(or opoint (setq opoint (point)));; return to where interactively started
(if (if (> arg 0)
(re-search-forward dired-re-mark nil t arg)
@ -4114,7 +4115,7 @@ ARG is the numeric prefix argument and defaults to 1.
If WRAP is non-nil, which happens interactively, wrap around
to the end of the buffer and search backwards from there, if
no ARGth marked file is found before this line."
(interactive "p\np")
(interactive "p\np" dired-mode)
(dired-next-marked-file (- arg) wrap))
(defun dired-file-marker (file)
@ -4153,7 +4154,7 @@ If on a subdir headerline, mark all its files except `.' and `..'.
Use \\[dired-unmark-all-files] to remove all marks
and \\[dired-unmark] on a subdir to remove the marks in
this subdir."
(interactive (list current-prefix-arg t))
(interactive (list current-prefix-arg t) dired-mode)
(cond
;; Mark files in the active region.
((and interactive dired-mark-region
@ -4192,7 +4193,7 @@ Otherwise, with a prefix arg, unmark files on the next ARG lines.
If looking at a subdir, unmark all its files except `.' and `..'.
If the region is active in Transient Mark mode, unmark all files
in the active region."
(interactive (list current-prefix-arg t))
(interactive (list current-prefix-arg t) dired-mode)
(let ((dired-marker-char ?\s))
(dired-mark arg interactive)))
@ -4204,7 +4205,7 @@ Otherwise, with a prefix arg, flag files on the next ARG lines.
If on a subdir headerline, flag all its files except `.' and `..'.
If the region is active in Transient Mark mode, flag all files
in the active region."
(interactive (list current-prefix-arg t))
(interactive (list current-prefix-arg t) dired-mode)
(let ((dired-marker-char dired-del-marker))
(dired-mark arg interactive)))
@ -4214,7 +4215,7 @@ Optional prefix ARG says how many lines to unmark/unflag; default
is one line.
If the region is active in Transient Mark mode, unmark all files
in the active region."
(interactive "p")
(interactive "p" dired-mode)
(dired-unmark (- arg) t))
(defun dired-toggle-marks ()
@ -4226,7 +4227,7 @@ As always, hidden subdirs are not affected.
In Transient Mark mode, if the mark is active, operate on the contents
of the region if `dired-mark-region' is non-nil. Otherwise, operate
on the whole buffer."
(interactive)
(interactive nil dired-mode)
(save-excursion
(let ((inhibit-read-only t)
(beg (dired-mark--region-beginning))
@ -4277,7 +4278,8 @@ object files--just `.o' will mark more than you might think."
(dired-get-filename nil t) t))
"\\'"))))
'dired-regexp-history)
(if current-prefix-arg ?\s)))
(if current-prefix-arg ?\s))
dired-mode)
(let ((dired-marker-char (or marker-char dired-marker-char)))
(dired-mark-if
(and (not (looking-at-p dired-re-dot))
@ -4288,7 +4290,7 @@ object files--just `.o' will mark more than you might think."
(defun dired-number-of-marked-files ()
"Display the number and total size of the marked files."
(interactive)
(interactive nil dired-mode)
(let* ((files (dired-get-marked-files nil nil nil t))
(nmarked
(cond ((null (cdr files))
@ -4327,7 +4329,8 @@ since it was last visited."
(list (read-regexp (concat (if current-prefix-arg "Unmark" "Mark")
" files containing (regexp): ")
nil 'dired-regexp-history)
(if current-prefix-arg ?\s)))
(if current-prefix-arg ?\s))
dired-mode)
(let ((dired-marker-char (or marker-char dired-marker-char)))
(dired-mark-if
(and (not (looking-at-p dired-re-dot))
@ -4356,7 +4359,8 @@ The match is against the non-directory part of the filename. Use `^'
and `$' to anchor matches. Exclude subdirs by hiding them.
`.' and `..' are never flagged."
(interactive (list (read-regexp "Flag for deletion (regexp): "
nil 'dired-regexp-history)))
nil 'dired-regexp-history))
dired-mode)
(dired-mark-files-regexp regexp dired-del-marker))
(defun dired-mark-symlinks (unflag-p)
@ -4364,7 +4368,7 @@ The match is against the non-directory part of the filename. Use `^'
With prefix argument, unmark or unflag all those files.
If the region is active in Transient Mark mode, mark files
only in the active region if `dired-mark-region' is non-nil."
(interactive "P")
(interactive "P" dired-mode)
(let ((dired-marker-char (if unflag-p ?\s dired-marker-char)))
(dired-mark-if (looking-at-p dired-re-sym) "symbolic link")))
@ -4373,7 +4377,7 @@ only in the active region if `dired-mark-region' is non-nil."
With prefix argument, unmark or unflag all those files.
If the region is active in Transient Mark mode, mark files
only in the active region if `dired-mark-region' is non-nil."
(interactive "P")
(interactive "P" dired-mode)
(let ((dired-marker-char (if unflag-p ?\s dired-marker-char)))
(dired-mark-if (and (looking-at-p dired-re-dir)
(not (looking-at-p dired-re-dot)))
@ -4384,7 +4388,7 @@ only in the active region if `dired-mark-region' is non-nil."
With prefix argument, unmark or unflag all those files.
If the region is active in Transient Mark mode, mark files
only in the active region if `dired-mark-region' is non-nil."
(interactive "P")
(interactive "P" dired-mode)
(let ((dired-marker-char (if unflag-p ?\s dired-marker-char)))
(dired-mark-if (looking-at-p dired-re-exe) "executable file")))
@ -4396,7 +4400,7 @@ only in the active region if `dired-mark-region' is non-nil."
A prefix argument says to unmark or unflag those files instead.
If the region is active in Transient Mark mode, flag files
only in the active region if `dired-mark-region' is non-nil."
(interactive "P")
(interactive "P" dired-mode)
(let ((dired-marker-char (if unflag-p ?\s dired-del-marker)))
(dired-mark-if
;; It is less than general to check for # here,
@ -4430,7 +4434,7 @@ only in the active region if `dired-mark-region' is non-nil."
(defun dired-flag-garbage-files ()
"Flag for deletion all files that match `dired-garbage-files-regexp'."
(interactive)
(interactive nil dired-mode)
(dired-flag-files-regexp dired-garbage-files-regexp))
(defun dired-flag-backup-files (&optional unflag-p)
@ -4438,7 +4442,7 @@ only in the active region if `dired-mark-region' is non-nil."
With prefix argument, unmark or unflag these files.
If the region is active in Transient Mark mode, flag files
only in the active region if `dired-mark-region' is non-nil."
(interactive "P")
(interactive "P" dired-mode)
(let ((dired-marker-char (if unflag-p ?\s dired-del-marker)))
(dired-mark-if
;; Don't call backup-file-name-p unless the last character looks like
@ -4466,7 +4470,8 @@ OLD and NEW are both characters used to mark files."
(old (progn (message "Change (old mark): ") (read-char)))
(new (progn (message "Change %c marks to (new mark): " old)
(read-char))))
(list old new)))
(list old new))
dired-mode)
(dolist (c (list new old))
(if (or (not (char-displayable-p c))
(eq c ?\r))
@ -4485,7 +4490,7 @@ OLD and NEW are both characters used to mark files."
(defun dired-unmark-all-marks ()
"Remove all marks from all files in the Dired buffer."
(interactive)
(interactive nil dired-mode)
(dired-unmark-all-files ?\r))
;; Bound in dired-unmark-all-files
@ -4497,7 +4502,7 @@ After this command, type the mark character to remove,
or type RET to remove all marks.
With prefix arg, query for each marked file.
Type \\[help-command] at that time for help."
(interactive "cRemove marks (RET means all): \nP")
(interactive "cRemove marks (RET means all): \nP" dired-mode)
(save-excursion
(let* ((count 0)
(inhibit-read-only t) case-fold-search
@ -4674,7 +4679,7 @@ Possible values:
(defun dired-sort-toggle-or-edit (&optional arg)
"Toggle sorting by date, and refresh the Dired buffer.
With a prefix argument, edit the current listing switches instead."
(interactive "P")
(interactive "P" dired-mode)
(when dired-sort-inhibit
(error "Cannot sort this Dired buffer"))
(if arg
@ -5044,7 +5049,7 @@ Interactively with prefix argument, read FILE-NAME."
(defun dired-mark-for-click (event)
"Mark or unmark the file underneath the mouse click at EVENT.
See `dired-click-to-select-mode' for more details."
(interactive "e")
(interactive "e" dired-mode)
(let ((posn (event-start event))
(inhibit-read-only t))
(with-selected-window (posn-window posn)
@ -5067,7 +5072,7 @@ See `dired-click-to-select-mode' for more details."
"Enable `dired-click-to-select-mode' and mark the file under EVENT.
If there is no file under EVENT, call `touch-screen-hold' with
EVENT instead."
(interactive "e")
(interactive "e" dired-mode)
(let* ((posn (event-start event))
(window (posn-window posn))
(point (posn-point posn)))