Function: dired-maybe-insert-subdir

dired-maybe-insert-subdir is an autoloaded, interactive and byte-compiled function defined in dired-aux.el.gz.

Signature

(dired-maybe-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, just move to it (type M-x dired-do-redisplay (dired-do-redisplay) to refresh),
  else inserts 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.

Dired remembers switches specified with a prefix arg, so that reverting the buffer will not reset them. However, using dired-undo to re-insert or delete subdirectories can bypass this machinery. Hence, you sometimes may have to reset some subdirectory switches after a dired-undo. You can reset all subdirectory switches to the default using M-x dired-reset-subdir-switches (dired-reset-subdir-switches). See Info node (emacs)Subdir switches for more details.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/dired-aux.el.gz
;;; Insert subdirectory

;;;###autoload
(defun dired-maybe-insert-subdir (dirname &optional
					  switches no-error-if-not-dir-p)
  "Insert this subdirectory into the same Dired buffer.
If it is already present, just move to it (type \\[dired-do-redisplay] to refresh),
  else inserts 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.

Dired remembers switches specified with a prefix arg, so that reverting
the buffer will not reset them.  However, using `dired-undo' to re-insert
or delete subdirectories can bypass this machinery.  Hence, you sometimes
may have to reset some subdirectory switches after a `dired-undo'.
You can reset all subdirectory switches to the default using
\\<dired-mode-map>\\[dired-reset-subdir-switches].
See Info node `(emacs)Subdir switches' for more details."
  (interactive
   (list (dired-get-filename)
	 (if current-prefix-arg
	     (read-string "Switches for listing: "
			  (or dired-subdir-switches dired-actual-switches))))
   dired-mode)
  (let ((opoint (point)))
    ;; We don't need a marker for opoint as the subdir is always
    ;; inserted *after* opoint.
    (setq dirname (file-name-as-directory dirname))
    (or (and (not switches)
	     (when (dired-goto-subdir dirname)
	       (unless (dired-subdir-hidden-p dirname)
		 (dired-initial-position dirname))
	       t))
	(dired-insert-subdir dirname switches no-error-if-not-dir-p))
    ;; Push mark so that it's easy to find back.  Do this after the
    ;; insert message so that the user sees the `Mark set' message.
    (push-mark opoint)))