summaryrefslogtreecommitdiff
path: root/lisp/dired.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/dired.el')
-rw-r--r--lisp/dired.el872
1 files changed, 417 insertions, 455 deletions
diff --git a/lisp/dired.el b/lisp/dired.el
index 553fb64da05..0add0ab3887 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -41,6 +41,7 @@
(declare-function dired-buffer-more-recently-used-p
"dired-x" (buffer1 buffer2))
+
;;; Customizable variables
(defgroup dired nil
@@ -53,17 +54,21 @@
:prefix "dired-"
:group 'dired)
-
;;;###autoload
(defcustom dired-listing-switches (purecopy "-al")
"Switches passed to `ls' for Dired. MUST contain the `l' option.
May contain all other options that don't contradict `-l';
may contain even `F', `b', `i' and `s'. See also the variable
`dired-ls-F-marks-symlinks' concerning the `F' switch.
+
+If you have files with names with embedded newline characters, adding
+`b' to the switches will allow Dired to handle those files better.
+
Options that include embedded whitespace must be quoted
like this: \"--option=value with spaces\"; you can use
`combine-and-quote-strings' to produce the correct quoting of
each option.
+
On systems such as MS-DOS and MS-Windows, which use `ls' emulation in Lisp,
some of the `ls' switches are not supported; see the doc string of
`insert-directory' in `ls-lisp.el' for more details."
@@ -73,9 +78,9 @@ some of the `ls' switches are not supported; see the doc string of
(defcustom dired-subdir-switches nil
"If non-nil, switches passed to `ls' for inserting subdirectories.
If nil, `dired-listing-switches' is used."
- :group 'dired
- :type '(choice (const :tag "Use dired-listing-switches" nil)
- (string :tag "Switches")))
+ :group 'dired
+ :type '(choice (const :tag "Use dired-listing-switches" nil)
+ (string :tag "Switches")))
(defcustom dired-maybe-use-globstar nil
"If non-nil, enable globstar if the shell supports it.
@@ -139,8 +144,8 @@ For more details, see Info node `(emacs)ls in Lisp'."
(defcustom dired-touch-program "touch"
"Name of touch command (usually `touch')."
- :group 'dired
- :type 'file)
+ :group 'dired
+ :type 'file)
(defcustom dired-ls-F-marks-symlinks nil
"Informs Dired about how `ls -lF' marks symbolic links.
@@ -158,7 +163,7 @@ always set this variable to t."
:type 'boolean
:group 'dired-mark)
-(defcustom dired-trivial-filenames (purecopy "\\`\\.\\.?\\'\\|\\`#")
+(defcustom dired-trivial-filenames (purecopy "\\`\\.\\.?\\'\\|\\`\\.?#")
"Regexp of files to skip when finding first file of a directory.
A value of nil means move to the subdir line.
A value of t means move to first file."
@@ -215,7 +220,7 @@ or the most recently used window with a Dired buffer, or to use any other
function. When the value is a function, it will be called with no
arguments and is expected to return a list of directories which will
be used as defaults (i.e. default target and \"future history\")
-(though, `dired-dwim-target-defaults' might modify it a bit).
+\(though, `dired-dwim-target-defaults' might modify it a bit).
The value t prefers the next windows on the same frame.
The target is used in the prompt for file copy, rename etc."
@@ -242,16 +247,14 @@ The target is used in the prompt for file copy, rename etc."
This is similar to the \"-L\" option for the \"cp\" shell command."
:type 'boolean
:group 'dired)
- ;
-; These variables were deleted and the replacements are on files.el.
-; We leave aliases behind for back-compatibility.
+
+;; These variables were deleted and the replacements are on files.el.
+;; We leave aliases behind for back-compatibility.
(define-obsolete-variable-alias 'dired-free-space-program
'directory-free-space-program "27.1")
(define-obsolete-variable-alias 'dired-free-space-args
'directory-free-space-args "27.1")
-;;; Hook variables
-
(defcustom dired-load-hook nil
"Run after loading Dired.
You can customize key bindings or load extensions with this."
@@ -353,7 +356,13 @@ is anywhere on its Dired line, except the beginning of the line."
:group 'dired
:version "28.1")
-;; Internal variables
+(defcustom dired-kill-when-opening-new-dired-buffer nil
+ "If non-nil, kill the current buffer when selecting a new directory."
+ :type 'boolean
+ :version "28.1")
+
+
+;;; Internal variables
(defvar dired-marker-char ?* ; the answer is 42
;; so that you can write things like
@@ -371,8 +380,8 @@ This is what the do-commands look for, and what the mark-commands store.")
"Character used to flag files for deletion.")
(defvar dired-shrink-to-fit t
-;; I see no reason ever to make this nil -- rms.
-;; (> baud-rate search-slow-speed)
+ ;; I see no reason ever to make this nil -- rms.
+ ;; (> baud-rate search-slow-speed)
"Non-nil means Dired shrinks the display buffer to fit the marked files.")
(make-obsolete-variable 'dired-shrink-to-fit
"use the Customization interface to add a new rule
@@ -420,7 +429,7 @@ The directory name must be absolute, but need not be fully expanded.")
"[bcsp][^:]"))
(defvar dired-re-exe;; match ls permission string of an executable file
(mapconcat (lambda (x)
- (concat dired-re-maybe-mark dired-re-inode-size x))
+ (concat dired-re-maybe-mark dired-re-inode-size x))
'("-[-r][-w][xs][-r][-w].[-r][-w]."
"-[-r][-w].[-r][-w][xs][-r][-w]."
"-[-r][-w].[-r][-w].[-r][-w][xst]")
@@ -453,6 +462,9 @@ The match starts at the beginning of the line and ends after the end
of the line.
Subexpression 2 must end right before the \\n.")
+
+;;; Faces
+
(defgroup dired-faces nil
"Faces used by Dired."
:group 'dired
@@ -556,6 +568,9 @@ Subexpression 2 must end right before the \\n.")
(defvar dired-ignored-face 'dired-ignored
"Face name used for files suffixed with `completion-ignored-extensions'.")
+
+;;; Font-lock
+
(defvar dired-font-lock-keywords
(list
;;
@@ -605,6 +620,31 @@ Subexpression 2 must end right before the \\n.")
(list dired-re-dir
'(".+" (dired-move-to-filename) nil (0 dired-directory-face)))
;;
+ ;; Files suffixed with `completion-ignored-extensions'.
+ '(eval .
+ ;; It is quicker to first find just an extension, then go back to the
+ ;; start of that file name. So we do this complex MATCH-ANCHORED form.
+ (list (concat
+ "\\(" (regexp-opt completion-ignored-extensions)
+ "\\|#\\|\\.#.+\\)$")
+ '(".+" (dired-move-to-filename) nil (0 dired-ignored-face))))
+ ;;
+ ;; Files suffixed with `completion-ignored-extensions'
+ ;; plus a character put in by -F.
+ '(eval .
+ (list (concat "\\(" (regexp-opt completion-ignored-extensions)
+ "\\|#\\|\\.#.+\\)[*=|]$")
+ '(".+" (progn
+ (end-of-line)
+ ;; If the last character is not part of the filename,
+ ;; move back to the start of the filename
+ ;; so it can be fontified.
+ ;; Otherwise, leave point at the end of the line;
+ ;; that way, nothing is fontified.
+ (unless (get-text-property (1- (point)) 'mouse-face)
+ (dired-move-to-filename)))
+ nil (0 dired-ignored-face))))
+ ;;
;; Broken Symbolic link.
(list dired-re-sym
(list (lambda (end)
@@ -649,29 +689,6 @@ Subexpression 2 must end right before the \\n.")
(list dired-re-special
'(".+" (dired-move-to-filename) nil (0 'dired-special)))
;;
- ;; Files suffixed with `completion-ignored-extensions'.
- '(eval .
- ;; It is quicker to first find just an extension, then go back to the
- ;; start of that file name. So we do this complex MATCH-ANCHORED form.
- (list (concat "\\(" (regexp-opt completion-ignored-extensions) "\\|#\\)$")
- '(".+" (dired-move-to-filename) nil (0 dired-ignored-face))))
- ;;
- ;; Files suffixed with `completion-ignored-extensions'
- ;; plus a character put in by -F.
- '(eval .
- (list (concat "\\(" (regexp-opt completion-ignored-extensions)
- "\\|#\\)[*=|]$")
- '(".+" (progn
- (end-of-line)
- ;; If the last character is not part of the filename,
- ;; move back to the start of the filename
- ;; so it can be fontified.
- ;; Otherwise, leave point at the end of the line;
- ;; that way, nothing is fontified.
- (unless (get-text-property (1- (point)) 'mouse-face)
- (dired-move-to-filename)))
- nil (0 dired-ignored-face))))
- ;;
;; Explicitly put the default face on file names ending in a colon to
;; avoid fontifying them as directory header.
(list (concat dired-re-maybe-mark dired-re-inode-size dired-re-perms ".*:$")
@@ -679,12 +696,15 @@ Subexpression 2 must end right before the \\n.")
;;
;; Directory headers.
(list dired-subdir-regexp '(1 dired-header-face))
-)
+ )
"Additional expressions to highlight in Dired mode.")
(defvar dnd-protocol-alist)
+
-;;; Macros must be defined before they are used, for the byte compiler.
+;;; Macros
+
+;; Macros must be defined before they are used, for the byte compiler.
(defmacro dired-mark-if (predicate msg)
"Mark files for PREDICATE, according to `dired-marker-char'.
@@ -879,7 +899,7 @@ ERROR can be a string with the error message."
(point-max)))
-;; The dired command
+;;; The dired command
(defun dired-read-dir-and-switches (str)
;; For use in interactive.
@@ -1259,7 +1279,7 @@ The return value is the target column for the file names."
found)))
-;; Read in a new dired buffer
+;;; Read in a new dired buffer
(defun dired-readin ()
"Read in a new Dired buffer.
@@ -1567,8 +1587,8 @@ see `dired-use-ls-dired' for more details.")
;; because newlines in dirnames are uncommon, and people may
;; have gotten used to seeing unescaped "\" in the headers.
;; Note: adjust dired-build-subdir-alist if you change this.
- (setq dir (replace-regexp-in-string "\\\\" "\\\\" dir nil t)
- dir (replace-regexp-in-string "\n" "\\n" dir nil t)))
+ (setq dir (string-replace "\\" "\\\\" dir)
+ dir (string-replace "\n" "\\n" dir)))
;; If we used --dired and it worked, the lines are already indented.
;; Otherwise, indent them.
(unless (save-excursion
@@ -1623,8 +1643,9 @@ see `dired-use-ls-dired' for more details.")
(put-text-property (+ (point) 4) (line-end-position)
'invisible 'dired-hide-details-link))))
(forward-line 1))))
+
-;; Reverting a dired buffer
+;;; Reverting a dired buffer
(defun dired-revert (&optional _arg _noconfirm)
"Reread the Dired buffer.
@@ -1811,8 +1832,9 @@ Do so according to the former subdir alist OLD-SUBDIR-ALIST."
(let ((handler (find-file-name-handler dir 'dired-uncache)))
(if handler
(funcall handler 'dired-uncache dir))))
+
-;; dired mode key bindings and initialization
+;;; Dired mode key bindings and menus
(defvar dired-mode-map
;; This looks ugly when substitute-command-keys uses C-d instead d:
@@ -1961,329 +1983,235 @@ Do so according to the former subdir alist OLD-SUBDIR-ALIST."
(define-key map ":s" 'epa-dired-do-sign)
(define-key map ":e" 'epa-dired-do-encrypt)
- ;; Make menu bar items.
-
;; No need to do this, now that top-level items are fewer.
;;;;
;; Get rid of the Edit menu bar item to save space.
- ;(define-key map [menu-bar edit] 'undefined)
-
- (define-key map [menu-bar subdir]
- (cons "Subdir" (make-sparse-keymap "Subdir")))
-
- (define-key map [menu-bar subdir hide-all]
- '(menu-item "Hide All" dired-hide-all
- :help "Hide all subdirectories, leave only header lines"))
- (define-key map [menu-bar subdir hide-subdir]
- '(menu-item "Hide/UnHide Subdir" dired-hide-subdir
- :help "Hide or unhide current directory listing"))
- (define-key map [menu-bar subdir tree-down]
- '(menu-item "Tree Down" dired-tree-down
- :help "Go to first subdirectory header down the tree"))
- (define-key map [menu-bar subdir tree-up]
- '(menu-item "Tree Up" dired-tree-up
- :help "Go to first subdirectory header up the tree"))
- (define-key map [menu-bar subdir up]
- '(menu-item "Up Directory" dired-up-directory
- :help "Edit the parent directory"))
- (define-key map [menu-bar subdir prev-subdir]
- '(menu-item "Prev Subdir" dired-prev-subdir
- :help "Go to previous subdirectory header line"))
- (define-key map [menu-bar subdir next-subdir]
- '(menu-item "Next Subdir" dired-next-subdir
- :help "Go to next subdirectory header line"))
- (define-key map [menu-bar subdir prev-dirline]
- '(menu-item "Prev Dirline" dired-prev-dirline
- :help "Move to next directory-file line"))
- (define-key map [menu-bar subdir next-dirline]
- '(menu-item "Next Dirline" dired-next-dirline
- :help "Move to previous directory-file line"))
- (define-key map [menu-bar subdir insert]
- '(menu-item "Insert This Subdir" dired-maybe-insert-subdir
- :help "Insert contents of subdirectory"
- :enable (let ((f (dired-get-filename nil t)))
- (and f (file-directory-p f)))))
- (define-key map [menu-bar immediate]
- (cons "Immediate" (make-sparse-keymap "Immediate")))
-
- (define-key map
- [menu-bar immediate image-dired-dired-display-external]
- '(menu-item "Display Image Externally" image-dired-dired-display-external
- :help "Display image in external viewer"))
- (define-key map
- [menu-bar immediate image-dired-dired-display-image]
- '(menu-item "Display Image" image-dired-dired-display-image
- :help "Display sized image in a separate window"))
- (define-key map
- [menu-bar immediate image-dired-dired-toggle-marked-thumbs]
- '(menu-item "Toggle Image Thumbnails in This Buffer" image-dired-dired-toggle-marked-thumbs
- :help "Add or remove image thumbnails in front of marked file names"))
-
- (define-key map [menu-bar immediate hide-details]
- '(menu-item "Hide Details" dired-hide-details-mode
- :help "Hide details in buffer"
- :button (:toggle . dired-hide-details-mode)))
- (define-key map [menu-bar immediate revert-buffer]
- '(menu-item "Refresh" revert-buffer
- :help "Update contents of shown directories"))
- (define-key map [menu-bar immediate dired-number-of-marked-files]
- '(menu-item "#Marked Files" dired-number-of-marked-files
- :help "Display the number and size of the marked files"))
-
- (define-key map [menu-bar immediate dashes]
- '("--"))
-
- (define-key map [menu-bar immediate isearch-filenames-regexp]
- '(menu-item "Isearch Regexp in File Names..." dired-isearch-filenames-regexp
- :help "Incrementally search for regexp in file names only"))
- (define-key map [menu-bar immediate isearch-filenames]
- '(menu-item "Isearch in File Names..." dired-isearch-filenames
- :help "Incrementally search for string in file names only."))
- (define-key map [menu-bar immediate compare-directories]
- '(menu-item "Compare Directories..." dired-compare-directories
- :help "Mark files with different attributes in two Dired buffers"))
- (define-key map [menu-bar immediate backup-diff]
- '(menu-item "Compare with Backup" dired-backup-diff
- :help "Diff file at cursor with its latest backup"))
- (define-key map [menu-bar immediate diff]
- '(menu-item "Diff..." dired-diff
- :help "Compare file at cursor with another file"))
- (define-key map [menu-bar immediate view]
- '(menu-item "View This File" dired-view-file
- :help "Examine file at cursor in read-only mode"))
- (define-key map [menu-bar immediate display]
- '(menu-item "Display in Other Window" dired-display-file
- :help "Display file at cursor in other window"))
- (define-key map [menu-bar immediate find-file-other-window]
- '(menu-item "Find in Other Window" dired-find-file-other-window
- :help "Edit file at cursor in other window"))
- (define-key map [menu-bar immediate find-file]
- '(menu-item "Find This File" dired-find-file
- :help "Edit file at cursor"))
- (define-key map [menu-bar immediate create-directory]
- '(menu-item "Create Directory..." dired-create-directory
- :help "Create a directory"))
- (define-key map [menu-bar immediate create-empty-file]
- '(menu-item "Create Empty file..." dired-create-empty-file
- :help "Create an empty file"))
- (define-key map [menu-bar immediate wdired-mode]
- '(menu-item "Edit File Names" wdired-change-to-wdired-mode
- :help "Put a Dired buffer in a mode in which filenames are editable"
- :keys "C-x C-q"
- :filter (lambda (x) (if (eq major-mode 'dired-mode) x))))
-
- (define-key map [menu-bar regexp]
- (cons "Regexp" (make-sparse-keymap "Regexp")))
-
- (define-key map
- [menu-bar regexp image-dired-mark-tagged-files]
- '(menu-item "Mark From Image Tag..." image-dired-mark-tagged-files
- :help "Mark files whose image tags matches regexp"))
-
- (define-key map [menu-bar regexp dashes-1]
- '("--"))
-
- (define-key map [menu-bar regexp downcase]
- '(menu-item "Downcase" dired-downcase
- ;; When running on plain MS-DOS, there's only one
- ;; letter-case for file names.
- :enable (or (not (fboundp 'msdos-long-file-names))
- (msdos-long-file-names))
- :help "Rename marked files to lower-case name"))
- (define-key map [menu-bar regexp upcase]
- '(menu-item "Upcase" dired-upcase
- :enable (or (not (fboundp 'msdos-long-file-names))
- (msdos-long-file-names))
- :help "Rename marked files to upper-case name"))
- (define-key map [menu-bar regexp hardlink]
- '(menu-item "Hardlink..." dired-do-hardlink-regexp
- :help "Make hard links for files matching regexp"))
- (define-key map [menu-bar regexp symlink]
- '(menu-item "Symlink..." dired-do-symlink-regexp
- :visible (fboundp 'make-symbolic-link)
- :help "Make symbolic links for files matching regexp"))
- (define-key map [menu-bar regexp rename]
- '(menu-item "Rename..." dired-do-rename-regexp
- :help "Rename marked files matching regexp"))
- (define-key map [menu-bar regexp copy]
- '(menu-item "Copy..." dired-do-copy-regexp
- :help "Copy marked files matching regexp"))
- (define-key map [menu-bar regexp flag]
- '(menu-item "Flag..." dired-flag-files-regexp
- :help "Flag files matching regexp for deletion"))
- (define-key map [menu-bar regexp mark]
- '(menu-item "Mark..." dired-mark-files-regexp
- :help "Mark files matching regexp for future operations"))
- (define-key map [menu-bar regexp mark-cont]
- '(menu-item "Mark Containing..." dired-mark-files-containing-regexp
- :help "Mark files whose contents matches regexp"))
-
- (define-key map [menu-bar mark]
- (cons "Mark" (make-sparse-keymap "Mark")))
-
- (define-key map [menu-bar mark prev]
- '(menu-item "Previous Marked" dired-prev-marked-file
- :help "Move to previous marked file"))
- (define-key map [menu-bar mark next]
- '(menu-item "Next Marked" dired-next-marked-file
- :help "Move to next marked file"))
- (define-key map [menu-bar mark marks]
- '(menu-item "Change Marks..." dired-change-marks
- :help "Replace marker with another character"))
- (define-key map [menu-bar mark unmark-all]
- '(menu-item "Unmark All" dired-unmark-all-marks))
- (define-key map [menu-bar mark symlinks]
- '(menu-item "Mark Symlinks" dired-mark-symlinks
- :visible (fboundp 'make-symbolic-link)
- :help "Mark all symbolic links"))
- (define-key map [menu-bar mark directories]
- '(menu-item "Mark Directories" dired-mark-directories
- :help "Mark all directories except `.' and `..'"))
- (define-key map [menu-bar mark directory]
- '(menu-item "Mark Old Backups" dired-clean-directory
- :help "Flag old numbered backups for deletion"))
- (define-key map [menu-bar mark executables]
- '(menu-item "Mark Executables" dired-mark-executables
- :help "Mark all executable files"))
- (define-key map [menu-bar mark garbage-files]
- '(menu-item "Flag Garbage Files" dired-flag-garbage-files
- :help "Flag unneeded files for deletion"))
- (define-key map [menu-bar mark backup-files]
- '(menu-item "Flag Backup Files" dired-flag-backup-files
- :help "Flag all backup files for deletion"))
- (define-key map [menu-bar mark auto-save-files]
- '(menu-item "Flag Auto-save Files" dired-flag-auto-save-files
- :help "Flag auto-save files for deletion"))
- (define-key map [menu-bar mark deletion]
- '(menu-item "Flag" dired-flag-file-deletion
- :help "Flag current line's file for deletion"))
- (define-key map [menu-bar mark unmark]
- '(menu-item "Unmark" dired-unmark
- :help "Unmark or unflag current line's file"))
- (define-key map [menu-bar mark mark]
- '(menu-item "Mark" dired-mark
- :help "Mark current line's file for future operations"))
- (define-key map [menu-bar mark toggle-marks]
- '(menu-item "Toggle Marks" dired-toggle-marks
- :help "Mark unmarked files, unmark marked ones"))
-
- (define-key map [menu-bar operate]
- (cons "Operate" (make-sparse-keymap "Operate")))
-
- (define-key map
- [menu-bar operate image-dired-delete-tag]
- '(menu-item "Delete Image Tag..." image-dired-delete-tag
- :help "Delete image tag from current or marked files"))
- (define-key map
- [menu-bar operate image-dired-tag-files]
- '(menu-item "Add Image Tags..." image-dired-tag-files
- :help "Add image tags to current or marked files"))
- (define-key map
- [menu-bar operate image-dired-dired-comment-files]
- '(menu-item "Add Image Comment..." image-dired-dired-comment-files
- :help "Add image comment to current or marked files"))
- (define-key map
- [menu-bar operate image-dired-display-thumbs]
- '(menu-item "Display Image Thumbnails" image-dired-display-thumbs
- :help "Display image thumbnails for current or marked image files"))
-
- (define-key map [menu-bar operate dashes-4]
- '("--"))
-
- (define-key map
- [menu-bar operate epa-dired-do-decrypt]
- '(menu-item "Decrypt..." epa-dired-do-decrypt
- :help "Decrypt current or marked files"))
-
- (define-key map
- [menu-bar operate epa-dired-do-verify]
- '(menu-item "Verify" epa-dired-do-verify
- :help "Verify digital signature of current or marked files"))
-
- (define-key map
- [menu-bar operate epa-dired-do-sign]
- '(menu-item "Sign..." epa-dired-do-sign
- :help "Create digital signature of current or marked files"))
-
- (define-key map
- [menu-bar operate epa-dired-do-encrypt]
- '(menu-item "Encrypt..." epa-dired-do-encrypt
- :help "Encrypt current or marked files"))
-
- (define-key map [menu-bar operate dashes-3]
- '("--"))
-
- (define-key map [menu-bar operate query-replace]
- '(menu-item "Query Replace in Files..." dired-do-find-regexp-and-replace
- :help "Replace regexp matches in marked files"))
- (define-key map [menu-bar operate search]
- '(menu-item "Search Files..." dired-do-find-regexp
- :help "Search marked files for matches of regexp"))
- (define-key map [menu-bar operate isearch-regexp]
- '(menu-item "Isearch Regexp Files..." dired-do-isearch-regexp
- :help "Incrementally search marked files for regexp"))
- (define-key map [menu-bar operate isearch]
- '(menu-item "Isearch Files..." dired-do-isearch
- :help "Incrementally search marked files for string"))
- (define-key map [menu-bar operate chown]
- '(menu-item "Change Owner..." dired-do-chown
- :visible (not (memq system-type '(ms-dos windows-nt)))
- :help "Change the owner of marked files"))
- (define-key map [menu-bar operate chgrp]
- '(menu-item "Change Group..." dired-do-chgrp
- :visible (not (memq system-type '(ms-dos windows-nt)))
- :help "Change the group of marked files"))
- (define-key map [menu-bar operate chmod]
- '(menu-item "Change Mode..." dired-do-chmod
- :help "Change mode (attributes) of marked files"))
- (define-key map [menu-bar operate touch]
- '(menu-item "Change Timestamp..." dired-do-touch
- :help "Change timestamp of marked files"))
- (define-key map [menu-bar operate load]
- '(menu-item "Load" dired-do-load
- :help "Load marked Emacs Lisp files"))
- (define-key map [menu-bar operate compile]
- '(menu-item "Byte-compile" dired-do-byte-compile
- :help "Byte-compile marked Emacs Lisp files"))
- (define-key map [menu-bar operate compress]
- '(menu-item "Compress" dired-do-compress
- :help "Compress/uncompress marked files"))
- (define-key map [menu-bar operate print]
- '(menu-item "Print..." dired-do-print
- :help "Ask for print command and print marked files"))
- (define-key map [menu-bar operate hardlink]
- '(menu-item "Hardlink to..." dired-do-hardlink
- :help "Make hard links for current or marked files"))
- (define-key map [menu-bar operate symlink]
- '(menu-item "Symlink to..." dired-do-symlink
- :visible (fboundp 'make-symbolic-link)
- :help "Make symbolic links for current or marked files"))
- (define-key map [menu-bar operate async-command]
- '(menu-item "Asynchronous Shell Command..." dired-do-async-shell-command
- :help "Run a shell command asynchronously on current or marked files"))
- (define-key map [menu-bar operate command]
- '(menu-item "Shell Command..." dired-do-shell-command
- :help "Run a shell command on current or marked files"))
- (define-key map [menu-bar operate delete]
- `(menu-item "Delete"
- ,(let ((menu (make-sparse-keymap "Delete")))
- (define-key menu [delete-flagged]
- '(menu-item "Delete Flagged Files" dired-do-flagged-delete
- :help "Delete all files flagged for deletion (D)"))
- (define-key menu [delete-marked]
- '(menu-item "Delete Marked (Not Flagged) Files" dired-do-delete
- :help "Delete current file or all marked files (excluding flagged files)"))
- menu)))
- (define-key map [menu-bar operate rename]
- '(menu-item "Rename to..." dired-do-rename
- :help "Rename current file or move marked files"))
- (define-key map [menu-bar operate copy]
- '(menu-item "Copy to..." dired-do-copy
- :help "Copy current file or all marked files"))
+ ;;(define-key map [menu-bar edit] 'undefined)
map)
"Local keymap for Dired mode buffers.")
+
+(easy-menu-define dired-mode-subdir-menu dired-mode-map
+ "Subdir menu for Dired mode."
+ '("Subdir"
+ ["Insert This Subdir" dired-maybe-insert-subdir
+ :help "Insert contents of subdirectory"
+ :enable (let ((f (dired-get-filename nil t)))
+ (and f (file-directory-p f)))]
+ ["Next Dirline" dired-next-dirline
+ :help "Move to previous directory-file line"]
+ ["Prev Dirline" dired-prev-dirline
+ :help "Move to next directory-file line"]
+ ["Next Subdir" dired-next-subdir
+ :help "Go to next subdirectory header line"]
+ ["Prev Subdir" dired-prev-subdir
+ :help "Go to previous subdirectory header line"]
+ ["Up Directory" dired-up-directory
+ :help "Edit the parent directory"]
+ ["Tree Up" dired-tree-up
+ :help "Go to first subdirectory header up the tree"]
+ ["Tree Down" dired-tree-down
+ :help "Go to first subdirectory header down the tree"]
+ ["Hide/UnHide Subdir" dired-hide-subdir
+ :help "Hide or unhide current directory listing"]
+ ["Hide All" dired-hide-all
+ :help "Hide all subdirectories, leave only header lines"]))
+
+(easy-menu-define dired-mode-immediate-menu dired-mode-map
+ "Immediate menu for Dired mode."
+ '("Immediate"
+ ["Edit File Names" wdired-change-to-wdired-mode
+ :help "Put a Dired buffer in a mode in which filenames are editable"
+ :keys "C-x C-q"
+ :filter (lambda (x) (if (eq major-mode 'dired-mode) x))]
+ ["Create Empty file..." dired-create-empty-file
+ :help "Create an empty file"]
+ ["Create Directory..." dired-create-directory
+ :help "Create a directory"]
+ ["Find This File" dired-find-file
+ :help "Edit file at cursor"]
+ ["Find in Other Window" dired-find-file-other-window
+ :help "Edit file at cursor in other window"]
+ ["Display in Other Window" dired-display-file
+ :help "Display file at cursor in other window"]
+ ["View This File" dired-view-file
+ :help "Examine file at cursor in read-only mode"]
+ ["Diff..." dired-diff
+ :help "Compare file at cursor with another file"]
+ ["Compare with Backup" dired-backup-diff
+ :help "Diff file at cursor with its latest backup"]
+ ["Compare Directories..." dired-compare-directories
+ :help "Mark files with different attributes in two Dired buffers"]
+ ["Isearch in File Names..." dired-isearch-filenames
+ :help "Incrementally search for string in file names only."]
+ ["Isearch Regexp in File Names..." dired-isearch-filenames-regexp
+ :help "Incrementally search for regexp in file names only"]
+ "---"
+ ["#Marked Files" dired-number-of-marked-files
+ :help "Display the number and size of the marked files"]
+ ["Refresh" revert-buffer
+ :help "Update contents of shown directories"]
+ ["Hide Details" dired-hide-details-mode
+ :help "Hide details in buffer"
+ :style toggle
+ :selected dired-hide-details-mode]
+ ["Toggle Image Thumbnails in This Buffer" image-dired-dired-toggle-marked-thumbs
+ :help "Add or remove image thumbnails in front of marked file names"]
+ ["Display Image" image-dired-dired-display-image
+ :help "Display sized image in a separate window"]
+ ["Display Image Externally" image-dired-dired-display-external
+ :help "Display image in external viewer"]))
+
+(easy-menu-define dired-mode-regexp-menu dired-mode-map
+ "Regexp menu for Dired mode."
+ '("Regexp"
+ ["Mark Containing..." dired-mark-files-containing-regexp
+ :help "Mark files whose contents matches regexp"]
+ ["Mark..." dired-mark-files-regexp
+ :help "Mark files matching regexp for future operations"]
+ ["Flag..." dired-flag-files-regexp
+ :help "Flag files matching regexp for deletion"]
+ ["Copy..." dired-do-copy-regexp
+ :help "Copy marked files matching regexp"]
+ ["Rename..." dired-do-rename-regexp
+ :help "Rename marked files matching regexp"]
+ ["Symlink..." dired-do-symlink-regexp
+ :visible (fboundp 'make-symbolic-link)
+ :help "Make symbolic links for files matching regexp"]
+ ["Hardlink..." dired-do-hardlink-regexp
+ :help "Make hard links for files matching regexp"]
+ ["Upcase" dired-upcase
+ :enable (or (not (fboundp 'msdos-long-file-names))
+ (msdos-long-file-names))
+ :help "Rename marked files to upper-case name"]
+ ["Downcase" dired-downcase
+ ;; When running on plain MS-DOS, there's only one
+ ;; letter-case for file names.
+ :enable (or (not (fboundp 'msdos-long-file-names))
+ (msdos-long-file-names))
+ :help "Rename marked files to lower-case name"]
+ "---"
+ ["Mark From Image Tag..." image-dired-mark-tagged-files
+ :help "Mark files whose image tags matches regexp"]))
+
+(easy-menu-define dired-mode-mark-menu dired-mode-map
+ "Mark menu for Dired mode."
+ '("Mark"
+ ["Toggle Marks" dired-toggle-marks
+ :help "Mark unmarked files, unmark marked ones"]
+ ["Mark" dired-mark
+ :help "Mark current line's file for future operations"]
+ ["Unmark" dired-unmark
+ :help "Unmark or unflag current line's file"]
+ ["Flag" dired-flag-file-deletion
+ :help "Flag current line's file for deletion"]
+ ["Flag Auto-save Files" dired-flag-auto-save-files
+ :help "Flag auto-save files for deletion"]
+ ["Flag Backup Files" dired-flag-backup-files
+ :help "Flag all backup files for deletion"]
+ ["Flag Garbage Files" dired-flag-garbage-files
+ :help "Flag unneeded files for deletion"]
+ ["Mark Executables" dired-mark-executables
+ :help "Mark all executable files"]
+ ["Mark Old Backups" dired-clean-directory
+ :help "Flag old numbered backups for deletion"]
+ ["Mark Directories" dired-mark-directories
+ :help "Mark all directories except `.' and `..'"]
+ ["Mark Symlinks" dired-mark-symlinks
+ :visible (fboundp 'make-symbolic-link)
+ :help "Mark all symbolic links"]
+ ["Unmark All" dired-unmark-all-marks]
+ ["Change Marks..." dired-change-marks
+ :help "Replace marker with another character"]
+ ["Next Marked" dired-next-marked-file
+ :help "Move to next marked file"]
+ ["Previous Marked" dired-prev-marked-file
+ :help "Move to previous marked file"]))
+
+(easy-menu-define dired-mode-operate-menu dired-mode-map
+ "Operate menu for Dired mode."
+ '("Operate"
+ ["Copy to..." dired-do-copy
+ :help "Copy current file or all marked files"]
+ ["Rename to..." dired-do-rename
+ :help "Rename current file or move marked files"]
+ ("Delete"
+ ["Delete Flagged Files" dired-do-flagged-delete
+ :help "Delete all files flagged for deletion (D)"]
+ ["Delete Marked (Not Flagged) Files" dired-do-delete
+ :help "Delete current file or all marked files (excluding flagged files)"])
+ ["Shell Command..." dired-do-shell-command
+ :help "Run a shell command on current or marked files"]
+ ["Asynchronous Shell Command..." dired-do-async-shell-command
+ :help "Run a shell command asynchronously on current or marked files"]
+ ["Symlink to..." dired-do-symlink
+ :visible (fboundp 'make-symbolic-link)
+ :help "Make symbolic links for current or marked files"]
+ ["Hardlink to..." dired-do-hardlink
+ :help "Make hard links for current or marked files"]
+ ["Print..." dired-do-print
+ :help "Ask for print command and print marked files"]
+ ["Compress" dired-do-compress
+ :help "Compress/uncompress marked files"]
+ ["Byte-compile" dired-do-byte-compile
+ :help "Byte-compile marked Emacs Lisp files"]
+ ["Load" dired-do-load
+ :help "Load marked Emacs Lisp files"]
+ ["Change Timestamp..." dired-do-touch
+ :help "Change timestamp of marked files"]
+ ["Change Mode..." dired-do-chmod
+ :help "Change mode (attributes) of marked files"]
+ ["Change Group..." dired-do-chgrp
+ :visible (not (memq system-type '(ms-dos windows-nt)))
+ :help "Change the group of marked files"]
+ ["Change Owner..." dired-do-chown
+ :visible (not (memq system-type '(ms-dos windows-nt)))
+ :help "Change the owner of marked files"]
+ ["Isearch Files..." dired-do-isearch
+ :help "Incrementally search marked files for string"]
+ ["Isearch Regexp Files..." dired-do-isearch-regexp
+ :help "Incrementally search marked files for regexp"]
+ ["Search Files..." dired-do-find-regexp
+ :help "Search marked files for matches of regexp"]
+ ["Query Replace in Files..." dired-do-find-regexp-and-replace
+ :help "Replace regexp matches in marked files"]
+ "---"
+ ["Encrypt..." epa-dired-do-encrypt
+ :help "Encrypt current or marked files"]
+ ["Sign..." epa-dired-do-sign
+ :help "Create digital signature of current or marked files"]
+ ["Verify" epa-dired-do-verify
+ :help "Verify digital signature of current or marked files"]
+ ["Decrypt..." epa-dired-do-decrypt
+ :help "Decrypt current or marked files"]
+ "---"
+ ["Display Image Thumbnails" image-dired-display-thumbs
+ :help "Display image thumbnails for current or marked image files"]
+ ["Add Image Comment..." image-dired-dired-comment-files
+ :help "Add image comment to current or marked files"]
+ ["Add Image Tags..." image-dired-tag-files
+ :help "Add image tags to current or marked files"]
+ ["Delete Image Tag..." image-dired-delete-tag
+ :help "Delete image tag from current or marked files"]))
+
+(defun dired-context-menu (menu)
+ (when (mouse-posn-property (event-start last-input-event) 'dired-filename)
+ (define-key menu [dired-separator] menu-bar-separator)
+ (let ((easy-menu (make-sparse-keymap "Immediate")))
+ (easy-menu-define nil easy-menu nil
+ '("Immediate"
+ ["Find This File" dired-mouse-find-file
+ :help "Edit file at mouse click"]
+ ["Find in Other Window" dired-mouse-find-file-other-window
+ :help "Edit file at mouse click in other window"]))
+ (dolist (item (reverse (lookup-key easy-menu [menu-bar immediate])))
+ (when (consp item)
+ (define-key menu (vector (car item)) (cdr item))))))
+ menu)
+
+;;; Dired mode
+
;; Dired mode is suitable only for specially formatted data.
(put 'dired-mode 'mode-class 'special)
@@ -2380,15 +2308,18 @@ Keybindings:
(append dired-dnd-protocol-alist dnd-protocol-alist)))
(add-hook 'file-name-at-point-functions #'dired-file-name-at-point nil t)
(add-hook 'isearch-mode-hook #'dired-isearch-filenames-setup nil t)
+ (add-hook 'context-menu-functions 'dired-context-menu 5 t)
(run-mode-hooks 'dired-mode-hook))
+
-;; Idiosyncratic dired commands that don't deal with marks.
+;;; Idiosyncratic dired commands that don't deal with marks
(defun dired-summary ()
"Summarize basic Dired commands and show recent Dired errors."
(interactive)
(dired-why)
- ;>> this should check the key-bindings and use substitute-command-keys if non-standard
+ ;; FIXME this should check the key-bindings and use
+ ;; substitute-command-keys if non-standard
(message
"d-elete, u-ndelete, x-punge, f-ind, o-ther window, R-ename, C-opy, h-elp"))
@@ -2469,7 +2400,7 @@ directory in another window."
(progn
(if other-window
(dired-other-window up)
- (dired up))
+ (dired--find-possibly-alternative-file up))
(dired-goto-file dir)))))
(defun dired-get-file-for-visit ()
@@ -2493,7 +2424,16 @@ directory in another window."
(defun dired-find-file ()
"In Dired, visit the file or directory named on this line."
(interactive)
- (dired--find-file #'find-file (dired-get-file-for-visit)))
+ (dired--find-possibly-alternative-file (dired-get-file-for-visit)))
+
+(defun dired--find-possibly-alternative-file (file)
+ "Find FILE, but respect `dired-kill-when-opening-new-dired-buffer'."
+ (if (and dired-kill-when-opening-new-dired-buffer
+ (file-directory-p file))
+ (progn
+ (set-buffer-modified-p nil)
+ (dired--find-file #'find-alternate-file file))
+ (dired--find-file #'find-file file)))
(defun dired--find-file (find-file-function file)
"Call FIND-FILE-FUNCTION on FILE, but bind some relevant variables."
@@ -2579,8 +2519,9 @@ Otherwise, display it in another buffer."
(interactive)
(display-buffer (find-file-noselect (dired-get-file-for-visit))
t))
+
-;;; Functions for extracting and manipulating file names in Dired buffers.
+;;; Functions for extracting and manipulating file names in Dired buffers
(defun dired-unhide-subdir ()
(with-silent-modifications
@@ -2687,7 +2628,7 @@ Otherwise, an error occurs in these cases."
(concat (dired-current-directory localp) file)))))
(defun dired-string-replace-match (regexp string newtext
- &optional literal global)
+ &optional literal global)
"Replace first match of REGEXP in STRING with NEWTEXT.
If it does not match, nil is returned instead of the new string.
Optional arg LITERAL means to take NEWTEXT literally.
@@ -2698,7 +2639,7 @@ Optional arg GLOBAL means to replace all matches."
(let ((from-end (- (length string) (match-end 0))))
(setq ret (setq string (replace-match newtext t literal string)))
(setq start (- (length string) from-end))))
- ret)
+ ret)
(if (not (string-match regexp string 0))
nil
(replace-match newtext t literal string))))
@@ -2725,7 +2666,10 @@ unchanged."
(if (string-match (concat "^" (regexp-quote dir)) file)
(substring file (match-end 0))
file))
+
+;;; Mode to hide details
+
(define-minor-mode dired-hide-details-mode
"Toggle visibility of detailed information in current Dired buffer.
When this minor mode is enabled, details such as file ownership and
@@ -2762,6 +2706,7 @@ See options: `dired-hide-details-hide-symlink-targets' and
'add-to-invisibility-spec
'remove-from-invisibility-spec)
'dired-hide-details-link))
+
;;; Functions to hide/unhide text
@@ -2791,7 +2736,7 @@ See options: `dired-hide-details-hide-symlink-targets' and
(progn (goto-char end) (line-end-position))
'(invisible))))
-;;; Functions for finding the file name in a dired buffer line.
+;;; Functions for finding the file name in a dired buffer line
(defvar dired-permission-flags-regexp
"\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)"
@@ -2882,15 +2827,15 @@ If EOL, it should be an position to use instead of
(or no-error
(not (eq opoint (point)))
(error "%s" (if hidden
- (substitute-command-keys
- "File line is hidden, type \\[dired-hide-subdir] to unhide")
- "No file on this line")))
+ (substitute-command-keys
+ "File line is hidden, type \\[dired-hide-subdir] to unhide")
+ "No file on this line")))
(if (eq opoint (point))
nil
(point)))))
-;;; COPY NAMES OF MARKED FILES INTO KILL-RING.
+;;; Copy names of marked files into kill-ring
(defun dired-copy-filename-as-kill (&optional arg)
"Copy names of marked (or next ARG) files into the kill ring.
@@ -2924,12 +2869,14 @@ You can then feed the file name(s) to other commands with \\[yank]."
(message "%s" string))))
-;; Keeping Dired buffers in sync with the filesystem and with each other
+;;; Keeping Dired buffers in sync with the filesystem and with each other
-(defun dired-buffers-for-dir (dir &optional file)
+(defun dired-buffers-for-dir (dir &optional file subdirs)
"Return a list of buffers for DIR (top level or in-situ subdir).
If FILE is non-nil, include only those whose wildcard pattern (if any)
matches FILE.
+If SUBDIRS is non-nil, also include the dired buffers of
+directories below DIR.
The list is in reverse order of buffer creation, most recent last.
As a side effect, killed dired buffers for DIR are removed from
dired-buffers."
@@ -2941,19 +2888,20 @@ dired-buffers."
((null (buffer-name buf))
;; Buffer is killed - clean up:
(setq dired-buffers (delq elt dired-buffers)))
- ((dired-in-this-tree-p dir (car elt))
+ ((dired-in-this-tree-p (car elt) dir)
(with-current-buffer buf
- (and (assoc dir dired-subdir-alist)
- (or (null file)
- (if (stringp dired-directory)
- (let ((wildcards (file-name-nondirectory
- dired-directory)))
- (or (zerop (length wildcards))
- (string-match-p (dired-glob-regexp wildcards)
- file)))
- (member (expand-file-name file dir)
- (cdr dired-directory))))
- (setq result (cons buf result)))))))
+ (when (and (or subdirs
+ (assoc dir dired-subdir-alist))
+ (or (null file)
+ (if (stringp dired-directory)
+ (let ((wildcards (file-name-nondirectory
+ dired-directory)))
+ (or (zerop (length wildcards))
+ (string-match-p (dired-glob-regexp wildcards)
+ file)))
+ (member (expand-file-name file dir)
+ (cdr dired-directory)))))
+ (setq result (cons buf result)))))))
result))
(defun dired-glob-regexp (pattern)
@@ -2977,7 +2925,7 @@ dired-buffers."
(if (= (aref pattern (1+ set-start)) ?^)
(+ 3 set-start)
(+ 2 set-start)))
- (set-end (string-match-p "]" pattern set-cont))
+ (set-end (string-search "]" pattern set-cont))
(set (substring pattern set-start (1+ set-end))))
(setq regexp (concat regexp set))
(setq matched-in-pattern (1+ set-end))))
@@ -2990,8 +2938,6 @@ dired-buffers."
(substring pattern matched-in-pattern))
"\\'")))
-
-
(defun dired-advertise ()
;;"Advertise in variable `dired-buffers' that we dired `default-directory'."
;; With wildcards we actually advertise too much.
@@ -3009,15 +2955,15 @@ dired-buffers."
;; Removing is also done as a side-effect in dired-buffer-for-dir.
(setq dired-buffers
(delq (assoc (expand-file-name dir) dired-buffers) dired-buffers)))
-
-;; Tree Dired
-;;; utility functions
+
+;;; Utility functions
(defun dired-in-this-tree-p (file dir)
;;"Is FILE part of the directory tree starting at DIR?"
(let (case-fold-search)
(string-match-p (concat "^" (regexp-quote dir)) file)))
+
(define-obsolete-function-alias 'dired-in-this-tree
'dired-in-this-tree-p "27.1")
@@ -3038,8 +2984,8 @@ dired-buffers."
(beginning-of-line) ; alist stores b-o-l positions
(and (zerop (- (point)
(cdr (assoc cur-dir
- dired-subdir-alist))))
- cur-dir))))
+ dired-subdir-alist))))
+ cur-dir))))
(define-obsolete-function-alias 'dired-get-subdir-min 'cdr "27.1")
@@ -3148,11 +3094,11 @@ instead of `dired-actual-switches'."
new-dir-name)
(setq new-dir-name res)))
(dired-alist-add-1 new-dir-name
- ;; Place a sub directory boundary between lines.
- (save-excursion
- (goto-char (match-beginning 0))
- (beginning-of-line)
- (point-marker)))))
+ ;; Place a sub directory boundary between lines.
+ (save-excursion
+ (goto-char (match-beginning 0))
+ (beginning-of-line)
+ (point-marker)))))
(if (and (> count 1) (called-interactively-p 'interactive))
(message "Buffer includes %d directories" count)))
;; We don't need to sort it because it is in buffer order per
@@ -3237,15 +3183,15 @@ the quoted forms of those characters.
FULL-NAME specifies the actual file name the listing must have,
as returned by `dired-get-filename'. LIMIT is the search limit."
(let (str)
- (setq str (replace-regexp-in-string "\^m" "\\^m" file nil t))
- (setq str (replace-regexp-in-string "\\\\" "\\\\" str nil t))
+ (setq str (string-replace "\^m" "\\^m" file))
+ (setq str (string-replace "\\" "\\\\" str))
(and (dired-switches-escape-p dired-actual-switches)
(string-match-p "[ \t\n]" str)
;; FIXME: to fix this for embedded control characters etc, we
;; should escape everything that `ls -b' does.
- (setq str (replace-regexp-in-string " " "\\ " str nil t)
- str (replace-regexp-in-string "\t" "\\t" str nil t)
- str (replace-regexp-in-string "\n" "\\n" str nil t)))
+ (setq str (string-replace " " "\\ " str)
+ str (string-replace "\t" "\\t" str)
+ str (string-replace "\n" "\\n" str)))
(let ((found nil)
;; filenames are preceded by SPC, this makes the search faster
;; (e.g. for the filename "-").
@@ -3271,7 +3217,7 @@ It runs the hook `dired-initial-position-hook'."
(dired-goto-subdir dirname))
(if dired-trivial-filenames (dired-goto-next-nontrivial-file))
(run-hooks 'dired-initial-position-hook))
-
+
;; These are hooks which make tree dired work.
;; They are in this file because other parts of dired need to call them.
;; But they don't call the rest of tree dired unless there are subdirs loaded.
@@ -3310,8 +3256,9 @@ is the directory where the file on this line resides."
(if (or (null (cdr dired-subdir-alist)) (not (dired-next-subdir 1 t t)))
(point-max)
(point))))
+
-;; Deleting files
+;;; Deleting files
(defcustom dired-recursive-deletes 'top
"Whether Dired deletes directories recursively.
@@ -3386,15 +3333,19 @@ non-empty directories is allowed."
(interactive)
(let* ((dired-marker-char dired-del-marker)
(regexp (dired-marker-regexp))
- case-fold-search)
+ case-fold-search markers)
(if (save-excursion (goto-char (point-min))
(re-search-forward regexp nil t))
(dired-internal-do-deletions
(nreverse
;; this can't move point since ARG is nil
- (dired-map-over-marks (cons (dired-get-filename) (point))
+ (dired-map-over-marks (cons (dired-get-filename)
+ (let ((m (point-marker)))
+ (push m markers)
+ m))
nil))
nil t)
+ (dolist (m markers) (set-marker m nil))
(or nomessage
(message "(No deletions requested)")))))
@@ -3405,12 +3356,17 @@ non-empty directories is allowed."
;; This is more consistent with the file marking feature than
;; dired-do-flagged-delete.
(interactive "P")
- (dired-internal-do-deletions
- (nreverse
- ;; this may move point if ARG is an integer
- (dired-map-over-marks (cons (dired-get-filename) (point))
- arg))
- arg t))
+ (let (markers)
+ (dired-internal-do-deletions
+ (nreverse
+ ;; this may move point if ARG is an integer
+ (dired-map-over-marks (cons (dired-get-filename)
+ (let ((m (point-marker)))
+ (push m markers)
+ m))
+ arg))
+ arg t)
+ (dolist (m markers) (set-marker m nil))))
(defvar dired-deletion-confirmer 'yes-or-no-p) ; or y-or-n-p?
@@ -3418,11 +3374,6 @@ non-empty directories is allowed."
;; L is an alist of files to delete, with their buffer positions.
;; ARG is the prefix arg.
;; Filenames are absolute.
- ;; (car L) *must* be the *last* (bottommost) file in the dired buffer.
- ;; That way as changes are made in the buffer they do not shift the
- ;; lines still to be changed, so the (point) values in L stay valid.
- ;; Also, for subdirs in natural order, a subdir's files are deleted
- ;; before the subdir itself - the other way around would not work.
(let* ((files (mapcar #'car l))
(count (length l))
(succ 0)
@@ -3443,9 +3394,10 @@ non-empty directories is allowed."
(make-progress-reporter
(if trashing "Trashing..." "Deleting...")
succ count))
- failures) ;; files better be in reverse order for this loop!
+ failures)
(while l
- (goto-char (cdr (car l)))
+ (goto-char (marker-position (cdr (car l))))
+ (dired-move-to-filename)
(let ((inhibit-read-only t))
(condition-case err
(let ((fn (car (car l))))
@@ -3475,7 +3427,7 @@ non-empty directories is allowed."
(defun dired-fun-in-all-buffers (directory file fun &rest args)
"In all buffers dired'ing DIRECTORY, run FUN with ARGS.
If the buffer has a wildcard pattern, check that it matches FILE.
-(FILE does not include a directory component.)
+\(FILE does not include a directory component.)
FILE may be nil, in which case ignore it.
Return list of buffers where FUN succeeded (i.e., returned non-nil)."
(let (success-list)
@@ -3528,20 +3480,26 @@ confirmation. To disable the confirmation, see
(file-name-nondirectory fn))))
(not dired-clean-confirm-killing-deleted-buffers))
(kill-buffer buf)))
- (let ((buf-list (dired-buffers-for-dir (expand-file-name fn))))
+ (let ((buf-list (dired-buffers-for-dir (expand-file-name fn)
+ nil 'subdirs)))
(and buf-list
(or (and dired-clean-confirm-killing-deleted-buffers
- (y-or-n-p (format
- (ngettext "Kill Dired buffer of %s, too? "
- "Kill Dired buffers of %s, too? "
- (length buf-list))
- (file-name-nondirectory fn))))
+ (y-or-n-p
+ (format
+ (ngettext "Kill Dired buffer of %s, too? "
+ "Kill Dired buffers of %s, too? "
+ (length buf-list))
+ (file-name-nondirectory
+ ;; FN may end in a / if `dired-listing-switches'
+ ;; contains -p, so we need to strip that
+ ;; (bug#48301).
+ (directory-file-name fn)))))
(not dired-clean-confirm-killing-deleted-buffers))
(dolist (buf buf-list)
(kill-buffer buf))))))
-;; Confirmation
+;;; Confirmation
(defun dired-marker-regexp ()
(concat "^" (regexp-quote (char-to-string dired-marker-char))))
@@ -3660,8 +3618,9 @@ argument or confirmation)."
(let ((beg (point)))
(completion--insert-strings files)
(put-text-property beg (point) 'mouse-face nil)))
+
-;; Commands to mark or flag file(s) at or near current line.
+;;; Commands to mark or flag file(s) at or near current line
(defun dired-repeat-over-lines (arg function)
;; This version skips non-file lines.
@@ -3849,8 +3808,9 @@ on the whole buffer."
(list ?\s dired-marker-char)
(list dired-marker-char ?\s))))
(forward-line 1)))))
+
-;;; Commands to mark or flag files based on their characteristics or names.
+;;; Commands to mark or flag files based on their characteristics or names
(defvar dired-regexp-history nil
"History list of regular expressions used in Dired commands.")
@@ -3906,13 +3866,13 @@ object files--just `.o' will mark more than you might think."
when (stringp file)
sum (file-attribute-size (file-attributes file)))))
(if (zerop nmarked)
- (message "No marked files"))
- (message "%d marked file%s (%s total size)"
- nmarked
- (if (= nmarked 1)
- ""
- "s")
- (funcall byte-count-to-string-function size))))
+ (message "No marked files")
+ (message "%d marked file%s (%s total size)"
+ nmarked
+ (if (= nmarked 1)
+ ""
+ "s")
+ (funcall byte-count-to-string-function size)))))
(defun dired-mark-files-containing-regexp (regexp &optional marker-char)
"Mark all files with contents containing REGEXP for use in later commands.
@@ -3951,8 +3911,7 @@ since it was last visited."
(with-temp-buffer
(insert-file-contents fn)
(goto-char (point-min))
- (re-search-forward regexp nil t))))
- )))
+ (re-search-forward regexp nil t)))))))
"matching file")))
(defun dired-flag-files-regexp (regexp)
@@ -4127,8 +4086,9 @@ Type SPC or `y' to unmark one file, DEL or `n' to skip to next,
(message (if (= count 1) "1 mark removed"
"%d marks removed")
count))))
+
-;; Logging failures operating on files, and showing the results.
+;;; Logging failures operating on files, and showing the results
(defvar dired-log-buffer "*Dired log*")
@@ -4193,6 +4153,7 @@ or nil if file names are not applicable."
;; Log a summary describing a bunch of errors.
(dired-log (concat "\n" string "\n"))
(dired-log t))
+
;;; Sorting
@@ -4235,7 +4196,8 @@ Possible values:
* `as-is': Show full switches.
* Integer: Show only the first N chars of full switches.
* Function: Pass `dired-actual-switches' as arg and show result."
- :group 'Dired-Plus
+ :group 'dired
+ :version "28.1"
:type '(choice
(const :tag "Indicate by name or date, else full" nil)
(const :tag "Show full switches" as-is)
@@ -4373,9 +4335,9 @@ To be called first in body of `dired-sort-other', etc."
;; No pre-R subdir alist, so revert to main directory
;; listing:
(list (car (reverse dired-subdir-alist))))))))
-
-;;;; Drag and drop support
+
+;;; Drag and drop support
(defcustom dired-recursive-copies 'top
"Whether Dired copies directories recursively.
@@ -4477,9 +4439,9 @@ Ask means pop up a menu for the user to select one of copy, move or link."
(let ((local-file (dnd-get-local-file-uri uri)))
(if local-file (dired-dnd-handle-local-file local-file action)
nil)))
-
-;;;; Desktop support
+
+;;; Desktop support
(eval-when-compile (require 'desktop))
(declare-function desktop-file-name "desktop" (filename dirname))
@@ -4496,10 +4458,10 @@ Ask means pop up a menu for the user to select one of copy, move or link."
(desktop-file-name dired-directory dirname))
;; Subdirectories in `dired-subdir-alist'.
(cdr
- (nreverse
- (mapcar
- (lambda (f) (desktop-file-name (car f) dirname))
- dired-subdir-alist)))))
+ (nreverse
+ (mapcar
+ (lambda (f) (desktop-file-name (car f) dirname))
+ dired-subdir-alist)))))
(defun dired-restore-desktop-buffer (_file-name
_buffer-name
@@ -4525,7 +4487,7 @@ Ask means pop up a menu for the user to select one of copy, move or link."
'(dired-mode . dired-restore-desktop-buffer))
-;;;; Jump to Dired
+;;; Jump to Dired
(defvar archive-superior-buffer)
(defvar tar-superior-buffer)