aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/dired-aux.el135
-rw-r--r--lisp/dired.el50
2 files changed, 100 insertions, 85 deletions
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index be93d71d70e..eea28769d93 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -28,6 +28,9 @@
28 28
29;;; Code: 29;;; Code:
30 30
31;; We need macros in dired.el to compile properly.
32(eval-when-compile (require 'dired))
33
31;;; 15K 34;;; 15K
32;;;###begin dired-cmd.el 35;;;###begin dired-cmd.el
33;; Diffing and compressing 36;; Diffing and compressing
@@ -127,7 +130,7 @@ This calls chmod, thus symbolic modes like `g+w' are allowed."
127 ;; and this file won't fit in the length limit, process now. 130 ;; and this file won't fit in the length limit, process now.
128 (if (and pending (> (+ thislength pending-length) max)) 131 (if (and pending (> (+ thislength pending-length) max))
129 (setq failures 132 (setq failures
130 (nconc (apply function (append args pending) pending) 133 (nconc (apply function (append args pending))
131 failures) 134 failures)
132 pending nil 135 pending nil
133 pending-length 0)) 136 pending-length 0))
@@ -137,7 +140,7 @@ This calls chmod, thus symbolic modes like `g+w' are allowed."
137 (setq pending files) 140 (setq pending files)
138 (setq pending-length (+ thislength pending-length)) 141 (setq pending-length (+ thislength pending-length))
139 (setq files rest))) 142 (setq files rest)))
140 (nconc (apply function (append args pending) pending) 143 (nconc (apply function (append args pending))
141 failures))) 144 failures)))
142 145
143;;;###autoload 146;;;###autoload
@@ -172,6 +175,8 @@ Uses the shell command coming from variables `lpr-command' and
172 175
173;;; Cleaning a directory: flagging some backups for deletion. 176;;; Cleaning a directory: flagging some backups for deletion.
174 177
178(defvar dired-file-version-alist)
179
175(defun dired-clean-directory (keep) 180(defun dired-clean-directory (keep)
176 "Flag numerical backups for deletion. 181 "Flag numerical backups for deletion.
177Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest. 182Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest.
@@ -282,46 +287,47 @@ with a prefix argument."
282;; The in-background argument is only needed in Emacs 18 where 287;; The in-background argument is only needed in Emacs 18 where
283;; shell-command doesn't understand an appended ampersand `&'. 288;; shell-command doesn't understand an appended ampersand `&'.
284;;;###autoload 289;;;###autoload
285(defun dired-do-shell-command (&optional arg in-background) 290(defun dired-do-shell-command (command &optional arg)
286 "Run a shell command on the marked files. 291 "Run a shell command COMMAND on the marked files.
292If no files are marked or a specific numeric prefix arg is given,
293the next ARG files are used. Just \\[universal-argument] means the current file.
294The prompt mentions the file(s) or the marker, as appropriate.
295
287If there is output, it goes to a separate buffer. 296If there is output, it goes to a separate buffer.
297
288Normally the command is run on each file individually. 298Normally the command is run on each file individually.
289However, if there is a `*' in the command then it is run 299However, if there is a `*' in the command then it is run
290just once with the entire file list substituted there. 300just once with the entire file list substituted there.
291 301
292If no files are marked or a specific numeric prefix arg is given, 302No automatic redisplay of dired buffers is attempted, as there's no
293the next ARG files are used. Just \\[universal-argument] means the current file. 303telling what files the command may have changed. Type
294The prompt mentions the file(s) or the marker, as appropriate. 304\\[dired-do-redisplay] to redisplay the marked files.
295
296No automatic redisplay is attempted, as the file names may have
297changed. Type \\[dired-do-redisplay] to redisplay the marked files.
298 305
299The shell command has the top level directory as working directory, so 306The shell command has the top level directory as working directory, so
300output files usually are created there instead of in a subdir." 307output files usually are created there instead of in a subdir."
301;;Functions dired-run-shell-command and dired-shell-stuff-it do the 308;;Functions dired-run-shell-command and dired-shell-stuff-it do the
302;;actual work and can be redefined for customization. 309;;actual work and can be redefined for customization.
303 (interactive "P") 310 (interactive (list
311 ;; Want to give feedback whether this file or marked files are used:
312 (dired-read-shell-command (concat "! on "
313 "%s: ")
314 current-prefix-arg
315 (dired-get-marked-files
316 t current-prefix-arg))
317 current-prefix-arg))
304 (let* ((on-each (not (string-match "\\*" command))) 318 (let* ((on-each (not (string-match "\\*" command)))
305 (prompt (concat (if in-background "& on " "! on ") 319 (file-list (dired-get-marked-files t arg)))
306 (if on-each "each " "")
307 "%s: "))
308 (file-list (dired-get-marked-files t arg))
309 ;; Want to give feedback whether this file or marked files are used:
310 (command (dired-read-shell-command
311 prompt arg file-list)))
312 (if on-each 320 (if on-each
313 (dired-bunch-files 321 (dired-bunch-files
314 (- 10000 (length command)) 322 (- 10000 (length command))
315 (function (lambda (&rest files) 323 (function (lambda (&rest files)
316 (dired-run-shell-command 324 (dired-run-shell-command
317 (dired-shell-stuff-it command files t arg)) 325 (dired-shell-stuff-it command files t arg))))
318 in-background))
319 nil 326 nil
320 file-list) 327 file-list)
321 ;; execute the shell command 328 ;; execute the shell command
322 (dired-run-shell-command 329 (dired-run-shell-command
323 (dired-shell-stuff-it command file-list nil arg) 330 (dired-shell-stuff-it command file-list nil arg)))))
324 in-background))))
325 331
326;; Might use {,} for bash or csh: 332;; Might use {,} for bash or csh:
327(defvar dired-mark-prefix "" 333(defvar dired-mark-prefix ""
@@ -356,12 +362,10 @@ output files usually are created there instead of in a subdir."
356 (funcall stuff-it fns))))) 362 (funcall stuff-it fns)))))
357 363
358;; This is an extra function so that it can be redefined by ange-ftp. 364;; This is an extra function so that it can be redefined by ange-ftp.
359(defun dired-run-shell-command (command &optional in-background) 365(defun dired-run-shell-command (command)
360 (if (not in-background) 366 (shell-command command)
361 (shell-command command) 367 ;; Return nil for sake of nconc in dired-bunch-files.
362 ;; We need this only in Emacs 18 (19's shell command has `&'). 368 nil)
363 ;; comint::background is defined in emacs-19.el.
364 (comint::background command)))
365 369
366;; In Emacs 19 this will return program's exit status. 370;; In Emacs 19 this will return program's exit status.
367;; This is a separate function so that ange-ftp can redefine it. 371;; This is a separate function so that ange-ftp can redefine it.
@@ -398,17 +402,6 @@ output files usually are created there instead of in a subdir."
398 402
399;; Commands that delete or redisplay part of the dired buffer. 403;; Commands that delete or redisplay part of the dired buffer.
400 404
401;;;###autoload
402(defun dired-kill-line-or-subdir (&optional arg)
403 "Kill this line (but don't delete its file).
404Optional prefix argument is a repeat factor.
405If file is displayed as in situ subdir, kill that as well.
406If on a subdir headerline, kill whole subdir."
407 (interactive "p")
408 (if (dired-get-subdir)
409 (dired-kill-subdir)
410 (dired-kill-line arg)))
411
412(defun dired-kill-line (&optional arg) 405(defun dired-kill-line (&optional arg)
413 (interactive "P") 406 (interactive "P")
414 (setq arg (prefix-numeric-value arg)) 407 (setq arg (prefix-numeric-value arg))
@@ -431,31 +424,38 @@ If on a subdir headerline, kill whole subdir."
431;;;###autoload 424;;;###autoload
432(defun dired-do-kill-lines (&optional arg fmt) 425(defun dired-do-kill-lines (&optional arg fmt)
433 "Kill all marked lines (not the files). 426 "Kill all marked lines (not the files).
434With a prefix arg, kill all lines not marked or flagged." 427With a prefix argument, kill that many lines starting with the current line.
428\(A negative argument kills lines before the current line.)
429To kill an entire subdirectory, go to its directory header line
430and use this command with a prefix argument (the value does not matter)."
435 ;; Returns count of killed lines. FMT="" suppresses message. 431 ;; Returns count of killed lines. FMT="" suppresses message.
436 (interactive "P") 432 (interactive "P")
437 (save-excursion 433 (if arg
438 (goto-char (point-min)) 434 (if (dired-get-subdir)
439 (let (buffer-read-only (count 0)) 435 (dired-kill-subdir)
440 (if (not arg) ; kill marked lines 436 (dired-kill-line arg))
441 (let ((regexp (dired-marker-regexp))) 437 (save-excursion
442 (while (and (not (eobp)) 438 (goto-char (point-min))
443 (re-search-forward regexp nil t)) 439 (let (buffer-read-only (count 0))
440 (if (not arg) ; kill marked lines
441 (let ((regexp (dired-marker-regexp)))
442 (while (and (not (eobp))
443 (re-search-forward regexp nil t))
444 (setq count (1+ count))
445 (delete-region (progn (beginning-of-line) (point))
446 (progn (forward-line 1) (point)))))
447 ;; else kill unmarked lines
448 (while (not (eobp))
449 (if (or (dired-between-files)
450 (not (looking-at "^ ")))
451 (forward-line 1)
444 (setq count (1+ count)) 452 (setq count (1+ count))
445 (delete-region (progn (beginning-of-line) (point)) 453 (delete-region (point) (save-excursion
446 (progn (forward-line 1) (point))))) 454 (forward-line 1)
447 ;; else kill unmarked lines 455 (point))))))
448 (while (not (eobp)) 456 (or (equal "" fmt)
449 (if (or (dired-between-files) 457 (message (or fmt "Killed %d line%s.") count (dired-plural-s count)))
450 (not (looking-at "^ "))) 458 count))))
451 (forward-line 1)
452 (setq count (1+ count))
453 (delete-region (point) (save-excursion
454 (forward-line 1)
455 (point))))))
456 (or (equal "" fmt)
457 (message (or fmt "Killed %d line%s.") count (dired-plural-s count)))
458 count)))
459 459
460;;;###end dired-cmd.el 460;;;###end dired-cmd.el
461 461
@@ -645,7 +645,8 @@ a prefix arg lets you edit the `ls' switches used for the new listing."
645 ;; here is faster than with dired-add-entry's optional arg). 645 ;; here is faster than with dired-add-entry's optional arg).
646 ;; Does not update other dired buffers. Use dired-relist-entry for that. 646 ;; Does not update other dired buffers. Use dired-relist-entry for that.
647 (beginning-of-line) 647 (beginning-of-line)
648 (let ((char (following-char)) (opoint (point))) 648 (let ((char (following-char)) (opoint (point))
649 (buffer-read-only))
649 (delete-region (point) (progn (forward-line 1) (point))) 650 (delete-region (point) (progn (forward-line 1) (point)))
650 (if file 651 (if file
651 (progn 652 (progn
@@ -801,12 +802,14 @@ a prefix arg lets you edit the `ls' switches used for the new listing."
801 "*Non-nil if Dired should ask about making backups before overwriting files. 802 "*Non-nil if Dired should ask about making backups before overwriting files.
802Special value `always' suppresses confirmation.") 803Special value `always' suppresses confirmation.")
803 804
805(defvar dired-overwrite-confirmed)
806
804(defun dired-handle-overwrite (to) 807(defun dired-handle-overwrite (to)
805 ;; Save old version of a to be overwritten file TO. 808 ;; Save old version of a to be overwritten file TO.
806 ;; `overwrite-confirmed' and `overwrite-backup-query' are fluid vars 809 ;; `dired-overwrite-confirmed' and `overwrite-backup-query' are fluid vars
807 ;; from dired-create-files. 810 ;; from dired-create-files.
808 (if (and dired-backup-overwrite 811 (if (and dired-backup-overwrite
809 overwrite-confirmed 812 dired-overwrite-confirmed
810 (or (eq 'always dired-backup-overwrite) 813 (or (eq 'always dired-backup-overwrite)
811 (dired-query 'overwrite-backup-query 814 (dired-query 'overwrite-backup-query
812 (format "Make backup for existing file `%s'? " to)))) 815 (format "Make backup for existing file `%s'? " to))))
@@ -1013,7 +1016,7 @@ Optional arg GLOBAL means to replace all matches."
1013 (if (not to) 1016 (if (not to)
1014 (setq skipped (cons (dired-make-relative from) skipped)) 1017 (setq skipped (cons (dired-make-relative from) skipped))
1015 (let* ((overwrite (file-exists-p to)) 1018 (let* ((overwrite (file-exists-p to))
1016 (overwrite-confirmed ; for dired-handle-overwrite 1019 (dired-overwrite-confirmed ; for dired-handle-overwrite
1017 (and overwrite 1020 (and overwrite
1018 (let ((help-form '(format "\ 1021 (let ((help-form '(format "\
1019Type SPC or `y' to overwrite file `%s', 1022Type SPC or `y' to overwrite file `%s',
@@ -1030,7 +1033,7 @@ ESC or `q' to not overwrite any of the remaining files,
1030 (t nil)))) 1033 (t nil))))
1031 (condition-case err 1034 (condition-case err
1032 (progn 1035 (progn
1033 (funcall file-creator from to overwrite-confirmed) 1036 (funcall file-creator from to dired-overwrite-confirmed)
1034 (if overwrite 1037 (if overwrite
1035 ;; If we get here, file-creator hasn't been aborted 1038 ;; If we get here, file-creator hasn't been aborted
1036 ;; and the old entry (if any) has to be deleted 1039 ;; and the old entry (if any) has to be deleted
diff --git a/lisp/dired.el b/lisp/dired.el
index be4595fa28b..2929bed5e8c 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -630,7 +630,7 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh."
630 (define-key dired-mode-map "/" 'dired-mark-directories) 630 (define-key dired-mode-map "/" 'dired-mark-directories)
631 (define-key dired-mode-map "@" 'dired-mark-symlinks) 631 (define-key dired-mode-map "@" 'dired-mark-symlinks)
632 (define-key dired-mode-map "~" 'dired-flag-backup-files) 632 (define-key dired-mode-map "~" 'dired-flag-backup-files)
633 ;; Upper case keys (except !, c) for operating on the marked files 633 ;; Upper case keys (except !) for operating on the marked files
634 (define-key dired-mode-map "C" 'dired-do-copy) 634 (define-key dired-mode-map "C" 'dired-do-copy)
635 (define-key dired-mode-map "B" 'dired-do-byte-compile) 635 (define-key dired-mode-map "B" 'dired-do-byte-compile)
636 (define-key dired-mode-map "D" 'dired-do-delete) 636 (define-key dired-mode-map "D" 'dired-do-delete)
@@ -657,8 +657,6 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh."
657 ;; move to marked files 657 ;; move to marked files
658 (define-key dired-mode-map "\M-{" 'dired-prev-marked-file) 658 (define-key dired-mode-map "\M-{" 'dired-prev-marked-file)
659 (define-key dired-mode-map "\M-}" 'dired-next-marked-file) 659 (define-key dired-mode-map "\M-}" 'dired-next-marked-file)
660 ;; kill marked files
661 (define-key dired-mode-map "\M-k" 'dired-do-kill-lines)
662 ;; Make all regexp commands share a `%' prefix: 660 ;; Make all regexp commands share a `%' prefix:
663 (fset 'dired-regexp-prefix (make-sparse-keymap)) 661 (fset 'dired-regexp-prefix (make-sparse-keymap))
664 (define-key dired-mode-map "%" 'dired-regexp-prefix) 662 (define-key dired-mode-map "%" 'dired-regexp-prefix)
@@ -672,13 +670,14 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh."
672 (define-key dired-mode-map "%R" 'dired-do-rename-regexp) 670 (define-key dired-mode-map "%R" 'dired-do-rename-regexp)
673 (define-key dired-mode-map "%S" 'dired-do-symlink-regexp) 671 (define-key dired-mode-map "%S" 'dired-do-symlink-regexp)
674 ;; Lower keys for commands not operating on all the marked files 672 ;; Lower keys for commands not operating on all the marked files
673 (define-key dired-mode-map "c" 'dired-change-marks)
675 (define-key dired-mode-map "d" 'dired-flag-file-deletion) 674 (define-key dired-mode-map "d" 'dired-flag-file-deletion)
676 (define-key dired-mode-map "e" 'dired-find-file) 675 (define-key dired-mode-map "e" 'dired-find-file)
677 (define-key dired-mode-map "f" 'dired-advertised-find-file) 676 (define-key dired-mode-map "f" 'dired-advertised-find-file)
678 (define-key dired-mode-map "g" 'revert-buffer) 677 (define-key dired-mode-map "g" 'revert-buffer)
679 (define-key dired-mode-map "h" 'describe-mode) 678 (define-key dired-mode-map "h" 'describe-mode)
680 (define-key dired-mode-map "i" 'dired-maybe-insert-subdir) 679 (define-key dired-mode-map "i" 'dired-maybe-insert-subdir)
681 (define-key dired-mode-map "k" 'dired-kill-line-or-subdir) 680 (define-key dired-mode-map "k" 'dired-do-kill-lines)
682 (define-key dired-mode-map "l" 'dired-do-redisplay) 681 (define-key dired-mode-map "l" 'dired-do-redisplay)
683 (define-key dired-mode-map "m" 'dired-mark) 682 (define-key dired-mode-map "m" 'dired-mark)
684 (define-key dired-mode-map "n" 'dired-next-line) 683 (define-key dired-mode-map "n" 'dired-next-line)
@@ -1678,6 +1677,24 @@ With prefix argument, unflag these files."
1678 (if fn (backup-file-name-p fn)))) 1677 (if fn (backup-file-name-p fn))))
1679 "backup file"))) 1678 "backup file")))
1680 1679
1680(defun dired-change-marks (&optional old new)
1681 "Change all OLD marks to NEW marks.
1682OLD and NEW are both characters used to mark files."
1683 (interactive
1684 (let* ((cursor-in-echo-area t)
1685 (old (progn (message "Change (old mark): ") (read-char)))
1686 (new (progn (message "Change %c marks to (new mark): " old)
1687 (read-char))))
1688 (list old new)))
1689 (let ((regexp (format "^%s" (regexp-quote old)))
1690 (buffer-read-only))
1691 (save-excursion
1692 (goto-char (point-min))
1693 (while (re-search-forward regexp nil t)
1694 (beginning-of-line)
1695 (delete-region (point) (1+ (point)))
1696 (insert-char new 1)))))
1697
1681(defun dired-unmark-all-files (flag &optional arg) 1698(defun dired-unmark-all-files (flag &optional arg)
1682 "Remove a specific mark or any mark from every file. 1699 "Remove a specific mark or any mark from every file.
1683With an arg, queries for each marked file. 1700With an arg, queries for each marked file.
@@ -1713,7 +1730,7 @@ Thus, use \\[backward-page] to find the beginning of a group of errors."
1713 (let ((owindow (selected-window)) 1730 (let ((owindow (selected-window))
1714 (window (display-buffer (get-buffer dired-log-buffer)))) 1731 (window (display-buffer (get-buffer dired-log-buffer))))
1715 (unwind-protect 1732 (unwind-protect
1716 (save-excursion 1733 (progn
1717 (select-window window) 1734 (select-window window)
1718 (goto-char (point-max)) 1735 (goto-char (point-max))
1719 (recenter -1)) 1736 (recenter -1))
@@ -1881,30 +1898,25 @@ Uses the shell command coming from variables `lpr-command' and
1881 t) 1898 t)
1882 1899
1883(autoload 'dired-do-shell-command "dired-aux" 1900(autoload 'dired-do-shell-command "dired-aux"
1884 "Run a shell command on the marked files. 1901 "Run a shell command COMMAND on the marked files.
1902If no files are marked or a specific numeric prefix arg is given,
1903the next ARG files are used. Just \\[universal-argument] means the current file.
1904The prompt mentions the file(s) or the marker, as appropriate.
1905
1885If there is output, it goes to a separate buffer. 1906If there is output, it goes to a separate buffer.
1907
1886Normally the command is run on each file individually. 1908Normally the command is run on each file individually.
1887However, if there is a `*' in the command then it is run 1909However, if there is a `*' in the command then it is run
1888just once with the entire file list substituted there. 1910just once with the entire file list substituted there.
1889 1911
1890If no files are marked or a specific numeric prefix arg is given, 1912No automatic redisplay of dired buffers is attempted, as there's no
1891the next ARG files are used. Just \\[universal-argument] means the current file. 1913telling what files the command may have changed. Type
1892The prompt mentions the file(s) or the marker, as appropriate. 1914\\[dired-do-redisplay] to redisplay the marked files.
1893
1894No automatic redisplay is attempted, as the file names may have
1895changed. Type \\[dired-do-redisplay] to redisplay the marked files.
1896 1915
1897The shell command has the top level directory as working directory, so 1916The shell command has the top level directory as working directory, so
1898output files usually are created there instead of in a subdir." 1917output files usually are created there instead of in a subdir."
1899 t) 1918 t)
1900 1919
1901(autoload 'dired-kill-line-or-subdir "dired-aux"
1902 "Kill this line (but don't delete its file).
1903Optional prefix argument is a repeat factor.
1904If file is displayed as in situ subdir, kill that as well.
1905If on a subdir headerline, kill whole subdir."
1906 t)
1907
1908(autoload 'dired-do-kill-lines "dired-aux" 1920(autoload 'dired-do-kill-lines "dired-aux"
1909 "Kill all marked lines (not the files). 1921 "Kill all marked lines (not the files).
1910With a prefix arg, kill all lines not marked or flagged." 1922With a prefix arg, kill all lines not marked or flagged."