Mercurial > emacs
comparison lisp/dired-aux.el @ 89943:4c90ffeb71c5
Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-15
Merge from emacs--cvs-trunk--0
Patches applied:
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-218
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-220
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-221
Restore deleted tagline in etc/TUTORIAL.ru
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-222
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-228
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-229
Remove TeX output files from the archive
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-230
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-247
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-248
src/lisp.h (CYCLE_CHECK): Macro moved from xfaces.c
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-249
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-256
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-258
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-263
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-264
Update from CVS: lispref/display.texi: emacs -> Emacs.
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-265
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-274
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-275
Update from CVS: man/makefile.w32-in: Revert last change
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-276
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-295
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-296
Allow restarting an existing debugger session that's exited
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-297
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-299
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-300
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-327
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-328
Update from CVS: src/.gdbinit (xsymbol): Fix last change.
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-329
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-344
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-345
Tweak source regexps so that building in place won't cause problems
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-346
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-351
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-352
Update from CVS: lisp/flymake.el: New file.
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-353
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-361
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-362
Support " [...]" style defaults in minibuffer-electric-default-mode
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-363
(read-number): Use canonical format for default in prompt.
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-364
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-367
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-368
Improve display-supports-face-attributes-p on non-ttys
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-369
Rewrite face-differs-from-default-p
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-370
Move `display-supports-face-attributes-p' entirely into C code
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-371
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-372
Simplify face-differs-from-default-p; don't consider :stipple.
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-373
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-374
(tty_supports_face_attributes_p): Ensure attributes differ from default
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-375
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-376
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-377
(Fdisplay_supports_face_attributes_p): Work around bootstrapping problem
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-378
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-380
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-381
Face merging cleanups
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-382
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-384
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-385
src/xfaces.c (push_named_merge_point): Return 0 if a cycle is detected
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-386
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-395
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-396
Tweak arch tagging to make build/install-in-place less annoying
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-397
Work around vc-arch problems when building eshell
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-398
Tweak permissions
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-399
Tweak directory permissions
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-400
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-401
More build-in-place tweaking of arch tagging
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-402
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-403
Yet more build-in-place tweaking of arch tagging
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-404
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-409
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-410
Make sure image types are initialized for lookup too
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-411
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-416
Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Mon, 28 Jun 2004 07:56:49 +0000 |
parents | 68c22ea6027c 1f13c1cdc0b1 |
children | b9eee0a7bef5 |
comparison
equal
deleted
inserted
replaced
89942:9cb747ae49af | 89943:4c90ffeb71c5 |
---|---|
62 (list (read-file-name (format "Diff %s with: %s" | 62 (list (read-file-name (format "Diff %s with: %s" |
63 (dired-get-filename t) | 63 (dired-get-filename t) |
64 (if default | 64 (if default |
65 (concat "(default " default ") ") | 65 (concat "(default " default ") ") |
66 "")) | 66 "")) |
67 (dired-current-directory) default t) | 67 (if default |
68 (dired-current-directory) | |
69 (dired-dwim-target-directory)) | |
70 default t) | |
68 (if current-prefix-arg | 71 (if current-prefix-arg |
69 (read-string "Options for diff: " | 72 (read-string "Options for diff: " |
70 (if (stringp diff-switches) | 73 (if (stringp diff-switches) |
71 diff-switches | 74 diff-switches |
72 (mapconcat 'identity diff-switches " "))))))) | 75 (mapconcat 'identity diff-switches " "))))))) |
183 (list file-name | 186 (list file-name |
184 full-file-name | 187 full-file-name |
185 (file-attributes full-file-name)))) | 188 (file-attributes full-file-name)))) |
186 (directory-files dir))) | 189 (directory-files dir))) |
187 | 190 |
191 | |
192 (defun dired-touch-initial (files) | |
193 "Create initial input value for `touch' command." | |
194 (let (initial) | |
195 (while files | |
196 (let ((current (nth 5 (file-attributes (car files))))) | |
197 (if (and initial (not (equal initial current))) | |
198 (setq initial (current-time) files nil) | |
199 (setq initial current)) | |
200 (setq files (cdr files)))) | |
201 (format-time-string "%Y%m%d%H%M.%S" initial))) | |
202 | |
188 (defun dired-do-chxxx (attribute-name program op-symbol arg) | 203 (defun dired-do-chxxx (attribute-name program op-symbol arg) |
189 ;; Change file attributes (mode, group, owner, timestamp) of marked files and | 204 ;; Change file attributes (mode, group, owner, timestamp) of marked files and |
190 ;; refresh their file lines. | 205 ;; refresh their file lines. |
191 ;; ATTRIBUTE-NAME is a string describing the attribute to the user. | 206 ;; ATTRIBUTE-NAME is a string describing the attribute to the user. |
192 ;; PROGRAM is the program used to change the attribute. | 207 ;; PROGRAM is the program used to change the attribute. |
194 ;; ARG describes which files to use, as in dired-get-marked-files. | 209 ;; ARG describes which files to use, as in dired-get-marked-files. |
195 (let* ((files (dired-get-marked-files t arg)) | 210 (let* ((files (dired-get-marked-files t arg)) |
196 (new-attribute | 211 (new-attribute |
197 (dired-mark-read-string | 212 (dired-mark-read-string |
198 (concat "Change " attribute-name " of %s to: ") | 213 (concat "Change " attribute-name " of %s to: ") |
199 nil op-symbol arg files)) | 214 (if (eq op-symbol 'touch) (dired-touch-initial files)) |
215 op-symbol arg files)) | |
200 (operation (concat program " " new-attribute)) | 216 (operation (concat program " " new-attribute)) |
201 failures) | 217 failures) |
202 (setq failures | 218 (setq failures |
203 (dired-bunch-files 10000 | 219 (dired-bunch-files 10000 |
204 (function dired-check-process) | 220 (function dired-check-process) |
237 (interactive "P") | 253 (interactive "P") |
238 (if (memq system-type '(ms-dos windows-nt)) | 254 (if (memq system-type '(ms-dos windows-nt)) |
239 (error "chown not supported on this system")) | 255 (error "chown not supported on this system")) |
240 (dired-do-chxxx "Owner" dired-chown-program 'chown arg)) | 256 (dired-do-chxxx "Owner" dired-chown-program 'chown arg)) |
241 | 257 |
258 ;;;###autoload | |
242 (defun dired-do-touch (&optional arg) | 259 (defun dired-do-touch (&optional arg) |
243 "Change the timestamp of the marked (or next ARG) files. | 260 "Change the timestamp of the marked (or next ARG) files. |
244 This calls touch." | 261 This calls touch." |
245 (interactive "P") | 262 (interactive "P") |
246 (dired-do-chxxx "Timestamp" dired-touch-program 'touch arg)) | 263 (dired-do-chxxx "Timestamp" dired-touch-program 'touch arg)) |
324 | 341 |
325 ;;; Cleaning a directory: flagging some backups for deletion. | 342 ;;; Cleaning a directory: flagging some backups for deletion. |
326 | 343 |
327 (defvar dired-file-version-alist) | 344 (defvar dired-file-version-alist) |
328 | 345 |
346 ;;;###autoload | |
329 (defun dired-clean-directory (keep) | 347 (defun dired-clean-directory (keep) |
330 "Flag numerical backups for deletion. | 348 "Flag numerical backups for deletion. |
331 Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest. | 349 Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest. |
332 Positive prefix arg KEEP overrides `dired-kept-versions'; | 350 Positive prefix arg KEEP overrides `dired-kept-versions'; |
333 Negative prefix arg KEEP overrides `kept-old-versions' with KEEP made positive. | 351 Negative prefix arg KEEP overrides `kept-old-versions' with KEEP made positive. |
533 (if (> (length file-list) 1) | 551 (if (> (length file-list) 1) |
534 (setq files (concat dired-mark-prefix files dired-mark-postfix))) | 552 (setq files (concat dired-mark-prefix files dired-mark-postfix))) |
535 (funcall stuff-it files))))) | 553 (funcall stuff-it files))))) |
536 | 554 |
537 ;; This is an extra function so that it can be redefined by ange-ftp. | 555 ;; This is an extra function so that it can be redefined by ange-ftp. |
556 ;;;###autoload | |
538 (defun dired-run-shell-command (command) | 557 (defun dired-run-shell-command (command) |
539 (let ((handler | 558 (let ((handler |
540 (find-file-name-handler (directory-file-name default-directory) | 559 (find-file-name-handler (directory-file-name default-directory) |
541 'shell-command))) | 560 'shell-command))) |
542 (if handler (apply handler 'shell-command (list command)) | 561 (if handler (apply handler 'shell-command (list command)) |
787 (?! . yes) ; `!' accepts rest | 806 (?! . yes) ; `!' accepts rest |
788 (?q . no) (?\e . no) ; `q' or ESC skips rest | 807 (?q . no) (?\e . no) ; `q' or ESC skips rest |
789 ;; None of these keys quit - use C-g for that. | 808 ;; None of these keys quit - use C-g for that. |
790 )) | 809 )) |
791 | 810 |
811 ;;;###autoload | |
792 (defun dired-query (qs-var qs-prompt &rest qs-args) | 812 (defun dired-query (qs-var qs-prompt &rest qs-args) |
793 ;; Query user and return nil or t. | 813 ;; Query user and return nil or t. |
794 ;; Store answer in symbol VAR (which must initially be bound to nil). | 814 ;; Store answer in symbol VAR (which must initially be bound to nil). |
795 ;; Format PROMPT with ARGS. | 815 ;; Format PROMPT with ARGS. |
796 ;; Binding variable help-form will help the user who types the help key. | 816 ;; Binding variable help-form will help the user who types the help key. |
873 | 893 |
874 ;;;###autoload | 894 ;;;###autoload |
875 (defun dired-do-redisplay (&optional arg test-for-subdir) | 895 (defun dired-do-redisplay (&optional arg test-for-subdir) |
876 "Redisplay all marked (or next ARG) files. | 896 "Redisplay all marked (or next ARG) files. |
877 If on a subdir line, redisplay that subdirectory. In that case, | 897 If on a subdir line, redisplay that subdirectory. In that case, |
878 a prefix arg lets you edit the `ls' switches used for the new listing." | 898 a prefix arg lets you edit the `ls' switches used for the new listing. |
899 | |
900 Dired remembers switches specified with a prefix arg, so that reverting | |
901 the buffer will not reset them. However, using `dired-undo' to re-insert | |
902 or delete subdirectories can bypass this machinery. Hence, you sometimes | |
903 may have to reset some subdirectory switches after a `dired-undo'. | |
904 You can reset all subdirectory switches to the default using | |
905 \\<dired-mode-map>\\[dired-reset-subdir-switches]. | |
906 See Info node `(emacs-xtra)Subdir switches' for more details." | |
879 ;; Moves point if the next ARG files are redisplayed. | 907 ;; Moves point if the next ARG files are redisplayed. |
880 (interactive "P\np") | 908 (interactive "P\np") |
881 (if (and test-for-subdir (dired-get-subdir)) | 909 (if (and test-for-subdir (dired-get-subdir)) |
882 (dired-insert-subdir | 910 (let* ((dir (dired-get-subdir)) |
883 (dired-get-subdir) | 911 (switches (cdr (assoc-string dir dired-switches-alist)))) |
884 (if arg (read-string "Switches for listing: " dired-actual-switches))) | 912 (dired-insert-subdir |
913 dir | |
914 (when arg | |
915 (read-string "Switches for listing: " | |
916 (or switches | |
917 dired-subdir-switches | |
918 dired-actual-switches))))) | |
885 (message "Redisplaying...") | 919 (message "Redisplaying...") |
886 ;; message much faster than making dired-map-over-marks show progress | 920 ;; message much faster than making dired-map-over-marks show progress |
887 (dired-uncache | 921 (dired-uncache |
888 (if (consp dired-directory) (car dired-directory) dired-directory)) | 922 (if (consp dired-directory) (car dired-directory) dired-directory)) |
889 (dired-map-over-marks (let ((fname (dired-get-filename))) | 923 (dired-map-over-marks (let ((fname (dired-get-filename))) |
890 (message "Redisplaying... %s" fname) | 924 (message "Redisplaying... %s" fname) |
891 (dired-update-file-line fname)) | 925 (dired-update-file-line fname)) |
892 arg) | 926 arg) |
893 (dired-move-to-filename) | 927 (dired-move-to-filename) |
894 (message "Redisplaying...done"))) | 928 (message "Redisplaying...done"))) |
929 | |
930 (defun dired-reset-subdir-switches () | |
931 "Set `dired-switches-alist' to nil and revert dired buffer." | |
932 (interactive) | |
933 (setq dired-switches-alist nil) | |
934 (revert-buffer)) | |
895 | 935 |
896 (defun dired-update-file-line (file) | 936 (defun dired-update-file-line (file) |
897 ;; Delete the current line, and insert an entry for FILE. | 937 ;; Delete the current line, and insert an entry for FILE. |
898 ;; If FILE is nil, then just delete the current line. | 938 ;; If FILE is nil, then just delete the current line. |
899 ;; Keeps any marks that may be present in column one (doing this | 939 ;; Keeps any marks that may be present in column one (doing this |
1189 (rename-buffer new-name))) | 1229 (rename-buffer new-name))) |
1190 ;; ... we dired TO now: | 1230 ;; ... we dired TO now: |
1191 (dired-advertise))))) | 1231 (dired-advertise))))) |
1192 | 1232 |
1193 (defun dired-rename-subdir-2 (elt dir to) | 1233 (defun dired-rename-subdir-2 (elt dir to) |
1194 ;; Update the headerline and dired-subdir-alist element of directory | 1234 ;; Update the headerline and dired-subdir-alist element, as well as |
1195 ;; described by alist-element ELT to reflect the moving of DIR to TO. | 1235 ;; dired-switches-alist element, of directory described by |
1196 ;; Thus, ELT describes either DIR itself or a subdir of DIR. | 1236 ;; alist-element ELT to reflect the moving of DIR to TO. Thus, ELT |
1237 ;; describes either DIR itself or a subdir of DIR. | |
1197 (save-excursion | 1238 (save-excursion |
1198 (let ((regexp (regexp-quote (directory-file-name dir))) | 1239 (let ((regexp (regexp-quote (directory-file-name dir))) |
1199 (newtext (directory-file-name to)) | 1240 (newtext (directory-file-name to)) |
1200 buffer-read-only) | 1241 buffer-read-only) |
1201 (goto-char (dired-get-subdir-min elt)) | 1242 (goto-char (dired-get-subdir-min elt)) |
1205 dir) | 1246 dir) |
1206 (goto-char (match-beginning 1)) | 1247 (goto-char (match-beginning 1)) |
1207 (if (re-search-forward regexp (match-end 1) t) | 1248 (if (re-search-forward regexp (match-end 1) t) |
1208 (replace-match newtext t t) | 1249 (replace-match newtext t t) |
1209 (error "Expected to find `%s' in headerline of %s" dir (car elt)))) | 1250 (error "Expected to find `%s' in headerline of %s" dir (car elt)))) |
1210 ;; Update buffer-local dired-subdir-alist | 1251 ;; Update buffer-local dired-subdir-alist and dired-switches-alist |
1211 (setcar elt | 1252 (let ((cons (assoc-string (car elt) dired-switches-alist)) |
1212 (dired-normalize-subdir | 1253 (cur-dir (dired-normalize-subdir |
1213 (dired-replace-in-string regexp newtext (car elt))))))) | 1254 (dired-replace-in-string regexp newtext (car elt))))) |
1255 (setcar elt cur-dir) | |
1256 (when cons (setcar cons cur-dir)))))) | |
1214 | 1257 |
1215 ;; The basic function for half a dozen variations on cp/mv/ln/ln -s. | 1258 ;; The basic function for half a dozen variations on cp/mv/ln/ln -s. |
1216 (defun dired-create-files (file-creator operation fn-list name-constructor | 1259 (defun dired-create-files (file-creator operation fn-list name-constructor |
1217 &optional marker-char) | 1260 &optional marker-char) |
1218 | 1261 |
1700 If it is already present, just move to it (type \\[dired-do-redisplay] to refresh), | 1743 If it is already present, just move to it (type \\[dired-do-redisplay] to refresh), |
1701 else inserts it at its natural place (as `ls -lR' would have done). | 1744 else inserts it at its natural place (as `ls -lR' would have done). |
1702 With a prefix arg, you may edit the ls switches used for this listing. | 1745 With a prefix arg, you may edit the ls switches used for this listing. |
1703 You can add `R' to the switches to expand the whole tree starting at | 1746 You can add `R' to the switches to expand the whole tree starting at |
1704 this subdirectory. | 1747 this subdirectory. |
1705 This function takes some pains to conform to `ls -lR' output." | 1748 This function takes some pains to conform to `ls -lR' output. |
1749 | |
1750 Dired remembers switches specified with a prefix arg, so that reverting | |
1751 the buffer will not reset them. However, using `dired-undo' to re-insert | |
1752 or delete subdirectories can bypass this machinery. Hence, you sometimes | |
1753 may have to reset some subdirectory switches after a `dired-undo'. | |
1754 You can reset all subdirectory switches to the default using | |
1755 \\<dired-mode-map>\\[dired-reset-subdir-switches]. | |
1756 See Info node `(emacs-xtra)Subdir switches' for more details." | |
1706 (interactive | 1757 (interactive |
1707 (list (dired-get-filename) | 1758 (list (dired-get-filename) |
1708 (if current-prefix-arg | 1759 (if current-prefix-arg |
1709 (read-string "Switches for listing: " dired-actual-switches)))) | 1760 (read-string "Switches for listing: " |
1761 (or dired-subdir-switches dired-actual-switches))))) | |
1710 (let ((opoint (point))) | 1762 (let ((opoint (point))) |
1711 ;; We don't need a marker for opoint as the subdir is always | 1763 ;; We don't need a marker for opoint as the subdir is always |
1712 ;; inserted *after* opoint. | 1764 ;; inserted *after* opoint. |
1713 (setq dirname (file-name-as-directory dirname)) | 1765 (setq dirname (file-name-as-directory dirname)) |
1714 (or (and (not switches) | 1766 (or (and (not switches) |
1731 ;; Prospero where dired-ls does the right thing, but | 1783 ;; Prospero where dired-ls does the right thing, but |
1732 ;; file-directory-p has not been redefined. | 1784 ;; file-directory-p has not been redefined. |
1733 (interactive | 1785 (interactive |
1734 (list (dired-get-filename) | 1786 (list (dired-get-filename) |
1735 (if current-prefix-arg | 1787 (if current-prefix-arg |
1736 (read-string "Switches for listing: " dired-actual-switches)))) | 1788 (read-string "Switches for listing: " |
1789 (or dired-subdir-switches dired-actual-switches))))) | |
1737 (setq dirname (file-name-as-directory (expand-file-name dirname))) | 1790 (setq dirname (file-name-as-directory (expand-file-name dirname))) |
1738 (dired-insert-subdir-validate dirname switches) | |
1739 (or no-error-if-not-dir-p | 1791 (or no-error-if-not-dir-p |
1740 (file-directory-p dirname) | 1792 (file-directory-p dirname) |
1741 (error "Attempt to insert a non-directory: %s" dirname)) | 1793 (error "Attempt to insert a non-directory: %s" dirname)) |
1742 (let ((elt (assoc dirname dired-subdir-alist)) | 1794 (let ((elt (assoc dirname dired-subdir-alist)) |
1743 switches-have-R mark-alist case-fold-search buffer-read-only) | 1795 (cons (assoc-string dirname dired-switches-alist)) |
1796 (modflag (buffer-modified-p)) | |
1797 (old-switches switches) | |
1798 switches-have-R mark-alist case-fold-search buffer-read-only) | |
1799 (and (not switches) cons (setq switches (cdr cons))) | |
1800 (dired-insert-subdir-validate dirname switches) | |
1744 ;; case-fold-search is nil now, so we can test for capital `R': | 1801 ;; case-fold-search is nil now, so we can test for capital `R': |
1745 (if (setq switches-have-R (and switches (string-match "R" switches))) | 1802 (if (setq switches-have-R (and switches (string-match "R" switches))) |
1746 ;; avoid duplicated subdirs | 1803 ;; avoid duplicated subdirs |
1747 (setq mark-alist (dired-kill-tree dirname t))) | 1804 (setq mark-alist (dired-kill-tree dirname t))) |
1748 (if elt | 1805 (if elt |
1749 ;; If subdir is already present, remove it and remember its marks | 1806 ;; If subdir is already present, remove it and remember its marks |
1750 (setq mark-alist (nconc (dired-insert-subdir-del elt) mark-alist)) | 1807 (setq mark-alist (nconc (dired-insert-subdir-del elt) mark-alist)) |
1751 (dired-insert-subdir-newpos dirname)) ; else compute new position | 1808 (dired-insert-subdir-newpos dirname)) ; else compute new position |
1752 (dired-insert-subdir-doupdate | 1809 (dired-insert-subdir-doupdate |
1753 dirname elt (dired-insert-subdir-doinsert dirname switches)) | 1810 dirname elt (dired-insert-subdir-doinsert dirname switches)) |
1754 (if switches-have-R (dired-build-subdir-alist switches)) | 1811 (when old-switches |
1812 (if cons | |
1813 (setcdr cons switches) | |
1814 (push (cons dirname switches) dired-switches-alist))) | |
1815 (when switches-have-R | |
1816 (dired-build-subdir-alist switches) | |
1817 (setq switches (dired-replace-in-string "R" "" switches)) | |
1818 (dolist (cur-ass dired-subdir-alist) | |
1819 (let ((cur-dir (car cur-ass))) | |
1820 (and (dired-in-this-tree cur-dir dirname) | |
1821 (let ((cur-cons (assoc-string cur-dir dired-switches-alist))) | |
1822 (if cur-cons | |
1823 (setcdr cur-cons switches) | |
1824 (push (cons cur-dir switches) dired-switches-alist))))))) | |
1755 (dired-initial-position dirname) | 1825 (dired-initial-position dirname) |
1756 (save-excursion (dired-mark-remembered mark-alist)))) | 1826 (save-excursion (dired-mark-remembered mark-alist)) |
1827 (restore-buffer-modified-p modflag))) | |
1757 | 1828 |
1758 ;; This is a separate function for dired-vms. | 1829 ;; This is a separate function for dired-vms. |
1759 (defun dired-insert-subdir-validate (dirname &optional switches) | 1830 (defun dired-insert-subdir-validate (dirname &optional switches) |
1760 ;; Check that it is valid to insert DIRNAME with SWITCHES. | 1831 ;; Check that it is valid to insert DIRNAME with SWITCHES. |
1761 ;; Signal an error if invalid (e.g. user typed `i' on `..'). | 1832 ;; Signal an error if invalid (e.g. user typed `i' on `..'). |
1762 (or (dired-in-this-tree dirname (expand-file-name default-directory)) | 1833 (or (dired-in-this-tree dirname (expand-file-name default-directory)) |
1763 (error "%s: not in this directory tree" dirname)) | 1834 (error "%s: not in this directory tree" dirname)) |
1764 (if switches | 1835 (let ((real-switches (or switches dired-subdir-switches))) |
1836 (when real-switches | |
1765 (let (case-fold-search) | 1837 (let (case-fold-search) |
1766 (mapcar | 1838 (mapcar |
1767 (function | 1839 (function |
1768 (lambda (x) | 1840 (lambda (x) |
1769 (or (eq (null (string-match x switches)) | 1841 (or (eq (null (string-match x real-switches)) |
1770 (null (string-match x dired-actual-switches))) | 1842 (null (string-match x dired-actual-switches))) |
1771 (error "Can't have dirs with and without -%s switches together" | 1843 (error |
1772 x)))) | 1844 "Can't have dirs with and without -%s switches together" x)))) |
1773 ;; all switches that make a difference to dired-get-filename: | 1845 ;; all switches that make a difference to dired-get-filename: |
1774 '("F" "b"))))) | 1846 '("F" "b")))))) |
1775 | 1847 |
1776 (defun dired-alist-add (dir new-marker) | 1848 (defun dired-alist-add (dir new-marker) |
1777 ;; Add new DIR at NEW-MARKER. Sort alist. | 1849 ;; Add new DIR at NEW-MARKER. Sort alist. |
1778 (dired-alist-add-1 dir new-marker) | 1850 (dired-alist-add-1 dir new-marker) |
1779 (dired-alist-sort)) | 1851 (dired-alist-sort)) |
1784 (sort dired-subdir-alist | 1856 (sort dired-subdir-alist |
1785 (function (lambda (elt1 elt2) | 1857 (function (lambda (elt1 elt2) |
1786 (> (dired-get-subdir-min elt1) | 1858 (> (dired-get-subdir-min elt1) |
1787 (dired-get-subdir-min elt2))))))) | 1859 (dired-get-subdir-min elt2))))))) |
1788 | 1860 |
1789 (defun dired-kill-tree (dirname &optional remember-marks) | 1861 (defun dired-kill-tree (dirname &optional remember-marks kill-root) |
1790 "Kill all proper subdirs of DIRNAME, excluding DIRNAME itself. | 1862 "Kill all proper subdirs of DIRNAME, excluding DIRNAME itself. |
1791 With optional arg REMEMBER-MARKS, return an alist of marked files." | 1863 Interactively, you can kill DIRNAME as well by using a prefix argument. |
1792 (interactive "DKill tree below directory: ") | 1864 In interactive use, the command prompts for DIRNAME. |
1793 (setq dirname (expand-file-name dirname)) | 1865 |
1866 When called from Lisp, if REMEMBER-MARKS is non-nil, return an alist | |
1867 of marked files. If KILL-ROOT is non-nil, kill DIRNAME as well." | |
1868 (interactive "DKill tree below directory: \ni\nP") | |
1869 (setq dirname (file-name-as-directory (expand-file-name dirname))) | |
1794 (let ((s-alist dired-subdir-alist) dir m-alist) | 1870 (let ((s-alist dired-subdir-alist) dir m-alist) |
1795 (while s-alist | 1871 (while s-alist |
1796 (setq dir (car (car s-alist)) | 1872 (setq dir (car (car s-alist)) |
1797 s-alist (cdr s-alist)) | 1873 s-alist (cdr s-alist)) |
1798 (if (and (not (string-equal dir dirname)) | 1874 (and (or kill-root (not (string-equal dir dirname))) |
1799 (dired-in-this-tree dir dirname) | 1875 (dired-in-this-tree dir dirname) |
1800 (dired-goto-subdir dir)) | 1876 (dired-goto-subdir dir) |
1801 (setq m-alist (nconc (dired-kill-subdir remember-marks) m-alist)))) | 1877 (setq m-alist (nconc (dired-kill-subdir remember-marks) m-alist)))) |
1802 m-alist)) | 1878 m-alist)) |
1803 | 1879 |
1804 (defun dired-insert-subdir-newpos (new-dir) | 1880 (defun dired-insert-subdir-newpos (new-dir) |
1805 ;; Find pos for new subdir, according to tree order. | 1881 ;; Find pos for new subdir, according to tree order. |
1806 ;;(goto-char (point-max)) | 1882 ;;(goto-char (point-max)) |
1837 (defun dired-insert-subdir-doinsert (dirname switches) | 1913 (defun dired-insert-subdir-doinsert (dirname switches) |
1838 ;; Insert ls output after point. | 1914 ;; Insert ls output after point. |
1839 ;; Return the boundary of the inserted text (as list of BEG and END). | 1915 ;; Return the boundary of the inserted text (as list of BEG and END). |
1840 (save-excursion | 1916 (save-excursion |
1841 (let ((begin (point))) | 1917 (let ((begin (point))) |
1842 (message "Reading directory %s..." dirname) | |
1843 (let ((dired-actual-switches | 1918 (let ((dired-actual-switches |
1844 (or switches | 1919 (or switches |
1920 dired-subdir-switches | |
1845 (dired-replace-in-string "R" "" dired-actual-switches)))) | 1921 (dired-replace-in-string "R" "" dired-actual-switches)))) |
1846 (if (equal dirname (car (car (last dired-subdir-alist)))) | 1922 (if (equal dirname (car (car (last dired-subdir-alist)))) |
1847 ;; If doing the top level directory of the buffer, | 1923 ;; If doing the top level directory of the buffer, |
1848 ;; redo it as specified in dired-directory. | 1924 ;; redo it as specified in dired-directory. |
1849 (dired-readin-insert) | 1925 (dired-readin-insert) |
1850 (dired-insert-directory dirname dired-actual-switches nil nil t))) | 1926 (dired-insert-directory dirname dired-actual-switches nil nil t))) |
1851 (message "Reading directory %s...done" dirname) | |
1852 (list begin (point))))) | 1927 (list begin (point))))) |
1853 | 1928 |
1854 (defun dired-insert-subdir-doupdate (dirname elt beg-end) | 1929 (defun dired-insert-subdir-doupdate (dirname elt beg-end) |
1855 ;; Point is at the correct subdir alist position for ELT, | 1930 ;; Point is at the correct subdir alist position for ELT, |
1856 ;; BEG-END is the subdir-region (as list of begin and end). | 1931 ;; BEG-END is the subdir-region (as list of begin and end). |
1989 (defun dired-kill-subdir (&optional remember-marks) | 2064 (defun dired-kill-subdir (&optional remember-marks) |
1990 "Remove all lines of current subdirectory. | 2065 "Remove all lines of current subdirectory. |
1991 Lower levels are unaffected." | 2066 Lower levels are unaffected." |
1992 ;; With optional REMEMBER-MARKS, return a mark-alist. | 2067 ;; With optional REMEMBER-MARKS, return a mark-alist. |
1993 (interactive) | 2068 (interactive) |
1994 (let ((beg (dired-subdir-min)) | 2069 (let* ((beg (dired-subdir-min)) |
1995 (end (dired-subdir-max)) | 2070 (end (dired-subdir-max)) |
1996 buffer-read-only cur-dir) | 2071 (modflag (buffer-modified-p)) |
1997 (setq cur-dir (dired-current-directory)) | 2072 (cur-dir (dired-current-directory)) |
2073 (cons (assoc-string cur-dir dired-switches-alist)) | |
2074 buffer-read-only) | |
1998 (if (equal cur-dir default-directory) | 2075 (if (equal cur-dir default-directory) |
1999 (error "Attempt to kill top level directory")) | 2076 (error "Attempt to kill top level directory")) |
2000 (prog1 | 2077 (prog1 |
2001 (if remember-marks (dired-remember-marks beg end)) | 2078 (if remember-marks (dired-remember-marks beg end)) |
2002 (delete-region beg end) | 2079 (delete-region beg end) |
2003 (if (eobp) ; don't leave final blank line | 2080 (if (eobp) ; don't leave final blank line |
2004 (delete-char -1)) | 2081 (delete-char -1)) |
2005 (dired-unsubdir cur-dir)))) | 2082 (dired-unsubdir cur-dir) |
2083 (when cons | |
2084 (setq dired-switches-alist (delete cons dired-switches-alist))) | |
2085 (restore-buffer-modified-p modflag)))) | |
2006 | 2086 |
2007 (defun dired-unsubdir (dir) | 2087 (defun dired-unsubdir (dir) |
2008 ;; Remove DIR from the alist | 2088 ;; Remove DIR from the alist |
2009 (setq dired-subdir-alist | 2089 (setq dired-subdir-alist |
2010 (delq (assoc dir dired-subdir-alist) dired-subdir-alist))) | 2090 (delq (assoc dir dired-subdir-alist) dired-subdir-alist))) |
2059 "Hide or unhide the current subdirectory and move to next directory. | 2139 "Hide or unhide the current subdirectory and move to next directory. |
2060 Optional prefix arg is a repeat factor. | 2140 Optional prefix arg is a repeat factor. |
2061 Use \\[dired-hide-all] to (un)hide all directories." | 2141 Use \\[dired-hide-all] to (un)hide all directories." |
2062 (interactive "p") | 2142 (interactive "p") |
2063 (dired-hide-check) | 2143 (dired-hide-check) |
2064 (while (>= (setq arg (1- arg)) 0) | 2144 (let ((modflag (buffer-modified-p))) |
2065 (let* ((cur-dir (dired-current-directory)) | 2145 (while (>= (setq arg (1- arg)) 0) |
2066 (hidden-p (dired-subdir-hidden-p cur-dir)) | 2146 (let* ((cur-dir (dired-current-directory)) |
2067 (elt (assoc cur-dir dired-subdir-alist)) | 2147 (hidden-p (dired-subdir-hidden-p cur-dir)) |
2068 (end-pos (1- (dired-get-subdir-max elt))) | 2148 (elt (assoc cur-dir dired-subdir-alist)) |
2069 buffer-read-only) | 2149 (end-pos (1- (dired-get-subdir-max elt))) |
2070 ;; keep header line visible, hide rest | 2150 buffer-read-only) |
2071 (goto-char (dired-get-subdir-min elt)) | 2151 ;; keep header line visible, hide rest |
2072 (skip-chars-forward "^\n\r") | 2152 (goto-char (dired-get-subdir-min elt)) |
2073 (if hidden-p | 2153 (skip-chars-forward "^\n\r") |
2074 (subst-char-in-region (point) end-pos ?\r ?\n) | 2154 (if hidden-p |
2075 (subst-char-in-region (point) end-pos ?\n ?\r))) | 2155 (subst-char-in-region (point) end-pos ?\r ?\n) |
2076 (dired-next-subdir 1 t))) | 2156 (subst-char-in-region (point) end-pos ?\n ?\r))) |
2157 (dired-next-subdir 1 t)) | |
2158 (restore-buffer-modified-p modflag))) | |
2077 | 2159 |
2078 ;;;###autoload | 2160 ;;;###autoload |
2079 (defun dired-hide-all (arg) | 2161 (defun dired-hide-all (arg) |
2080 "Hide all subdirectories, leaving only their header lines. | 2162 "Hide all subdirectories, leaving only their header lines. |
2081 If there is already something hidden, make everything visible again. | 2163 If there is already something hidden, make everything visible again. |
2082 Use \\[dired-hide-subdir] to (un)hide a particular subdirectory." | 2164 Use \\[dired-hide-subdir] to (un)hide a particular subdirectory." |
2083 (interactive "P") | 2165 (interactive "P") |
2084 (dired-hide-check) | 2166 (dired-hide-check) |
2085 (let (buffer-read-only) | 2167 (let ((modflag (buffer-modified-p)) |
2168 buffer-read-only) | |
2086 (if (save-excursion | 2169 (if (save-excursion |
2087 (goto-char (point-min)) | 2170 (goto-char (point-min)) |
2088 (search-forward "\r" nil t)) | 2171 (search-forward "\r" nil t)) |
2089 ;; unhide - bombs on \r in filenames | 2172 ;; unhide - bombs on \r in filenames |
2090 (subst-char-in-region (point-min) (point-max) ?\r ?\n) | 2173 (subst-char-in-region (point-min) (point-max) ?\r ?\n) |
2091 ;; hide | 2174 ;; hide |
2092 (let ((pos (point-max)) ; pos of end of last directory | 2175 (let ((pos (point-max)) ; pos of end of last directory |
2093 (alist dired-subdir-alist)) | 2176 (alist dired-subdir-alist)) |
2094 (while alist ; while there are dirs before pos | 2177 (while alist ; while there are dirs before pos |
2095 (subst-char-in-region (dired-get-subdir-min (car alist)) ; pos of prev dir | 2178 (subst-char-in-region (dired-get-subdir-min (car alist)) ; pos of prev dir |
2096 (save-excursion | 2179 (save-excursion |
2097 (goto-char pos) ; current dir | 2180 (goto-char pos) ; current dir |
2098 ;; we're somewhere on current dir's line | 2181 ;; we're somewhere on current dir's line |
2099 (forward-line -1) | 2182 (forward-line -1) |
2100 (point)) | 2183 (point)) |
2101 ?\n ?\r) | 2184 ?\n ?\r) |
2102 (setq pos (dired-get-subdir-min (car alist))) ; prev dir gets current dir | 2185 (setq pos (dired-get-subdir-min (car alist))) ; prev dir gets current dir |
2103 (setq alist (cdr alist))))))) | 2186 (setq alist (cdr alist))))) |
2187 (restore-buffer-modified-p modflag))) | |
2104 | 2188 |
2105 ;;;###end dired-ins.el | 2189 ;;;###end dired-ins.el |
2106 | 2190 |
2107 | 2191 |
2108 ;; Functions for searching in tags style among marked files. | 2192 ;; Functions for searching in tags style among marked files. |