Function: speedbar-directory-buttons

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

Signature

(speedbar-directory-buttons DIRECTORY INDEX)

Documentation

Insert a single button group at point for DIRECTORY.

Each directory part is a different button. If part of the directory matches the user directory ~, then it is replaced with a ~. INDEX is not used, but is required by the caller.

Source Code

;; Defined in /usr/src/emacs/lisp/speedbar.el.gz
(defun speedbar-directory-buttons (directory _index)
  "Insert a single button group at point for DIRECTORY.
Each directory part is a different button.  If part of the directory
matches the user directory ~, then it is replaced with a ~.
INDEX is not used, but is required by the caller."
  (let* ((tilde (expand-file-name "~/"))
	 (dd (expand-file-name directory))
	 (junk (string-match (regexp-quote tilde) dd))
	 (displayme (if junk
			(concat "~/" (substring dd (match-end 0)))
		      dd))
	 (p (point)))
    (if (string-match "^~[/\\]?\\'" displayme) (setq displayme tilde))
    (insert displayme)
    (save-excursion
      (goto-char p)
      (while (re-search-forward "\\([^/\\]+\\)[/\\]" nil t)
	(speedbar-make-button (match-beginning 1) (match-end 1)
			      'speedbar-directory-face
			      'speedbar-highlight-face
			      'speedbar-directory-buttons-follow
			      (if (and (= (match-beginning 1) p)
				       (not (char-equal (char-after (+ p 1)) ?:)))
				  (expand-file-name "~/")  ;the tilde
				(buffer-substring-no-properties
				 p (match-end 0)))))
      ;; Nuke the beginning of the directory if it's too long...
      (cond ((eq speedbar-directory-button-trim-method 'span)
	     (beginning-of-line)
	     (let ((ww (or (speedbar-frame-width) 20)))
	       (move-to-column ww nil)
	       (while (>= (current-column) ww)
		 (re-search-backward "[/\\]" nil t)
		 (if (<= (current-column) 2)
		     (progn
		       (re-search-forward "[/\\]" nil t)
		       (if (< (current-column) 4)
			   (re-search-forward "[/\\]" nil t))
		       (forward-char -1)))
		 (if (looking-at "[/\\]?$")
		     (beginning-of-line)
		   (insert "/...\n ")
		   (move-to-column ww nil)))))
	    ((eq speedbar-directory-button-trim-method 'trim)
	     (end-of-line)
	     (let ((ww (or (speedbar-frame-width) 20))
		   (tl (current-column)))
	       (if (< ww tl)
		   (progn
		     (move-to-column (- tl ww))
		     (if (re-search-backward "[/\\]" nil t)
			 (progn
			   (delete-region (point-min) (point))
			   (insert "$")
			   )))))))
      )
    (if (string-match "\\`[/\\][^/\\]+[/\\]\\'" displayme)
	(progn
	  (insert "  ")
	  (let ((p (point)))
	    (insert "<root>")
	    (speedbar-make-button p (point)
				  'speedbar-directory-face
				  'speedbar-highlight-face
				  'speedbar-directory-buttons-follow
				  "/"))))
    (end-of-line)
    (insert-char ?\n 1 nil)))