1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-17 11:20:39 -08:00

* lisp/speedbar.el: Minor tweaks

(speedbar-directory-buttons-follow): Use file-name-as-directory.
(speedbar-ignored-directory-expressions)
(speedbar-supported-extension-expressions): Use `sym` in the setter.
(speedbar-frame-mode): Use with-current-buffer.
(speedbar-item-info-tag-helper): Use 'cond'.
(speedbar-highlight-one-tag-line): Don't use position beyond EOB.
This commit is contained in:
Stefan Monnier 2019-03-10 03:54:46 -04:00
parent affd2a0cee
commit e70a65d403

View file

@ -647,9 +647,9 @@ speedbar is loaded. You may place anything you like in this list
before speedbar has been loaded." before speedbar has been loaded."
:group 'speedbar :group 'speedbar
:type '(repeat (regexp :tag "Directory Regexp")) :type '(repeat (regexp :tag "Directory Regexp"))
:set (lambda (_sym val) :set (lambda (sym val)
(setq speedbar-ignored-directory-expressions val (set sym val)
speedbar-ignored-directory-regexp (setq speedbar-ignored-directory-regexp
(speedbar-extension-list-to-regex val)))) (speedbar-extension-list-to-regex val))))
(defcustom speedbar-directory-unshown-regexp "^\\(\\..*\\)\\'" (defcustom speedbar-directory-unshown-regexp "^\\(\\..*\\)\\'"
@ -701,9 +701,9 @@ need to also modify `completion-ignored-extension' which will also help
file completion." file completion."
:group 'speedbar :group 'speedbar
:type '(repeat (regexp :tag "Extension Regexp")) :type '(repeat (regexp :tag "Extension Regexp"))
:set (lambda (_sym val) :set (lambda (sym val)
(set 'speedbar-supported-extension-expressions val) (set sym val)
(set 'speedbar-file-regexp (speedbar-extension-list-to-regex val)))) (setq speedbar-file-regexp (speedbar-extension-list-to-regex val))))
(setq speedbar-file-regexp (setq speedbar-file-regexp
(speedbar-extension-list-to-regex speedbar-supported-extension-expressions)) (speedbar-extension-list-to-regex speedbar-supported-extension-expressions))
@ -972,9 +972,8 @@ supported at a time.
(interactive "P") (interactive "P")
;; Get the buffer to play with ;; Get the buffer to play with
(if (not (buffer-live-p speedbar-buffer)) (if (not (buffer-live-p speedbar-buffer))
(save-excursion (with-current-buffer
(setq speedbar-buffer (get-buffer-create " SPEEDBAR")) (setq speedbar-buffer (get-buffer-create " SPEEDBAR"))
(set-buffer speedbar-buffer)
(speedbar-mode))) (speedbar-mode)))
;; Do the frame thing ;; Do the frame thing
(dframe-frame-mode arg (dframe-frame-mode arg
@ -1476,57 +1475,59 @@ instead of reading it from the speedbar buffer."
Return nil if not applicable." Return nil if not applicable."
(save-excursion (save-excursion
(beginning-of-line) (beginning-of-line)
(if (re-search-forward " [-+=]?> \\([^\n]+\\)" (line-end-position) t) (cond
(let* ((tag (match-string 1)) ((re-search-forward " [-+=]?> \\([^\n]+\\)" (line-end-position) t)
(attr (speedbar-line-token)) (let* ((tag (match-string 1))
(item nil) (attr (speedbar-line-token))
(semantic-tagged (if (fboundp 'semantic-tag-p) (item nil)
(semantic-tag-p attr)))) (semantic-tagged (if (fboundp 'semantic-tag-p)
(if semantic-tagged (semantic-tag-p attr))))
(with-no-warnings (if semantic-tagged
(save-excursion (with-no-warnings
(when (and (semantic-tag-overlay attr) (save-excursion
(semantic-tag-buffer attr)) (when (and (semantic-tag-overlay attr)
(set-buffer (semantic-tag-buffer attr))) (semantic-tag-buffer attr))
(dframe-message (set-buffer (semantic-tag-buffer attr)))
(funcall semantic-sb-info-format-tag-function attr) (dframe-message
))) (funcall semantic-sb-info-format-tag-function attr)
(looking-at "\\([0-9]+\\):") )))
(setq item (file-name-nondirectory (speedbar-line-directory))) (looking-at "\\([0-9]+\\):")
(dframe-message "Tag: %s in %s" tag item))) (setq item (file-name-nondirectory (speedbar-line-directory)))
(if (re-search-forward "{[+-]} \\([^\n]+\\)$" (line-end-position) t) (dframe-message "Tag: %s in %s" tag item))))
(dframe-message "Group of tags \"%s\"" (match-string 1)) ((re-search-forward "{[+-]} \\([^\n]+\\)$" (line-end-position) t)
(if (re-search-forward " [+-]?[()|@] \\([^\n]+\\)$" nil t) (dframe-message "Group of tags \"%s\"" (match-string 1)))
(let* ((detailtext (match-string 1)) ((re-search-forward " [+-]?[()|@] \\([^\n]+\\)$" nil t)
(detail (or (speedbar-line-token) detailtext)) (let* ((detailtext (match-string 1))
(parent (save-excursion (detail (or (speedbar-line-token) detailtext))
(beginning-of-line) (parent (save-excursion
(let ((dep (if (looking-at "[0-9]+:") (beginning-of-line)
(1- (string-to-number (match-string 0))) (let ((dep (if (looking-at "[0-9]+:")
0))) (1- (string-to-number (match-string 0)))
(re-search-backward (concat "^" 0)))
(int-to-string dep) (re-search-backward (concat "^"
":") (int-to-string dep)
nil t)) ":")
(if (looking-at "[0-9]+: +[-+=>]> \\([^\n]+\\)$") nil t))
(speedbar-line-token) (if (looking-at "[0-9]+: +[-+=>]> \\([^\n]+\\)$")
nil)))) (speedbar-line-token)
(if (featurep 'semantic) nil))))
(with-no-warnings (cond
(if (semantic-tag-p detail) ((featurep 'semantic)
(dframe-message (with-no-warnings
(funcall semantic-sb-info-format-tag-function detail parent)) (if (semantic-tag-p detail)
(if parent (dframe-message
(dframe-message "Detail: %s of tag %s" detail (funcall semantic-sb-info-format-tag-function detail parent))
(if (semantic-tag-p parent) (if parent
(semantic-format-tag-name parent nil t) (dframe-message "Detail: %s of tag %s" detail
parent)) (if (semantic-tag-p parent)
(dframe-message "Detail: %s" detail)))) (semantic-format-tag-name parent nil t)
;; Not using `semantic': parent))
(if parent (dframe-message "Detail: %s" detail)))))
(dframe-message "Detail: %s of tag %s" detail parent) ;; Not using `semantic':
(dframe-message "Detail: %s" detail)))) (parent
nil))))) (dframe-message "Detail: %s of tag %s" detail parent))
(t
(dframe-message "Detail: %s" detail))))))))
(defun speedbar-files-item-info () (defun speedbar-files-item-info ()
"Display info in the minibuffer about the button the mouse is over." "Display info in the minibuffer about the button the mouse is over."
@ -3388,9 +3389,7 @@ expanded. INDENT is the current indentation level."
"Speedbar click handler for default directory buttons. "Speedbar click handler for default directory buttons.
TEXT is the button clicked on. TOKEN is the directory to follow. TEXT is the button clicked on. TOKEN is the directory to follow.
INDENT is the current indentation level and is unused." INDENT is the current indentation level and is unused."
(if (string-match "^[A-Za-z]:$" token) (setq default-directory (file-name-as-directory token))
(setq default-directory (concat token "/"))
(setq default-directory token))
;; Because we leave speedbar as the current buffer, ;; Because we leave speedbar as the current buffer,
;; update contents will change directory without ;; update contents will change directory without
;; having to touch the attached frame. ;; having to touch the attached frame.
@ -3964,7 +3963,7 @@ TEXT is the buffer's name, TOKEN and INDENT are unused."
(speedbar-unhighlight-one-tag-line) (speedbar-unhighlight-one-tag-line)
(setq speedbar-highlight-one-tag-line (setq speedbar-highlight-one-tag-line
(speedbar-make-overlay (line-beginning-position) (speedbar-make-overlay (line-beginning-position)
(1+ (line-end-position)))) (line-beginning-position 2)))
(speedbar-overlay-put speedbar-highlight-one-tag-line 'face (speedbar-overlay-put speedbar-highlight-one-tag-line 'face
'speedbar-highlight-face) 'speedbar-highlight-face)
(add-hook 'pre-command-hook 'speedbar-unhighlight-one-tag-line)) (add-hook 'pre-command-hook 'speedbar-unhighlight-one-tag-line))