diff options
| author | Eric S. Raymond | 1993-04-08 16:35:59 +0000 |
|---|---|---|
| committer | Eric S. Raymond | 1993-04-08 16:35:59 +0000 |
| commit | 8d23c16b3e7d77d1eda235ae4acc67d7d667ac1e (patch) | |
| tree | 9e43a9c276a1bf36faec9dd2bfa28c15c0d51341 | |
| parent | 7bc2b98bd80c9ab626df22868fe12acd3f33f4a5 (diff) | |
| download | emacs-8d23c16b3e7d77d1eda235ae4acc67d7d667ac1e.tar.gz emacs-8d23c16b3e7d77d1eda235ae4acc67d7d667ac1e.zip | |
dired-noselect, dired-internal-noselect, dired-insert-directory:
Enhancements to support passing dired a DIRNAME argument consisting
of a directory-name car and a list-of-files cdr. This is needed to
support VC's augmented dired, which wants a filtered file display
that recurses (showing all version-controlled files in subdirectories
as well as the top-level ones).
| -rw-r--r-- | lisp/dired.el | 143 |
1 files changed, 88 insertions, 55 deletions
diff --git a/lisp/dired.el b/lisp/dired.el index b44f8dd2bfd..fe4db3c69e9 100644 --- a/lisp/dired.el +++ b/lisp/dired.el | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | ;; Copyright (C) 1985, 1986, 1992 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1985, 1986, 1992 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>. | 5 | ;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>. |
| 6 | ;; Version: 5.234 | 6 | ;; Version: 6 |
| 7 | 7 | ||
| 8 | ;; This file is part of GNU Emacs. | 8 | ;; This file is part of GNU Emacs. |
| 9 | 9 | ||
| @@ -34,9 +34,6 @@ | |||
| 34 | 34 | ||
| 35 | ;;; Customizable variables | 35 | ;;; Customizable variables |
| 36 | 36 | ||
| 37 | ;;; The funny comments are for autoload.el, to automagically update | ||
| 38 | ;;; loaddefs. | ||
| 39 | |||
| 40 | ;;;###autoload | 37 | ;;;###autoload |
| 41 | (defvar dired-listing-switches "-al" | 38 | (defvar dired-listing-switches "-al" |
| 42 | "*Switches passed to `ls' for dired. MUST contain the `l' option. | 39 | "*Switches passed to `ls' for dired. MUST contain the `l' option. |
| @@ -160,7 +157,8 @@ This is what the `do' commands look for and what the `mark' commands store.") | |||
| 160 | 157 | ||
| 161 | (defvar dired-directory nil | 158 | (defvar dired-directory nil |
| 162 | "The directory name or shell wildcard that was used as argument to `ls'. | 159 | "The directory name or shell wildcard that was used as argument to `ls'. |
| 163 | Local to each dired buffer.") | 160 | Local to each dired buffer. May be a list, in which case the car is the |
| 161 | directory name and the cdr is the actual files to list.") | ||
| 164 | 162 | ||
| 165 | (defvar dired-actual-switches nil | 163 | (defvar dired-actual-switches nil |
| 166 | "The value of `dired-listing-switches' used to make this buffer's text.") | 164 | "The value of `dired-listing-switches' used to make this buffer's text.") |
| @@ -327,11 +325,13 @@ Optional second argument ARG forces to use other files. If ARG is an | |||
| 327 | Optional second argument SWITCHES specifies the `ls' options used. | 325 | Optional second argument SWITCHES specifies the `ls' options used. |
| 328 | \(Interactively, use a prefix argument to be able to specify SWITCHES.) | 326 | \(Interactively, use a prefix argument to be able to specify SWITCHES.) |
| 329 | Dired displays a list of files in DIRNAME (which may also have | 327 | Dired displays a list of files in DIRNAME (which may also have |
| 330 | shell wildcards appended to select certain files). | 328 | shell wildcards appended to select certain files). If DIRNAME is a cons, |
| 329 | its first element is taken as the directory name and the resr as an explicit | ||
| 330 | list of files to make directory entries for. | ||
| 331 | \\<dired-mode-map>\ | 331 | \\<dired-mode-map>\ |
| 332 | You can move around in it with the usual commands. | 332 | You can move around in it with the usual commands. |
| 333 | You can flag files for deletion with \\[dired-flag-file-deletion] and then delete them by | 333 | You can flag files for deletion with \\[dired-flag-file-deletion] and then |
| 334 | typing \\[dired-do-flagged-delete]. | 334 | delete them by typing \\[dired-do-flagged-delete]. |
| 335 | Type \\[describe-mode] after entering dired for more info. | 335 | Type \\[describe-mode] after entering dired for more info. |
| 336 | 336 | ||
| 337 | If DIRNAME is already in a dired buffer, that buffer is used without refresh." | 337 | If DIRNAME is already in a dired buffer, that buffer is used without refresh." |
| @@ -347,18 +347,25 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh." | |||
| 347 | (switch-to-buffer-other-window (dired-noselect dirname switches))) | 347 | (switch-to-buffer-other-window (dired-noselect dirname switches))) |
| 348 | 348 | ||
| 349 | ;;;###autoload | 349 | ;;;###autoload |
| 350 | (defun dired-noselect (dirname &optional switches) | 350 | (defun dired-noselect (dir-or-list &optional switches) |
| 351 | "Like `dired' but returns the dired buffer as value, does not select it." | 351 | "Like `dired' but returns the dired buffer as value, does not select it." |
| 352 | (or dirname (setq dirname default-directory)) | 352 | (or dir-or-list (setq dir-or-list default-directory)) |
| 353 | ;; This loses the distinction between "/foo/*/" and "/foo/*" that | 353 | ;; This loses the distinction between "/foo/*/" and "/foo/*" that |
| 354 | ;; some shells make: | 354 | ;; some shells make: |
| 355 | (setq dirname (expand-file-name (directory-file-name dirname))) | 355 | (let (dirname) |
| 356 | (if (file-directory-p dirname) | 356 | (if (consp dir-or-list) |
| 357 | (setq dirname (file-name-as-directory dirname))) | 357 | (setq dirname (car dir-or-list)) |
| 358 | (dired-internal-noselect dirname switches)) | 358 | (setq dirname dir-or-list)) |
| 359 | (setq dirname (expand-file-name (directory-file-name dirname))) | ||
| 360 | (if (file-directory-p dirname) | ||
| 361 | (setq dirname (file-name-as-directory dirname))) | ||
| 362 | (if (consp dir-or-list) | ||
| 363 | (setq dir-or-list (cons dirname (cdr dir-or-list))) | ||
| 364 | (setq dir-or-list dirname)) | ||
| 365 | (dired-internal-noselect dir-or-list switches))) | ||
| 359 | 366 | ||
| 360 | ;; Separate function from dired-noselect for the sake of dired-vms.el. | 367 | ;; Separate function from dired-noselect for the sake of dired-vms.el. |
| 361 | (defun dired-internal-noselect (dirname &optional switches) | 368 | (defun dired-internal-noselect (dir-or-list &optional switches) |
| 362 | ;; If there is an existing dired buffer for DIRNAME, just leave | 369 | ;; If there is an existing dired buffer for DIRNAME, just leave |
| 363 | ;; buffer as it is (don't even call dired-revert). | 370 | ;; buffer as it is (don't even call dired-revert). |
| 364 | ;; This saves time especially for deep trees or with ange-ftp. | 371 | ;; This saves time especially for deep trees or with ange-ftp. |
| @@ -368,7 +375,8 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh." | |||
| 368 | ;; revert the buffer. | 375 | ;; revert the buffer. |
| 369 | ;; A pity we can't possibly do "Directory has changed - refresh? " | 376 | ;; A pity we can't possibly do "Directory has changed - refresh? " |
| 370 | ;; like find-file does. | 377 | ;; like find-file does. |
| 371 | (let* ((buffer (dired-find-buffer-nocreate dirname)) | 378 | (let* ((dirname (if (consp dir-or-list) (car dir-or-list) dir-or-list)) |
| 379 | (buffer (dired-find-buffer-nocreate dir-or-list)) | ||
| 372 | ;; note that buffer already is in dired-mode, if found | 380 | ;; note that buffer already is in dired-mode, if found |
| 373 | (new-buffer-p (not buffer)) | 381 | (new-buffer-p (not buffer)) |
| 374 | (old-buf (current-buffer))) | 382 | (old-buf (current-buffer))) |
| @@ -392,7 +400,7 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh." | |||
| 392 | ;; (buffer-local), so we can call dired-readin: | 400 | ;; (buffer-local), so we can call dired-readin: |
| 393 | (let ((failed t)) | 401 | (let ((failed t)) |
| 394 | (unwind-protect | 402 | (unwind-protect |
| 395 | (progn (dired-readin dirname buffer) | 403 | (progn (dired-readin dir-or-list buffer) |
| 396 | (setq failed nil)) | 404 | (setq failed nil)) |
| 397 | ;; dired-readin can fail if parent directories are inaccessible. | 405 | ;; dired-readin can fail if parent directories are inaccessible. |
| 398 | ;; Don't leave an empty buffer around in that case. | 406 | ;; Don't leave an empty buffer around in that case. |
| @@ -427,7 +435,7 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh." | |||
| 427 | ;; dired-readin differs from dired-insert-subdir in that it accepts | 435 | ;; dired-readin differs from dired-insert-subdir in that it accepts |
| 428 | ;; wildcards, erases the buffer, and builds the subdir-alist anew | 436 | ;; wildcards, erases the buffer, and builds the subdir-alist anew |
| 429 | ;; (including making it buffer-local and clearing it first). | 437 | ;; (including making it buffer-local and clearing it first). |
| 430 | (defun dired-readin (dirname buffer) | 438 | (defun dired-readin (dir-or-list buffer) |
| 431 | ;; default-directory and dired-actual-switches must be buffer-local | 439 | ;; default-directory and dired-actual-switches must be buffer-local |
| 432 | ;; and initialized by now. | 440 | ;; and initialized by now. |
| 433 | ;; Thus we can test (equal default-directory dirname) instead of | 441 | ;; Thus we can test (equal default-directory dirname) instead of |
| @@ -435,44 +443,67 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh." | |||
| 435 | ;; Also, we can run this hook which may want to modify the switches | 443 | ;; Also, we can run this hook which may want to modify the switches |
| 436 | ;; based on default-directory, e.g. with ange-ftp to a SysV host | 444 | ;; based on default-directory, e.g. with ange-ftp to a SysV host |
| 437 | ;; where ls won't understand -Al switches. | 445 | ;; where ls won't understand -Al switches. |
| 438 | (setq dirname (expand-file-name dirname)) | 446 | (let (dirname) |
| 439 | (run-hooks 'dired-before-readin-hook) | 447 | (if (consp dir-or-list) |
| 440 | (save-excursion | 448 | (setq dirname (car dir-or-list)) |
| 441 | (message "Reading directory %s..." dirname) | 449 | (setq dirname dir-or-list)) |
| 442 | (set-buffer buffer) | 450 | (setq dirname (expand-file-name dirname)) |
| 443 | (let (buffer-read-only (failed t)) | 451 | (if (consp dir-or-list) |
| 444 | (widen) | 452 | (setq dir-or-list (cons dirname (cdr dir-or-list)))) |
| 445 | (erase-buffer) | 453 | (run-hooks 'dired-before-readin-hook) |
| 446 | (dired-readin-insert dirname) | 454 | (save-excursion |
| 447 | (indent-rigidly (point-min) (point-max) 2) | 455 | (message "Reading directory %s..." dirname) |
| 448 | ;; We need this to make the root dir have a header line as all | 456 | (set-buffer buffer) |
| 449 | ;; other subdirs have: | 457 | (let (buffer-read-only (failed t)) |
| 450 | (goto-char (point-min)) | 458 | (widen) |
| 451 | (dired-insert-headerline default-directory) | 459 | (erase-buffer) |
| 452 | ;; can't run dired-after-readin-hook here, it may depend on the subdir | 460 | (dired-readin-insert dir-or-list) |
| 453 | ;; alist to be OK. | 461 | (indent-rigidly (point-min) (point-max) 2) |
| 454 | ) | 462 | ;; We need this to make the root dir have a header line as all |
| 455 | (message "Reading directory %s...done" dirname) | 463 | ;; other subdirs have: |
| 456 | (set-buffer-modified-p nil) | 464 | (goto-char (point-min)) |
| 457 | ;; Must first make alist buffer local and set it to nil because | 465 | (dired-insert-headerline default-directory) |
| 458 | ;; dired-build-subdir-alist will call dired-clear-alist first | 466 | ;; can't run dired-after-readin-hook here, it may depend on the subdir |
| 459 | (set (make-local-variable 'dired-subdir-alist) nil) | 467 | ;; alist to be OK. |
| 460 | (dired-build-subdir-alist))) | 468 | ) |
| 469 | (message "Reading directory %s...done" dirname) | ||
| 470 | (set-buffer-modified-p nil) | ||
| 471 | ;; Must first make alist buffer local and set it to nil because | ||
| 472 | ;; dired-build-subdir-alist will call dired-clear-alist first | ||
| 473 | (set (make-local-variable 'dired-subdir-alist) nil) | ||
| 474 | (dired-build-subdir-alist)))) | ||
| 461 | 475 | ||
| 462 | ;; Subroutines of dired-readin | 476 | ;; Subroutines of dired-readin |
| 463 | 477 | ||
| 464 | (defun dired-readin-insert (dirname) | 478 | (defun dired-readin-insert (dir-or-list) |
| 465 | ;; Just insert listing for DIRNAME, assuming a clean buffer. | 479 | ;; Just insert listing for the passed-in directory or |
| 466 | (if (equal default-directory dirname);; i.e., (file-directory-p dirname) | 480 | ;; directory-and-file list, assuming a clean buffer. |
| 467 | (insert-directory dirname dired-actual-switches nil t) | 481 | (let (dirname) |
| 468 | (if (not (file-readable-p | 482 | (if (consp dir-or-list) |
| 469 | (directory-file-name (file-name-directory dirname)))) | 483 | (setq dirname (car dir-or-list)) |
| 470 | (error "Directory %s inaccessible or nonexistent" dirname) | 484 | (setq dirname dir-or-list)) |
| 471 | ;; else assume it contains wildcards: | 485 | (if (equal default-directory dirname) ;; i.e., (file-directory-p dirname) |
| 472 | (insert-directory dirname dired-actual-switches t) | 486 | (dired-insert-directory dir-or-list dired-actual-switches nil t) |
| 473 | (save-excursion;; insert wildcard instead of total line: | 487 | (if (not (file-readable-p |
| 474 | (goto-char (point-min)) | 488 | (directory-file-name (file-name-directory dirname)))) |
| 475 | (insert "wildcard " (file-name-nondirectory dirname) "\n"))))) | 489 | (error "Directory %s inaccessible or nonexistent" dirname) |
| 490 | ;; else assume it contains wildcards: | ||
| 491 | (dired-insert-directory dir-or-list dired-actual-switches t) | ||
| 492 | (save-excursion ;; insert wildcard instead of total line: | ||
| 493 | (goto-char (point-min)) | ||
| 494 | (insert "wildcard " (file-name-nondirectory dirname) "\n")))))) | ||
| 495 | |||
| 496 | (defun dired-insert-directory (dir-or-list switches &optional wildcard full-p) | ||
| 497 | ;; Do the right thing whether dir-or-list is atomic or not. If it is, | ||
| 498 | ;; inset all files listed in the cdr (the car is the passed-in directory | ||
| 499 | ;; list. | ||
| 500 | (if (consp dir-or-list) | ||
| 501 | (progn | ||
| 502 | (mapcar | ||
| 503 | (function (lambda (x) (insert-directory x switches wildcard full-p))) | ||
| 504 | (cdr dir-or-list))) | ||
| 505 | (insert-directory dir-or-list switches wildcard full-p)) | ||
| 506 | (setq dired-directory dir-or-list)) | ||
| 476 | 507 | ||
| 477 | (defun dired-insert-headerline (dir);; also used by dired-insert-subdir | 508 | (defun dired-insert-headerline (dir);; also used by dired-insert-subdir |
| 478 | ;; Insert DIR's headerline with no trailing slash, exactly like ls | 509 | ;; Insert DIR's headerline with no trailing slash, exactly like ls |
| @@ -500,7 +531,8 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh." | |||
| 500 | (setq mark-alist;; only after dired-remember-hidden since this unhides: | 531 | (setq mark-alist;; only after dired-remember-hidden since this unhides: |
| 501 | (dired-remember-marks (point-min) (point-max))) | 532 | (dired-remember-marks (point-min) (point-max))) |
| 502 | ;; treat top level dir extra (it may contain wildcards) | 533 | ;; treat top level dir extra (it may contain wildcards) |
| 503 | (dired-uncache dired-directory) | 534 | (dired-uncache |
| 535 | (if (consp dired-directory) (car dired-directory) dired-directory)) | ||
| 504 | (dired-readin dired-directory (current-buffer)) | 536 | (dired-readin dired-directory (current-buffer)) |
| 505 | (let ((dired-after-readin-hook nil)) | 537 | (let ((dired-after-readin-hook nil)) |
| 506 | ;; don't run that hook for each subdir... | 538 | ;; don't run that hook for each subdir... |
| @@ -853,7 +885,8 @@ Creates a buffer if necessary." | |||
| 853 | (and (cdr dired-subdir-alist) | 885 | (and (cdr dired-subdir-alist) |
| 854 | (dired-goto-subdir up)) | 886 | (dired-goto-subdir up)) |
| 855 | (progn | 887 | (progn |
| 856 | (dired up) | 888 | (dired |
| 889 | up) | ||
| 857 | (dired-goto-file dir))))) | 890 | (dired-goto-file dir))))) |
| 858 | 891 | ||
| 859 | (defun dired-find-file () | 892 | (defun dired-find-file () |