1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-16 02:50:26 -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,7 +1475,8 @@ 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
((re-search-forward " [-+=]?> \\([^\n]+\\)" (line-end-position) t)
(let* ((tag (match-string 1)) (let* ((tag (match-string 1))
(attr (speedbar-line-token)) (attr (speedbar-line-token))
(item nil) (item nil)
@ -1493,10 +1493,10 @@ Return nil if not applicable."
))) )))
(looking-at "\\([0-9]+\\):") (looking-at "\\([0-9]+\\):")
(setq item (file-name-nondirectory (speedbar-line-directory))) (setq item (file-name-nondirectory (speedbar-line-directory)))
(dframe-message "Tag: %s in %s" tag item))) (dframe-message "Tag: %s in %s" tag item))))
(if (re-search-forward "{[+-]} \\([^\n]+\\)$" (line-end-position) t) ((re-search-forward "{[+-]} \\([^\n]+\\)$" (line-end-position) t)
(dframe-message "Group of tags \"%s\"" (match-string 1)) (dframe-message "Group of tags \"%s\"" (match-string 1)))
(if (re-search-forward " [+-]?[()|@] \\([^\n]+\\)$" nil t) ((re-search-forward " [+-]?[()|@] \\([^\n]+\\)$" nil t)
(let* ((detailtext (match-string 1)) (let* ((detailtext (match-string 1))
(detail (or (speedbar-line-token) detailtext)) (detail (or (speedbar-line-token) detailtext))
(parent (save-excursion (parent (save-excursion
@ -1511,7 +1511,8 @@ Return nil if not applicable."
(if (looking-at "[0-9]+: +[-+=>]> \\([^\n]+\\)$") (if (looking-at "[0-9]+: +[-+=>]> \\([^\n]+\\)$")
(speedbar-line-token) (speedbar-line-token)
nil)))) nil))))
(if (featurep 'semantic) (cond
((featurep 'semantic)
(with-no-warnings (with-no-warnings
(if (semantic-tag-p detail) (if (semantic-tag-p detail)
(dframe-message (dframe-message
@ -1521,12 +1522,12 @@ Return nil if not applicable."
(if (semantic-tag-p parent) (if (semantic-tag-p parent)
(semantic-format-tag-name parent nil t) (semantic-format-tag-name parent nil t)
parent)) parent))
(dframe-message "Detail: %s" detail)))) (dframe-message "Detail: %s" detail)))))
;; Not using `semantic': ;; Not using `semantic':
(if parent (parent
(dframe-message "Detail: %s of tag %s" detail parent) (dframe-message "Detail: %s of tag %s" detail parent))
(dframe-message "Detail: %s" detail)))) (t
nil))))) (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))