diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi index 599c0308cec..a70a0444d12 100644 --- a/doc/emacs/dired.texi +++ b/doc/emacs/dired.texi @@ -733,7 +733,8 @@ Auto-Revert mode, you might want to set Undo changes in the Dired buffer, such as adding or removing marks (@code{dired-undo}). @emph{This command does not revert the actual file operations, nor recover lost files!} It just undoes -changes in the buffer itself. +changes in the buffer itself. Like with @code{undo}, a numeric prefix +argument specifies a repeat count. In some cases, using this after commands that operate on files can cause trouble. For example, after renaming one or more files, diff --git a/etc/NEWS b/etc/NEWS index 8dd3bdbca2e..89710fa82ca 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -888,6 +888,14 @@ failed. You can now use 'C-u C-x .' to clear the fill prefix, similarly to how you could already use 'C-u C-x C-n' to clear the goal column. ++++ +** New prefix argument for 'C-/' in Dired and Proced modes. +The Dired and Proced major modes bind mode-specific undo commands to the +same keys to which 'undo' is globally bound, 'C-/', 'C-_' and 'C-x u'. +These commands did not previously accept a prefix argument. +Now a numeric prefix argument specifies a repeat count, just like it +already did for 'undo'. + * Changes in Specialized Modes and Packages in Emacs 31.1 diff --git a/lisp/dired.el b/lisp/dired.el index 2a8b23b69b6..450b408975e 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -2893,13 +2893,13 @@ Keybindings: (concat "\\`d'-elete, \\`u'-ndelete, \\`x'-punge, \\`f'-ind, " "\\`o'-ther window, \\`R'-ename, \\`C'-opy, \\`h'-elp")))) -(defun dired-undo () +(defun dired-undo (&optional arg) "Undo in a Dired buffer. +A numeric ARG serves as a repeat count. 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 nil dired-mode) - (let ((inhibit-read-only t)) - (undo)) + (interactive "P" dired-mode) + (undo-ignore-read-only arg) (dired-build-subdir-alist) (message "Change in Dired buffer undone. Actual changes in files cannot be undone by Emacs.")) diff --git a/lisp/proced.el b/lisp/proced.el index ca2fa694665..90b4e1445ce 100644 --- a/lisp/proced.el +++ b/lisp/proced.el @@ -2311,13 +2311,13 @@ STRING is an overall summary of the failures." (describe-mode) (message (substitute-command-keys proced-help-string)))) -(defun proced-undo () +(defun proced-undo (&optional arg) "Undo in a Proced buffer. +A numeric ARG serves as a repeat count. This doesn't recover killed processes, it just undoes changes in the Proced buffer. You can use it to recover marks." - (interactive nil proced-mode) - (let (buffer-read-only) - (undo)) + (interactive "P" proced-mode) + (undo-ignore-read-only arg) (message "Change in Proced buffer undone. Killed processes cannot be recovered by Emacs.")) diff --git a/lisp/simple.el b/lisp/simple.el index 63c2a665b64..2f9d24812a9 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -3577,6 +3577,13 @@ as an argument limits undo to changes within the current region." (if message (message "%s" message)))) +(defun undo-ignore-read-only (&optional arg) + "Perform `undo', ignoring the buffer's read-only status. +A numeric ARG serves as a repeat count." + (interactive "P") + (let ((inhibit-read-only t)) + (undo arg))) + (defun buffer-disable-undo (&optional buffer) "Make BUFFER stop keeping undo information. No argument or nil as argument means do this for the current buffer." diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 5e219bd1d68..bc05ce2c7fc 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -217,7 +217,7 @@ See also `diff-mode-read-only-map'." "RET" #'diff-goto-source "" #'diff-goto-source "o" #'diff-goto-source ; other-window - " " #'diff-undo + " " #'undo-ignore-read-only ;; The foregoing commands don't affect buffers beyond this one. ;; The following command is the only one that has a single-letter @@ -2815,12 +2815,6 @@ Call FUN with two args (BEG and END) for each hunk." (defun diff--overlay-auto-delete (ol _after _beg _end &optional _len) (delete-overlay ol)) -(defun diff-undo (&optional arg) - "Perform `undo', ignoring the buffer's read-only status." - (interactive "P") - (let ((inhibit-read-only t)) - (undo arg))) - ;;;###autoload (defcustom diff-add-log-use-relative-names nil "Use relative file names when generating ChangeLog skeletons.