(dired.info)Tree Dired Internals
Next: Dired Mark Internals Prev: Dired Internals Up: Dired Internals
Tree Dired Internals
In Tree Dired, instead of just one directory, all or part of the
directory *tree* starting at the top level directory (the working
directory or `default-directory' of the buffer) may be in a Dired
buffer. Each file line belongs to exactly one of those subdirectories.
After the `ls' program has inserted its output, Dired parses the
buffer once to find out where the subdirectory boundaries are and saves
them in the variable `dired-subdir-alist'. The beginning of the
headerline inserted by `ls' serves as boundary between subdirectories.
Subsequent `i' (`dired-maybe-insert-subdir') commands update this
alist and insert the appropriate headerline. Each retrieval of the
filename on the current line first extracts the basename (assuming a
more or less standard `ls' output format), and then function
`dired-current-directory' looks up the current Dired directory in
`dired-subdir-alist'. The lookup is keyed on buffer position, as each
buffer position is between exactly two subdirectory boundaries. (The
end of the buffer serves as an implicit subdirectory boundary.)
Association list of subdirectories and their buffer positions:
((LASTDIR . LASTMARKER) ... (DEFAULT-DIRECTORY . FIRSTMARKER)).
The markers point right before the beginning of the line, so that
they separate subdirectories adjacent in the buffer. The
directories must be in the form returned by
Value: "^. \\([^ \n\r]+\\)\\(:\\)[\n\r]"
Regexp matching a maybe hidden subdirectory line in `ls -lR'
output. Subexpression 1 is subdirectory proper, no trailing
colon. The match starts at the beginning of the line and ends
after the end of the line (`\n' or `\r'). Subexpression 2 must
end right before the `\n' or `\r'. This is so that Dired can
easily check whether a subdirectory is hidden or not: hidden lines
end with `\r' (`C-m') instead of a newline.
This regexp used to be `"^. \\(/[^\n\r]*\\)\\(:\\)[\n\r]"',
allowing spaces, but disallowing relative filenames (which occur
when browsing ls -lR listing in virtual Dired mode, so I changed
Note that `"^. \\([^\n\r]+\\)\\(:\\)[\n\r]"' (desirable since it
allows both spaces and relative names) will not always work: if
you have a file that ends in a colon, its whole line (including
permission bits, date etc.) would be mistaken for a subdirectory
headerline when parsing `ls -lR' output.
`dired-subdir-regexp' is only relevant for parsing `ls -lR'
output. If Dired inserts subdirectories itself (using
`dired-insert-subdir'), they will always be absolute and there is
no restriction on the format of filenames, e.g., they can contain
automatically generated by info2www