X-Git-Url: https://git.hcoop.net/bpt/emacs.git/blobdiff_plain/2b0c7330457b8ca42375c92ada7dc7cefb0fa9fb..5396468298b0122469e0b41da8f49860d99a2b51:/lisp/dired.el diff --git a/lisp/dired.el b/lisp/dired.el index 625ed48eff..32a7f74968 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -1,4 +1,4 @@ -;;; dired.el --- directory-browsing commands +;;; dired.el --- directory-browsing commands -*- lexical-binding: t -*- ;; Copyright (C) 1985-1986, 1992-1997, 2000-2011 ;; Free Software Foundation, Inc. @@ -78,10 +78,22 @@ If nil, `dired-listing-switches' is used." :type 'file) (defcustom dired-use-ls-dired 'unspecified - "Non-nil means Dired should use \"ls --dired\". + "Non-nil means Dired should pass the \"--dired\" option to \"ls\". The special value of `unspecified' means to check explicitly, and save the result in this variable. This is performed the first -time `dired-insert-directory' is called." +time `dired-insert-directory' is called. + +Note that if you set this option to nil, either through choice or +because your \"ls\" program does not support \"--dired\", Dired +will fail to parse some \"unusual\" file names, e.g. those with leading +spaces. You might want to install ls from GNU Coreutils, which does +support this option. Alternatively, you might want to use Emacs's +own emulation of \"ls\", by using: + \(setq ls-lisp-use-insert-directory-program nil) + \(require 'ls-lisp) +This is used by default on MS Windows, which does not have an \"ls\" program. +Note that `ls-lisp' does not support as many options as GNU ls, though. +For more details, see Info node `(emacs)ls in Lisp'." :group 'dired :type '(choice (const :tag "Check for --dired support" unspecified) (const :tag "Do not use --dired" nil) @@ -238,8 +250,6 @@ This is what the do-commands look for, and what the mark-commands store.") ;; (> baud-rate search-slow-speed) "Non-nil means Dired shrinks the display buffer to fit the marked files.") -(defvar dired-flagging-regexp nil);; Last regexp used to flag files. - (defvar dired-file-version-alist) ;;;###autoload @@ -249,9 +259,19 @@ Local to each dired buffer. May be a list, in which case the car is the directory name and the cdr is the list of files to mention. The directory name must be absolute, but need not be fully expanded.") +;; Beware of "-l;reboot" etc. See bug#3230. +(defun dired-safe-switches-p (switches) + "Return non-nil if string SWITCHES does not look risky for dired." + (or (not switches) + (and (stringp switches) + (< (length switches) 100) ; arbitrary + (string-match "\\` *-[- [:alnum:]]+\\'" switches)))) + (defvar dired-actual-switches nil "The value of `dired-listing-switches' used to make this buffer's text.") +(put 'dired-actual-switches 'safe-local-variable 'dired-safe-switches-p) + (defvar dired-re-inode-size "[0-9 \t]*" "Regexp for optional initial inode and file size as made by `ls -i -s'.") @@ -322,7 +342,7 @@ Subexpression 2 must end right before the \\n or \\r.") "Face name used for dired marks.") (defface dired-marked - '((t (:inherit font-lock-warning-face))) + '((t (:inherit warning))) "Face used for marked files." :group 'dired-faces :version "22.1") @@ -330,12 +350,12 @@ Subexpression 2 must end right before the \\n or \\r.") "Face name used for marked files.") (defface dired-flagged - '((t (:inherit font-lock-warning-face))) - "Face used for flagged files." + '((t (:inherit error))) + "Face used for files flagged for deletion." :group 'dired-faces :version "22.1") (defvar dired-flagged-face 'dired-flagged - "Face name used for flagged files.") + "Face name used for files flagged for deletion.") (defface dired-warning ;; Inherit from font-lock-warning-face since with min-colors 8 @@ -475,7 +495,16 @@ Return value is the number of files marked, or nil if none were marked." `(let ((inhibit-read-only t) count) (save-excursion (setq count 0) - (if ,msg (message "Marking %ss..." ,msg)) + (when ,msg + (message "%s %ss%s..." + (cond ((eq dired-marker-char ?\040) "Unmarking") + ((eq dired-del-marker dired-marker-char) + "Flagging") + (t "Marking")) + ,msg + (if (eq dired-del-marker dired-marker-char) + " for deletion" + ""))) (goto-char (point-min)) (while (not (eobp)) (if ,predicate @@ -496,24 +525,31 @@ Return value is the number of files marked, or nil if none were marked." (defmacro dired-map-over-marks (body arg &optional show-progress distinguish-one-marked) "Eval BODY with point on each marked line. Return a list of BODY's results. -If no marked file could be found, execute BODY on the current line. -ARG, if non-nil, specifies the files to use instead of the marked files. - If ARG is an integer, use the next ARG (or previous -ARG, if - ARG<0) files. In that case, point is dragged along. This is - so that commands on the next ARG (instead of the marked) files - can be chained easily. - For any other non-nil value of ARG, use the current file. +If no marked file could be found, execute BODY on the current +line. ARG, if non-nil, specifies the files to use instead of the +marked files. + +If ARG is an integer, use the next ARG (or previous -ARG, if +ARG<0) files. In that case, point is dragged along. This is so +that commands on the next ARG (instead of the marked) files can +be chained easily. +For any other non-nil value of ARG, use the current file. + If optional third arg SHOW-PROGRESS evaluates to non-nil, - redisplay the dired buffer after each file is processed. -No guarantee is made about the position on the marked line. - BODY must ensure this itself if it depends on this. -Search starts at the beginning of the buffer, thus the car of the list - corresponds to the line nearest to the buffer's bottom. This - is also true for (positive and negative) integer values of ARG. +redisplay the dired buffer after each file is processed. + +No guarantee is made about the position on the marked line. BODY +must ensure this itself if it depends on this. + +Search starts at the beginning of the buffer, thus the car of the +list corresponds to the line nearest to the buffer's bottom. +This is also true for (positive and negative) integer values of +ARG. + BODY should not be too long as it is expanded four times. -If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one marked file, -return (t FILENAME) instead of (FILENAME)." +If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one +marked file, return (t FILENAME) instead of (FILENAME)." ;; ;;Warning: BODY must not add new lines before point - this may cause an ;;endless loop. @@ -601,9 +637,12 @@ Don't use that together with FILTER." (if current-prefix-arg (read-string "Dired listing switches: " dired-listing-switches)) - ;; If a dialog is about to be used, call read-directory-name so - ;; the dialog code knows we want directories. Some dialogs can - ;; only select directories or files when popped up, not both. + ;; If a dialog is used, call `read-directory-name' so the + ;; dialog code knows we want directories. Some dialogs + ;; can only select directories or files when popped up, + ;; not both. If no dialog is used, call `read-file-name' + ;; because the user may want completion of file names for + ;; use in a wildcard pattern. (if (next-read-file-uses-dialog-p) (read-directory-name (format "Dired %s(directory): " str) nil default-directory nil) @@ -665,7 +704,7 @@ Don't use that together with FILTER." (defun dired-file-name-at-point () "Try to get a file name at point in the current dired buffer. -This hook is inteneded to be put in `file-name-at-point-functions'." +This hook is intended to be put in `file-name-at-point-functions'." (let ((filename (dired-get-filename nil t))) (when filename (if (file-directory-p filename) @@ -683,7 +722,6 @@ shell wildcards appended to select certain files). If DIRNAME is a cons, its first element is taken as the directory name and the rest as an explicit list of files to make directory entries for. \\\ -You can move around in it with the usual commands. You can flag files for deletion with \\[dired-flag-file-deletion] and then delete them by typing \\[dired-do-flagged-delete]. Type \\[describe-mode] after entering Dired for more info. @@ -987,7 +1025,7 @@ BEG..END is the line where the file info is located." ;; spaces there (and within the filename as well, of course). (save-excursion (let (file file-col other other-col) - ;; Check that there is indeed a file, and that there is anoter adjacent + ;; Check that there is indeed a file, and that there is another adjacent ;; file with which to align, and that additional spaces are needed to ;; align the filenames. (when (and (setq file (progn (goto-char beg) @@ -1093,9 +1131,13 @@ If HDR is non-nil, insert a header line with the directory name." (or (if (eq dired-use-ls-dired 'unspecified) ;; Check whether "ls --dired" gives exit code 0, and ;; save the answer in `dired-use-ls-dired'. - (setq dired-use-ls-dired - (eq (call-process insert-directory-program nil nil nil "--dired") - 0)) + (or (setq dired-use-ls-dired + (eq 0 (call-process insert-directory-program + nil nil nil "--dired"))) + (progn + (message "ls does not support --dired; \ +see `dired-use-ls-dired' for more details.") + nil)) dired-use-ls-dired) (file-remote-p dir))) (setq switches (concat "--dired " switches))) @@ -1149,7 +1191,7 @@ If HDR is non-nil, insert a header line with the directory name." (insert " wildcard " (file-name-nondirectory dir) "\n"))))) (defun dired-insert-set-properties (beg end) - "Make the file names highlight when the mouse is on them." + "Add various text properties to the lines in the region." (save-excursion (goto-char beg) (while (< (point) end) @@ -1168,7 +1210,7 @@ If HDR is non-nil, insert a header line with the directory name." ;; Reverting a dired buffer -(defun dired-revert (&optional arg noconfirm) +(defun dired-revert (&optional _arg _noconfirm) "Reread the dired buffer. Must also be called after `dired-actual-switches' have changed. Should not fail even on completely garbaged buffers. @@ -1510,6 +1552,10 @@ Do so according to the former subdir alist OLD-SUBDIR-ALIST." [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 revert-buffer] '(menu-item "Refresh" revert-buffer @@ -1666,7 +1712,7 @@ Do so according to the former subdir alist OLD-SUBDIR-ALIST." :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 + '(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] @@ -1776,8 +1822,8 @@ In Dired, you are \"editing\" a list of the files in a directory and files for later commands or \"flag\" them for deletion, either file by file or all files matching certain criteria. You can move using the usual cursor motion commands.\\ -Letters no longer insert themselves. Digits are prefix arguments. -Instead, type \\[dired-flag-file-deletion] to flag a file for Deletion. +The buffer is read-only. Digits are prefix arguments. +Type \\[dired-flag-file-deletion] to flag a file `D' for deletion. Type \\[dired-mark] to Mark a file or subdirectory for later commands. Most commands operate on the marked files and use the current file if no files are marked. Use a numeric prefix argument to operate on @@ -1785,9 +1831,9 @@ Type \\[dired-mark] to Mark a file or subdirectory for later commands. to operate on the current file only. Prefix arguments override marks. Mark-using commands display a list of failures afterwards. Type \\[dired-summary] to see why something went wrong. -Type \\[dired-unmark] to Unmark a file or all files of a subdirectory. -Type \\[dired-unmark-backward] to back up one line and unflag. -Type \\[dired-do-flagged-delete] to eXecute the deletions requested. +Type \\[dired-unmark] to Unmark a file or all files of an inserted subdirectory. +Type \\[dired-unmark-backward] to back up one line and unmark or unflag. +Type \\[dired-do-flagged-delete] to delete (eXecute) the files flagged `D'. Type \\[dired-find-file] to Find the current line's file (or dired it in another buffer, if it is a directory). Type \\[dired-find-file-other-window] to find file or dired directory in Other window. @@ -1797,12 +1843,12 @@ Type \\[dired-do-copy] to Copy files. Type \\[dired-sort-toggle-or-edit] to toggle Sorting by name/date or change the `ls' switches. Type \\[revert-buffer] to read all currently expanded directories aGain. This retains all marks and hides subdirs again that were hidden before. -SPC and DEL can be used to move down and up by lines. +Use `SPC' and `DEL' to move down and up by lines. If Dired ever gets confused, you can either type \\[revert-buffer] \ to read the directories again, type \\[dired-do-redisplay] \ -to relist a single or the marked files or a +to relist the file at point or the marked files or a subdirectory, or type \\[dired-build-subdir-alist] to parse the buffer again for the directory tree. @@ -2130,7 +2176,7 @@ Optional arg GLOBAL means to replace all matches." ;; dired-get-filename. (concat (or dir default-directory) file)) -(defun dired-make-relative (file &optional dir ignore) +(defun dired-make-relative (file &optional dir _ignore) "Convert FILE (an absolute file name) to a name relative to DIR. If this is impossible, return FILE unchanged. DIR must be a directory name, not a file name." @@ -2805,8 +2851,12 @@ also offers to kill buffers visiting deleted files and directories." (if (= 1 count) "" "s")) (defun dired-mark-prompt (arg files) - "Return a string for use in a prompt, either the current file -name, or the marker and a count of marked files." + "Return a string suitable for use in a Dired prompt. +ARG is normally the prefix argument for the calling command. +FILES should be a list of file names. + +The return value has a form like \"foo.txt\", \"[next 3 files]\", +or \"* [3 files]\"." ;; distinguish-one-marked can cause the first element to be just t. (if (eq (car files) t) (setq files (cdr files))) (let ((count (length files))) @@ -2829,7 +2879,7 @@ name, or the marker and a count of marked files." (window-splittable-p (selected-window))) ;; Try to split the selected window vertically if ;; that's possible. (Bug#1806) - (split-window-vertically)) + (split-window-below)) ;; Otherwise, try to split WINDOW sensibly. (split-window-sensibly window)))) pop-up-frames) @@ -3002,8 +3052,9 @@ If on a subdir headerline, mark all its files except `.' and `..'." (dired-mark arg))) (defun dired-unmark-backward (arg) - "In Dired, move up lines and remove deletion flag there. -Optional prefix ARG says how many lines to unflag; default is one line." + "In Dired, move up lines and remove marks or deletion flags there. +Optional prefix ARG says how many lines to unmark/unflag; default +is one line." (interactive "p") (dired-unmark (- arg))) @@ -3097,14 +3148,14 @@ The match is against the non-directory part of the filename. Use `^' (defun dired-mark-symlinks (unflag-p) "Mark all symbolic links. -With prefix argument, unflag all those files." +With prefix argument, unmark or unflag all those files." (interactive "P") (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char))) (dired-mark-if (looking-at dired-re-sym) "symbolic link"))) (defun dired-mark-directories (unflag-p) "Mark all directory file lines except `.' and `..'. -With prefix argument, unflag all those files." +With prefix argument, unmark or unflag all those files." (interactive "P") (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char))) (dired-mark-if (and (looking-at dired-re-dir) @@ -3113,7 +3164,7 @@ With prefix argument, unflag all those files." (defun dired-mark-executables (unflag-p) "Mark all executable files. -With prefix argument, unflag all those files." +With prefix argument, unmark or unflag all those files." (interactive "P") (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char))) (dired-mark-if (looking-at dired-re-exe) "executable file"))) @@ -3123,7 +3174,7 @@ With prefix argument, unflag all those files." (defun dired-flag-auto-save-files (&optional unflag-p) "Flag for deletion files whose names suggest they are auto save files. -A prefix argument says to unflag those files instead." +A prefix argument says to unmark or unflag those files instead." (interactive "P") (let ((dired-marker-char (if unflag-p ?\040 dired-del-marker))) (dired-mark-if @@ -3163,7 +3214,7 @@ A prefix argument says to unflag those files instead." (defun dired-flag-backup-files (&optional unflag-p) "Flag all backup files (names ending with `~') for deletion. -With prefix argument, unflag these files." +With prefix argument, unmark or unflag these files." (interactive "P") (let ((dired-marker-char (if unflag-p ?\s dired-del-marker))) (dired-mark-if @@ -3220,7 +3271,7 @@ Type \\[help-command] at that time for help." (interactive "cRemove marks (RET means all): \nP") (save-excursion (let* ((count 0) - (inhibit-read-only t) case-fold-search query + (inhibit-read-only t) case-fold-search (string (format "\n%c" mark)) (help-form "\ Type SPC or `y' to unmark one file, DEL or `n' to skip to next, @@ -3495,6 +3546,8 @@ Anything else means ask for each directory." (declare-function dnd-get-local-file-name "dnd" (uri &optional must-exist)) (declare-function dnd-get-local-file-uri "dnd" (uri)) +(defvar dired-overwrite-confirmed) ;Defined in dired-aux. + (defun dired-dnd-handle-local-file (uri action) "Copy, move or link a file to the dired directory. URI is the file to handle, ACTION is one of copy, move, link or ask. @@ -3556,38 +3609,38 @@ Ask means pop up a menu for the user to select one of copy, move or link." (eval-when-compile (require 'desktop)) -(defun dired-desktop-buffer-misc-data (desktop-dirname) +(defun dired-desktop-buffer-misc-data (dirname) "Auxiliary information to be saved in desktop file." (cons ;; Value of `dired-directory'. (if (consp dired-directory) ;; Directory name followed by list of files. - (cons (desktop-file-name (car dired-directory) desktop-dirname) + (cons (desktop-file-name (car dired-directory) dirname) (cdr dired-directory)) ;; Directory name, optionally with shell wildcard. - (desktop-file-name dired-directory desktop-dirname)) + (desktop-file-name dired-directory dirname)) ;; Subdirectories in `dired-subdir-alist'. (cdr (nreverse (mapcar - (function (lambda (f) (desktop-file-name (car f) desktop-dirname))) + (function (lambda (f) (desktop-file-name (car f) dirname))) dired-subdir-alist))))) -(defun dired-restore-desktop-buffer (desktop-buffer-file-name - desktop-buffer-name - desktop-buffer-misc) +(defun dired-restore-desktop-buffer (_file-name + _buffer-name + misc-data) "Restore a dired buffer specified in a desktop file." - ;; First element of `desktop-buffer-misc' is the value of `dired-directory'. + ;; First element of `misc-data' is the value of `dired-directory'. ;; This value is a directory name, optionally with shell wildcard or ;; a directory name followed by list of files. - (let* ((dired-dir (car desktop-buffer-misc)) + (let* ((dired-dir (car misc-data)) (dir (if (consp dired-dir) (car dired-dir) dired-dir))) (if (file-directory-p (file-name-directory dir)) (progn (dired dired-dir) - ;; The following elements of `desktop-buffer-misc' are the keys + ;; The following elements of `misc-data' are the keys ;; from `dired-subdir-alist'. - (mapc 'dired-maybe-insert-subdir (cdr desktop-buffer-misc)) + (mapc 'dired-maybe-insert-subdir (cdr misc-data)) (current-buffer)) (message "Desktop: Directory %s no longer exists." dir) (when desktop-missing-file-warning (sit-for 1)) @@ -3614,16 +3667,16 @@ Ask means pop up a menu for the user to select one of copy, move or link." ;;;;;; dired-run-shell-command dired-do-shell-command dired-do-async-shell-command ;;;;;; dired-clean-directory dired-do-print dired-do-touch dired-do-chown ;;;;;; dired-do-chgrp dired-do-chmod dired-compare-directories dired-backup-diff -;;;;;; dired-diff) "dired-aux" "dired-aux.el" "9d6333fab9c0f1b49e0bf2a536b8f245") +;;;;;; dired-diff) "dired-aux" "dired-aux.el" "2026ac587f0d9e893bae7662ff9d9318") ;;; Generated autoloads from dired-aux.el (autoload 'dired-diff "dired-aux" "\ Compare file at point with file FILE using `diff'. FILE defaults to the file at the mark. (That's the mark set by \\[set-mark-command], not by Dired's \\[dired-mark] command.) -The prompted-for file is the first file given to `diff'. +The prompted-for FILE is the first file given to `diff'. With prefix arg, prompt for second argument SWITCHES, -which is options for `diff'. +which is the string of command switches for `diff'. \(fn FILE &optional SWITCHES)" t nil) @@ -3751,7 +3804,7 @@ can be produced by `dired-get-marked-files', for example. \(fn COMMAND &optional ARG FILE-LIST)" t nil) (autoload 'dired-run-shell-command "dired-aux" "\ -Not documented + \(fn COMMAND)" nil nil) @@ -3770,7 +3823,7 @@ command with a prefix argument (the value does not matter). \(fn &optional ARG FMT)" t nil) (autoload 'dired-compress-file "dired-aux" "\ -Not documented + \(fn FILE)" nil nil) @@ -3819,12 +3872,12 @@ See Info node `(emacs)Subdir switches' for more details. \(fn &optional ARG TEST-FOR-SUBDIR)" t nil) (autoload 'dired-add-file "dired-aux" "\ -Not documented + \(fn FILENAME &optional MARKER-CHAR)" nil nil) (autoload 'dired-remove-file "dired-aux" "\ -Not documented + \(fn FILE)" nil nil) @@ -3834,17 +3887,18 @@ Create or update the line for FILE in all Dired buffers it would belong in. \(fn FILE)" nil nil) (autoload 'dired-copy-file "dired-aux" "\ -Not documented + \(fn FROM TO OK-FLAG)" nil nil) (autoload 'dired-rename-file "dired-aux" "\ -Not documented + \(fn FILE NEWNAME OK-IF-ALREADY-EXISTS)" nil nil) (autoload 'dired-create-directory "dired-aux" "\ Create a directory called DIRECTORY. +If DIRECTORY already exists, signal an error. \(fn DIRECTORY)" t nil) @@ -4065,15 +4119,16 @@ with the command \\[tags-loop-continue]. (autoload 'dired-show-file-type "dired-aux" "\ Print the type of FILE, according to the `file' command. -If FILE is a symbolic link and the optional argument DEREF-SYMLINKS is -true then the type of the file linked to by FILE is printed instead. +If you give a prefix to this command, and FILE is a symbolic +link, then the type of the file linked to by FILE is printed +instead. \(fn FILE &optional DEREF-SYMLINKS)" t nil) ;;;*** -;;;### (autoloads (dired-do-relsymlink dired-jump) "dired-x" "dired-x.el" -;;;;;; "c24f202ea049990539accfd4c2c73fe9") +;;;### (autoloads (dired-do-relsymlink dired-jump-other-window dired-jump) +;;;;;; "dired-x" "dired-x.el" "ea7c74fbb7dddf43bb85875018cb59ad") ;;; Generated autoloads from dired-x.el (autoload 'dired-jump "dired-x" "\ @@ -4088,6 +4143,11 @@ move to its line in dired. \(fn &optional OTHER-WINDOW FILE-NAME)" t nil) +(autoload 'dired-jump-other-window "dired-x" "\ +Like \\[dired-jump] (`dired-jump') but in other window. + +\(fn &optional FILE-NAME)" t nil) + (autoload 'dired-do-relsymlink "dired-x" "\ Relative symlink all marked (or next ARG) files into a directory. Otherwise make a relative symbolic link to the current file.