Function: speedbar-update-directory-contents

speedbar-update-directory-contents is a byte-compiled function defined in speedbar.el.gz.

Signature

(speedbar-update-directory-contents)

Documentation

Update the contents of the speedbar buffer based on the current directory.

Source Code

;; Defined in /usr/src/emacs/lisp/speedbar.el.gz
(defun speedbar-update-directory-contents ()
  "Update the contents of the speedbar buffer based on the current directory."
    (let ((cbd (expand-file-name default-directory))
	  cbd-parent
	  (funclst (speedbar-initial-expansion-list))
	  (cache speedbar-full-text-cache)
	  ;; disable stealth during update
	  (speedbar-stealthy-function-list nil)
	  (use-cache nil)
	  (expand-local nil)
	  ;; Because there is a bug I can't find just yet
	  (inhibit-quit nil))
      (set-buffer speedbar-buffer)
      ;; If we are updating contents to where we are, then this is
      ;; really a request to update existing contents, so we must be
      ;; careful with our text cache!
      (if (member cbd speedbar-shown-directories)
	  (progn
	    (setq cache nil)
	    ;; If the current directory is not the last element in the dir
	    ;; list, then we ALSO need to zap the list of expanded directories
	    (if (/= (length (member cbd speedbar-shown-directories)) 1)
		(setq speedbar-shown-directories (list cbd))))

	;; Build cbd-parent, and see if THAT is in the current shown
	;; directories.  First, go through pains to get the parent directory
	(if (and speedbar-smart-directory-expand-flag
		 (save-match-data
		   (setq cbd-parent cbd)
		   (if (string-match "[/\\]$" cbd-parent)
		       (setq cbd-parent (substring cbd-parent 0
						   (match-beginning 0))))
		   (setq cbd-parent (file-name-directory cbd-parent)))
		 (member cbd-parent speedbar-shown-directories))
	    (setq expand-local t)

	  ;; If this directory is NOT in the current list of available
	  ;; directories, then use the cache, and set the cache to our new
	  ;; value.  Make sure to unhighlight the current file, or if we
	  ;; come back to this directory, it might be a different file
	  ;; and then we get a mess!
	  (if (> (point-max) 1)
	      (progn
		(speedbar-clear-current-file)
		(setq speedbar-full-text-cache
		      (cons speedbar-shown-directories (buffer-string)))))

	  ;; Check if our new directory is in the list of directories
	  ;; shown in the text-cache
	  (if (member cbd (car cache))
	      (setq speedbar-shown-directories (car cache)
		    use-cache t)
	    ;; default the shown directories to this list...
	    (setq speedbar-shown-directories (list cbd)))
	  ))
      (if (not expand-local) (setq speedbar-last-selected-file nil))
      (speedbar-with-writable
	(if (and expand-local
		 ;; Find this directory as a speedbar node.
		 (speedbar-directory-line cbd))
	    ;; Open it.
	    (speedbar-expand-line)
	  (let* ((window (get-buffer-window speedbar-buffer 0))
		 (p (window-point window))
		 (start (window-start window)))
	    (erase-buffer)
	    (cond (use-cache
		   (setq default-directory
			 (nth (1- (length speedbar-shown-directories))
			      speedbar-shown-directories))
		   (insert (cdr cache)))
		  (t
		   (dolist (func funclst)
		     (setq default-directory cbd)
	    (funcall func cbd 0))))
	    (set-window-point window p)
	    (set-window-start window start)))))
  (speedbar-reconfigure-keymaps))