Function: dired-insert-subdir
dired-insert-subdir is an autoloaded, interactive and byte-compiled
function defined in dired-aux.el.gz.
Signature
(dired-insert-subdir DIRNAME &optional SWITCHES NO-ERROR-IF-NOT-DIR-P)
Documentation
Insert this subdirectory into the same Dired buffer.
If it is already present, overwrite the previous entry;
otherwise, insert it at its natural place (as ls -lR would
have done).
With a prefix arg, you may edit the ls switches used for this listing.
You can add R to the switches to expand the whole tree starting at
this subdirectory.
This function takes some pains to conform to ls -lR output.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/dired-aux.el.gz
;;;###autoload
(defun dired-insert-subdir (dirname &optional switches no-error-if-not-dir-p)
"Insert this subdirectory into the same Dired buffer.
If it is already present, overwrite the previous entry;
otherwise, insert it at its natural place (as `ls -lR' would
have done).
With a prefix arg, you may edit the `ls' switches used for this listing.
You can add `R' to the switches to expand the whole tree starting at
this subdirectory.
This function takes some pains to conform to `ls -lR' output."
;; NO-ERROR-IF-NOT-DIR-P needed for special filesystems like
;; Prospero where dired-ls does the right thing, but
;; file-directory-p has not been redefined.
(interactive
(list (dired-get-filename)
(if current-prefix-arg
(read-string "Switches for listing: "
(or dired-subdir-switches dired-actual-switches)))))
(setq dirname (file-name-as-directory (expand-file-name dirname)))
(or no-error-if-not-dir-p
(file-directory-p dirname)
(error "Attempt to insert a non-directory: %s" dirname))
(let ((elt (assoc dirname dired-subdir-alist))
(cons (assoc-string dirname dired-switches-alist))
(modflag (buffer-modified-p))
(old-switches switches)
switches-have-R mark-alist case-fold-search buffer-read-only)
(and (not switches) cons (setq switches (cdr cons)))
(dired-insert-subdir-validate dirname switches)
;; case-fold-search is nil now, so we can test for capital `R':
(if (setq switches-have-R (and switches (string-match-p "R" switches)))
;; avoid duplicated subdirs
(setq mark-alist (dired-kill-tree dirname t)))
(if elt
;; If subdir is already present, remove it and remember its marks
(setq mark-alist (nconc (dired-insert-subdir-del elt) mark-alist))
(dired-insert-subdir-newpos dirname)) ; else compute new position
(dired-insert-subdir-doupdate
dirname elt (dired-insert-subdir-doinsert dirname switches))
(when old-switches
(if cons
(setcdr cons switches)
(push (cons dirname switches) dired-switches-alist)))
(when switches-have-R
(dired-build-subdir-alist switches)
(setq switches (string-replace "R" "" switches))
(dolist (cur-ass dired-subdir-alist)
(let ((cur-dir (car cur-ass)))
(and (dired-in-this-tree-p cur-dir dirname)
(let ((cur-cons (assoc-string cur-dir dired-switches-alist)))
(if cur-cons
(setcdr cur-cons switches)
(push (cons cur-dir switches) dired-switches-alist)))))))
(dired-initial-position dirname)
(save-excursion (dired-mark-remembered mark-alist))
(restore-buffer-modified-p modflag)))