annotate lisp/dired/dired-nstd.el @ 83:ba3ba6e17456

Added tag r20-0b91 for changeset 6a378aca36af
author cvs
date Mon, 13 Aug 2007 09:07:39 +0200
parents 376386a54a3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; -*- Mode:Emacs-Lisp -*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;; Jamie Zawinski <jwz@lucid.com> 7-may-91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;; This makes dired buffers which display multiple directories display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;; them in a tree rather than in an "ls -R"-like format. Which, as every
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;; Lisp Machine hacker knows, is the Right Thing!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; -rw-r--r-- 1 jwz 31543 Mar 26 03:20 reportmail.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;; -rw-r--r-- 1 jwz 14919 Mar 26 03:20 reportmail.elc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;; drwxr-xr-x 2 jwz 1024 Apr 5 13:08 sk-dired/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;; -rw-r--r-- 1 jwz 3258 Mar 6 06:33 ange-ftp-dired.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;; -rw-r--r-- 1 jwz 1750 Mar 12 15:04 ange-ftp-dired.elc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; -rw-r--r-- 1 jwz 3151 Mar 29 00:01 symbol-syntax.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; -rw-r--r-- 1 jwz 1504 Mar 29 01:01 symbol-syntax.elc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;; This program is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; A copy of the GNU General Public License can be obtained from this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; program's author (send electronic mail to the above address) or from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (defconst dired-subdir-alist nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 "Association list of subdirectories and their buffer positions:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ((LASTDIR STARTMARKER ENDMARKER NESTING-DEPTH)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (DEFAULT-DIRECTORY POINTMIN POINTMAX 0)).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;The markers point right at the end of the line, so that the cursor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;looks at either \\n or \\r, the latter for a hidden subdir.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; The directories must be file-name-as-directory, of course.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (defun dired-simple-subdir-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; Build and return `dired-subdir-alist' assuming just the top level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; directory to be inserted. Don't parse the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (set (make-local-variable 'dired-subdir-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (list (list default-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (point-min-marker) (point-max-marker) 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (define-key dired-mode-map "i" 'dired-insert-subdir-inline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (define-key dired-mode-map "j" 'dired-maybe-insert-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;; ## these should be macros when this is integrated with the distribution.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (defun dired-get-subdir-min (elt) (nth 1 elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (defun dired-get-subdir-max (elt) (nth 2 elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (defun dired-subdir-min ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (let ((d (dired-current-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (if (setq c (assoc d dired-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (marker-position (dired-get-subdir-min c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (error "not in a subdir!"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (defun dired-subdir-max ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (let ((d (dired-current-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (if (setq c (assoc d dired-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (marker-position (dired-get-subdir-max c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (defun dired-clear-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (while dired-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (let ((elt (car dired-subdir-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (set-marker (nth 1 elt) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (set-marker (nth 2 elt) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (setq dired-subdir-alist (cdr dired-subdir-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (defun dired-unsubdir (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;; Remove DIR from the alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;; also remove any directories which are inside of it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (let* ((elt (assoc dir dired-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (min (nth 1 elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (max (nth 2 elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 other-elt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (rest dired-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (while rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (setq other-elt (car rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (if (and (<= min (nth 1 other-elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (>= max (nth 2 other-elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (setq dired-subdir-alist (delq other-elt dired-subdir-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (setq rest (cdr rest)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;;; this needs to be changed to grok indentation. Or not. -jwz
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;;; Probably not, as dired-revert either starts with one dir and inserting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;;; then enlarges the alist automatically, or it inserts all dirs with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;;; one "ls -lR". -sk
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (defun dired-build-subdir-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 "Build dired-subdir-alist by parsing the buffer and return it's new value."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (dired-clear-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (let ((count 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (setq dired-subdir-alist nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (while (re-search-forward dired-subdir-regexp nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (setq count (1+ count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (dired-alist-add (buffer-substring (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;; Put subdir boundary between lines:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;; isn't this wrong when already more than one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; subdir is present with -lR?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;; maybe. I don't know. But we can't call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;; dired-subdir-max here, it loops. -jwz.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (point-max-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (message "%d" count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (message "%d director%s." count (if (= 1 count) "y" "ies"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;; return new alist:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 dired-subdir-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (defun dired-alist-add (dir start-marker end-marker indentation-depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ;; indentation-depth may be 0 for more than one directory -- this happens
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;; when "ls -R" format is used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;; ## debugging code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (or start-marker (error "start marker nil"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (or end-marker (error "end marker nil"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;;(or (/= start-marker end-marker) (error "markers are the same"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (let ((old (assoc dir dired-subdir-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (setq dired-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (cons (list (dired-normalize-subdir dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 start-marker end-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (or indentation-depth 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (delq old dired-subdir-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (dired-alist-sort)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;; can't see at the moment how this could work with a mixed format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;; alist -sk
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (defun dired-current-directory (&optional relative)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 "Get the subdirectory to which this line belongs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 This returns a string with trailing slash, like default-directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 Optional argument means return a name relative to default-directory."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (let (elt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (alist (or dired-subdir-alist (dired-build-subdir-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 best-so-far)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (setq elt (car alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (if (or (< here (nth 1 elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (> here (nth 2 elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 nil ;; the subdir is disjoint
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;; otherwise it's on the path between the current file and the root.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;; decide if it's deeper than what we've already got.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (if (or (null best-so-far)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (< (- (nth 2 elt) (nth 1 elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (- (nth 2 best-so-far) (nth 1 best-so-far))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (setq best-so-far elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (setq alist (cdr alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (if best-so-far
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (if relative
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (dired-make-relative (car best-so-far) default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (car best-so-far))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (dired-build-subdir-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (dired-current-directory relative)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (defun dired-insert-subdir-del (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 ;; Erase an already present subdir (given by ELEMENT) from buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ;; Move to that buffer position. Return a mark-alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (let ((begin-marker (dired-get-subdir-min element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (end-marker (dired-get-subdir-max element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (goto-char end-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (or (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (not (= 0 (nth 3 element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;; for -R style, want a separating newline _between_ subdirs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (if (= 0 (nth 3 element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (insert "\n\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (dired-remember-marks begin-marker (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (delete-region begin-marker (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (defun dired-insert-subdir-doupdate (dirname elt beg-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (let ((beg (nth 0 beg-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (end (nth 1 beg-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (indent (or (nth 2 beg-end) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (if (and elt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (not (eq indent (nth 2 elt))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (setq elt nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 dired-subdir-alist (delq elt dired-subdir-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (if elt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (let ((old-start (nth 1 elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (old-end (nth 2 elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (set-marker old-start beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (set-marker old-end end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (setcar (nthcdr 3 elt) indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (dired-alist-add dirname
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (set-marker (make-marker) beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (set-marker (make-marker) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 indent))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (defun dired-insert-subdir-inline (dirname &optional switches no-error-if-not-dir-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 "Insert this subdirectory into the same dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 If it is already present, overwrites previous entry,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 else inserts it, indented, within its parent's listing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 With a prefix arg, you may edit the ls switches used for this listing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 This command ignores the `R' switch."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ;; NO-ERROR-IF-NOT-DIR-P needed for special filesystems like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ;; Prospero where dired-ls does the right thing, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ;; file-directory-p has not been redefined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (list (dired-get-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (read-string "Switches for listing: " dired-actual-switches))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (setq dirname (file-name-as-directory (expand-file-name dirname)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (if (let ((case-fold-search nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (string-match "R" (or switches "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (setq switches (concat (substring switches 0 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (substring switches (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (dired-make-relative dirname default-directory) ; error on failure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (or no-error-if-not-dir-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (file-directory-p dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (error "Attempt to insert a non-directory: %s" dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (let ((elt (assoc dirname dired-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (parentdir (file-name-directory (directory-file-name dirname)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 beg end old-start old-end new-start new-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 mark-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 tail-adjascents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 buffer-read-only case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (if elt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 ;; subdir is already present - must first erase it from buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;; if it's already in -R format, pretend it wasn't there, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ;; remember its file marks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (setq mark-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (append (dired-insert-subdir-del elt) mark-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (setq dired-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (delq elt dired-subdir-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ;;(dired-insert-subdir-newpos) ;##
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (dired-goto-file dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (dired-insert-subdir-doupdate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 dirname elt (dired-insert-subdir-inline-doinsert dirname switches parentdir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (dired-initial-position dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (save-excursion (dired-mark-remembered mark-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (dired-nuke-extra-newlines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (defun dired-insert-subdir (dirname &optional switches no-error-if-not-dir-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 "Insert this subdirectory into the same dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 If it is already present, overwrites previous entry,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 else appends at end of buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 With a prefix arg, you may edit the ls switches used for this listing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 You can add `R' to the switches to expand the whole tree starting at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 this subdirectory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 This function takes some pains to conform to ls -lR output."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 ;; NO-ERROR-IF-NOT-DIR-P needed for special filesystems like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ;; Prospero where dired-ls does the right thing, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; file-directory-p has not been redefined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (list (dired-get-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (read-string "Switches for listing: " dired-actual-switches))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (setq dirname (file-name-as-directory (expand-file-name dirname)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (dired-make-relative dirname default-directory) ; error on failure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (or no-error-if-not-dir-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (file-directory-p dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (error "Attempt to insert a non-directory: %s" dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (let ((elt (assoc dirname dired-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (switches-have-R (and switches (string-match "R" switches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 mark-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 buffer-read-only case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (if switches-have-R ; avoid double subdirs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (setq mark-alist (dired-kill-tree dirname t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (let ((was-nested (and (nth 3 elt) (not (eq 0 (nth 3 elt))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (if elt ; subdir is already present
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (setq mark-alist ; remove it, remembering marks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (append (dired-insert-subdir-del elt) mark-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (if (or was-nested (null elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (dired-insert-subdir-newpos dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (if was-nested (setcar (nthcdr 3 elt) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (dired-insert-subdir-doupdate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 dirname elt (dired-insert-subdir-doinsert dirname switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (if switches-have-R (dired-build-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (dired-initial-position dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (save-excursion (dired-mark-remembered mark-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (dired-nuke-extra-newlines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (defun dired-nuke-extra-newlines ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (let ((buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (while (re-search-forward "\n\n\n+" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (goto-char (+ 2 (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (delete-region (point) (match-end 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (defun dired-insert-subdir-newpos (new-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ;; Find pos for new subdir, according to tree order.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ;;(goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (let ((alist dired-subdir-alist) elt dir pos new-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (setq elt (car alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 alist (cdr alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 dir (car elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 pos (dired-get-subdir-min elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (if (and (= 0 (nth 3 elt)) ; nested ones don't count.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (dired-tree-lessp dir new-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 ;; Insert NEW-DIR after DIR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (setq new-pos (dired-get-subdir-max elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 alist nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (goto-char new-pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 ;; want a separating newline between subdirs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (insert "\n\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (defvar dired-no-inline-headerlines t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 "*set this to t to suppress the directory header and `total' line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (defun dired-insert-subdir-inline-doinsert (dirname switches parentdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 ;; Insert ls output after point and put point on the correct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 ;; position for the subdir alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 ;; returns the dired-subdir-alist entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (let ((begin (point)) end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 tail-adjascents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (message "Reading directory %s..." dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (dired-ls dirname
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (or switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (dired-replace-in-string "R" "" dired-actual-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (message "Reading directory %s...done" dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (setq indent (1+ (nth 3 (assoc parentdir dired-subdir-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (goto-char begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (or dired-no-inline-headerlines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (dired-insert-headerline dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (save-excursion (delete-horizontal-space)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (goto-char begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (delete-horizontal-space))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (if (and dired-no-inline-headerlines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (looking-at "^ *total [0-9]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (delete-region (point) (progn (forward-line 1) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (setq begin (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 ;; If there are other directories whose end-point is right here,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 ;; then they are the directories such that X is the last directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 ;; in the listing of Y. We need to grab them and update their
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 ;; last-point to be the same as ours will be (goofy margin-case).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (let ((rest dired-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (while rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (if (= (point) (nth 2 (car rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (setq tail-adjascents (cons (car rest) tail-adjascents)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (setq rest (cdr rest))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (let ((indent-tabs-mode nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (indent-rigidly begin (point) (* 2 (1+ indent))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (setq end (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (goto-char begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (while tail-adjascents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (set-marker (nth 2 (car tail-adjascents)) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (setq tail-adjascents (cdr tail-adjascents)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (if dired-after-readin-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (narrow-to-region begin end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (run-hooks 'dired-after-readin-hook)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 ;; call dired-insert-headerline afterwards, as under VMS dired-ls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 ;; does insert the headerline itself and the insert function just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 ;; moves point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (setq end (prog1 (marker-position end) (set-marker end nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (goto-char begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (list begin end indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (defun dired-insert-subdir-doinsert (dirname switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 ;; Insert ls output after point and put point on the correct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 ;; position for the subdir alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 ;; Return the boundary of the inserted text (as list of BEG and END).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (let ((begin (point)) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (message "Reading directory %s..." dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (dired-ls dirname
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (or switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (dired-replace-in-string "R" "" dired-actual-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (message "Reading directory %s...done" dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (insert "\n\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (setq end (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (indent-rigidly begin (point) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (if dired-after-readin-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (narrow-to-region begin (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (run-hooks 'dired-after-readin-hook)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 ;; call dired-insert-headerline afterwards, as under VMS dired-ls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 ;; does insert the headerline itself and the insert function just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 ;; moves point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (goto-char begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (dired-insert-headerline dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 ;; point is now like in dired-build-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (setq end (prog1 (marker-position end) (set-marker end nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (list begin end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (defun dired-insert-old-subdirs (old-subdir-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 ;; Try to insert all subdirs that were displayed before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (or (string-match "R" dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (let (elt dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (setq old-subdir-alist (sort old-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (function (lambda (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (< (nth 3 x) (nth 3 y))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (while old-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (setq elt (car old-subdir-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 old-subdir-alist (cdr old-subdir-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 dir (car elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (if (= 0 (nth 3 elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (dired-insert-subdir dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (dired-insert-subdir-inline dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (error nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (defun dired-add-entry-do-indentation (marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 ;; two spaces or a marker plus a space, plus nesting indentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 ;; Uses fluid vars `directory', `marker-char' from dired-add-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (insert (if marker-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (if (integerp marker-char) marker-char dired-marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 ?\040)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 ?\040)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (let ((indent (nth 3 (assoc directory dired-subdir-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (insert (make-string (* 2 indent) ?\040))))