comparison lisp/speedbar.el @ 78055:e49170723831

(speedbar-handle-delete-frame): Don't try to delete the speedbar frame if nil; that deletes the current frame or causes an error if it is the only frame.
author Juanma Barranquero <lekktu@gmail.com>
date Thu, 28 Jun 2007 09:03:36 +0000
parents f110ee6599bf
children 9355f9b7bbff 988f1edc9674
comparison
equal deleted inserted replaced
78054:1a55eb494131 78055:e49170723831
8 8
9 (defvar speedbar-version "1.0" 9 (defvar speedbar-version "1.0"
10 "The current version of speedbar.") 10 "The current version of speedbar.")
11 (defvar speedbar-incompatible-version "0.14beta4" 11 (defvar speedbar-incompatible-version "0.14beta4"
12 "This version of speedbar is incompatible with this version. 12 "This version of speedbar is incompatible with this version.
13 Due to massive API changes (removing the use of the word PATH) 13 Due to massive API changes (removing the use of the word PATH)
14 this version is not backward compatible to 0.14 or earlier.") 14 this version is not backward compatible to 0.14 or earlier.")
15 15
16 ;; This file is part of GNU Emacs. 16 ;; This file is part of GNU Emacs.
17 17
18 ;; GNU Emacs is free software; you can redistribute it and/or modify 18 ;; GNU Emacs is free software; you can redistribute it and/or modify
913 ["Delete Object" speedbar-item-object-delete 913 ["Delete Object" speedbar-item-object-delete
914 (save-excursion (beginning-of-line) 914 (save-excursion (beginning-of-line)
915 (looking-at "[0-9]+: *\\[[+-]\\] [^ \n]+ \\*?[!#]$"))] 915 (looking-at "[0-9]+: *\\[[+-]\\] [^ \n]+ \\*?[!#]$"))]
916 ) 916 )
917 "Additional menu items while in file-mode.") 917 "Additional menu items while in file-mode.")
918 918
919 (defvar speedbar-easymenu-definition-trailer 919 (defvar speedbar-easymenu-definition-trailer
920 (append 920 (append
921 (if (and (featurep 'custom) (fboundp 'custom-declare-variable)) 921 (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
922 (list ["Customize..." speedbar-customize t])) 922 (list ["Customize..." speedbar-customize t]))
923 (list 923 (list
956 ;;; Compatibility 956 ;;; Compatibility
957 ;; 957 ;;
958 (defalias 'speedbar-make-overlay 958 (defalias 'speedbar-make-overlay
959 (if (featurep 'xemacs) 'make-extent 'make-overlay)) 959 (if (featurep 'xemacs) 'make-extent 'make-overlay))
960 960
961 (defalias 'speedbar-overlay-put 961 (defalias 'speedbar-overlay-put
962 (if (featurep 'xemacs) 'set-extent-property 'overlay-put)) 962 (if (featurep 'xemacs) 'set-extent-property 'overlay-put))
963 963
964 (defalias 'speedbar-delete-overlay 964 (defalias 'speedbar-delete-overlay
965 (if (featurep 'xemacs) 'delete-extent 'delete-overlay)) 965 (if (featurep 'xemacs) 'delete-extent 'delete-overlay))
966 966
967 (defalias 'speedbar-mode-line-update 967 (defalias 'speedbar-mode-line-update
968 (if (featurep 'xemacs) 'redraw-modeline 'force-mode-line-update)) 968 (if (featurep 'xemacs) 'redraw-modeline 'force-mode-line-update))
969 969
970 ;;; Mode definitions/ user commands 970 ;;; Mode definitions/ user commands
971 ;; 971 ;;
972 972
1051 1051
1052 (defun speedbar-handle-delete-frame (e) 1052 (defun speedbar-handle-delete-frame (e)
1053 "Handle a delete frame event E. 1053 "Handle a delete frame event E.
1054 If the deleted frame is the frame SPEEDBAR is attached to, 1054 If the deleted frame is the frame SPEEDBAR is attached to,
1055 we need to delete speedbar also." 1055 we need to delete speedbar also."
1056 (let ((frame-to-be-deleted (car (car (cdr e))))) 1056 (when (and speedbar-frame
1057 (if (eq frame-to-be-deleted dframe-attached-frame) 1057 (eq (car (car (cdr e))) ;; frame to be deleted
1058 (delete-frame speedbar-frame))) 1058 dframe-attached-frame))
1059 ) 1059 (delete-frame speedbar-frame)))
1060 1060
1061 ;;;###autoload 1061 ;;;###autoload
1062 (defun speedbar-get-focus () 1062 (defun speedbar-get-focus ()
1063 "Change frame focus to or from the speedbar frame. 1063 "Change frame focus to or from the speedbar frame.
1064 If the selected frame is not speedbar, then speedbar frame is 1064 If the selected frame is not speedbar, then speedbar frame is
1156 (dframe-select-attached-frame (speedbar-current-frame))) 1156 (dframe-select-attached-frame (speedbar-current-frame)))
1157 1157
1158 ;; Backwards compatibility 1158 ;; Backwards compatibility
1159 (defalias 'speedbar-with-attached-buffer 'dframe-with-attached-buffer) 1159 (defalias 'speedbar-with-attached-buffer 'dframe-with-attached-buffer)
1160 (defalias 'speedbar-maybee-jump-to-attached-frame 'dframe-maybee-jump-to-attached-frame) 1160 (defalias 'speedbar-maybee-jump-to-attached-frame 'dframe-maybee-jump-to-attached-frame)
1161 1161
1162 (defun speedbar-set-mode-line-format () 1162 (defun speedbar-set-mode-line-format ()
1163 "Set the format of the mode line based on the current speedbar environment. 1163 "Set the format of the mode line based on the current speedbar environment.
1164 This gives visual indications of what is up. It EXPECTS the speedbar 1164 This gives visual indications of what is up. It EXPECTS the speedbar
1165 frame and window to be the currently active frame and window." 1165 frame and window to be the currently active frame and window."
1166 (if (and (frame-live-p (speedbar-current-frame)) 1166 (if (and (frame-live-p (speedbar-current-frame))
2053 (put-text-property (1- (point)) (point) 'invisible nil) 2053 (put-text-property (1- (point)) (point) 'invisible nil)
2054 (speedbar-make-button start end tag-button-face 2054 (speedbar-make-button start end tag-button-face
2055 (if tag-button-function 'speedbar-highlight-face nil) 2055 (if tag-button-function 'speedbar-highlight-face nil)
2056 tag-button-function tag-button-data)) 2056 tag-button-function tag-button-data))
2057 )) 2057 ))
2058 2058
2059 (defun speedbar-change-expand-button-char (char) 2059 (defun speedbar-change-expand-button-char (char)
2060 "Change the expansion button character to CHAR for the current line." 2060 "Change the expansion button character to CHAR for the current line."
2061 (save-excursion 2061 (save-excursion
2062 (beginning-of-line) 2062 (beginning-of-line)
2063 (if (re-search-forward ":\\s-*.\\([-+?]\\)" (save-excursion (end-of-line) 2063 (if (re-search-forward ":\\s-*.\\([-+?]\\)" (save-excursion (end-of-line)
2098 'speedbar-file-face level))) 2098 'speedbar-file-face level)))
2099 (setq lst (cdr lst))))) 2099 (setq lst (cdr lst)))))
2100 2100
2101 (defun speedbar-default-directory-list (directory index) 2101 (defun speedbar-default-directory-list (directory index)
2102 "Insert files for DIRECTORY with level INDEX at point." 2102 "Insert files for DIRECTORY with level INDEX at point."
2103 (speedbar-insert-files-at-point 2103 (speedbar-insert-files-at-point
2104 (speedbar-file-lists directory) index) 2104 (speedbar-file-lists directory) index)
2105 (speedbar-reset-scanners) 2105 (speedbar-reset-scanners)
2106 (if (= index 0) 2106 (if (= index 0)
2107 ;; If the shown files variable has extra directories, then 2107 ;; If the shown files variable has extra directories, then
2108 ;; it is our responsibility to redraw them all 2108 ;; it is our responsibility to redraw them all
2452 (defun speedbar-insert-imenu-list (indent lst) 2452 (defun speedbar-insert-imenu-list (indent lst)
2453 "At level INDENT, insert the imenu generated LST." 2453 "At level INDENT, insert the imenu generated LST."
2454 (speedbar-insert-generic-list indent lst 2454 (speedbar-insert-generic-list indent lst
2455 'speedbar-tag-expand 2455 'speedbar-tag-expand
2456 'speedbar-tag-find)) 2456 'speedbar-tag-find))
2457 2457
2458 (defun speedbar-insert-etags-list (indent lst) 2458 (defun speedbar-insert-etags-list (indent lst)
2459 "At level INDENT, insert the etags generated LST." 2459 "At level INDENT, insert the etags generated LST."
2460 (speedbar-insert-generic-list indent lst 2460 (speedbar-insert-generic-list indent lst
2461 'speedbar-tag-expand 2461 'speedbar-tag-expand
2462 'speedbar-tag-find)) 2462 'speedbar-tag-find))
2727 2727
2728 (defun speedbar-find-selected-file (file) 2728 (defun speedbar-find-selected-file (file)
2729 "Go to the line where FILE is." 2729 "Go to the line where FILE is."
2730 2730
2731 (set-buffer speedbar-buffer) 2731 (set-buffer speedbar-buffer)
2732 2732
2733 (goto-char (point-min)) 2733 (goto-char (point-min))
2734 (let ((m nil)) 2734 (let ((m nil))
2735 (while (and (setq m (re-search-forward 2735 (while (and (setq m (re-search-forward
2736 (concat " \\(" (regexp-quote (file-name-nondirectory file)) 2736 (concat " \\(" (regexp-quote (file-name-nondirectory file))
2737 "\\)\\(" speedbar-indicator-regex "\\)?\n") 2737 "\\)\\(" speedbar-indicator-regex "\\)?\n")
3218 `speedbar-mode-functions-list' as `speedbar-line-directory'." 3218 `speedbar-mode-functions-list' as `speedbar-line-directory'."
3219 (save-restriction 3219 (save-restriction
3220 (widen) 3220 (widen)
3221 (let ((rf (speedbar-fetch-replacement-function 'speedbar-line-directory))) 3221 (let ((rf (speedbar-fetch-replacement-function 'speedbar-line-directory)))
3222 (if rf (funcall rf depth) default-directory)))) 3222 (if rf (funcall rf depth) default-directory))))
3223 3223
3224 (defun speedbar-files-line-directory (&optional depth) 3224 (defun speedbar-files-line-directory (&optional depth)
3225 "Retrieve the directoryname associated with the current line. 3225 "Retrieve the directoryname associated with the current line.
3226 This may require traversing backwards from DEPTH and combining the default 3226 This may require traversing backwards from DEPTH and combining the default
3227 directory with these items." 3227 directory with these items."
3228 (save-excursion 3228 (save-excursion
3303 (re-search-forward ":\\s-*.\\+. " 3303 (re-search-forward ":\\s-*.\\+. "
3304 (save-excursion (end-of-line) (point))) 3304 (save-excursion (end-of-line) (point)))
3305 (forward-char -2) 3305 (forward-char -2)
3306 (speedbar-do-function-pointer)) 3306 (speedbar-do-function-pointer))
3307 (error (speedbar-position-cursor-on-line))))) 3307 (error (speedbar-position-cursor-on-line)))))
3308 3308
3309 (defun speedbar-flush-expand-line () 3309 (defun speedbar-flush-expand-line ()
3310 "Expand the line under the cursor and flush any cached information." 3310 "Expand the line under the cursor and flush any cached information."
3311 (interactive) 3311 (interactive)
3312 (speedbar-expand-line 1)) 3312 (speedbar-expand-line 1))
3313 3313
3314 (defun speedbar-contract-line () 3314 (defun speedbar-contract-line ()
3315 "Contract the line under the cursor." 3315 "Contract the line under the cursor."
3316 (interactive) 3316 (interactive)
3317 (beginning-of-line) 3317 (beginning-of-line)
3318 (condition-case nil 3318 (condition-case nil
3557 "Recenter a speedbar buffer so the current indentation level is all visible. 3557 "Recenter a speedbar buffer so the current indentation level is all visible.
3558 This assumes that the cursor is on a file, or tag of a file which the user is 3558 This assumes that the cursor is on a file, or tag of a file which the user is
3559 interested in." 3559 interested in."
3560 3560
3561 (save-selected-window 3561 (save-selected-window
3562 3562
3563 (select-window (get-buffer-window speedbar-buffer t)) 3563 (select-window (get-buffer-window speedbar-buffer t))
3564 3564
3565 (set-buffer speedbar-buffer) 3565 (set-buffer speedbar-buffer)
3566 3566
3567 (if (<= (count-lines (point-min) (point-max)) 3567 (if (<= (count-lines (point-min) (point-max))
3568 (1- (window-height (selected-window)))) 3568 (1- (window-height (selected-window))))
3569 ;; whole buffer fits 3569 ;; whole buffer fits
3570 (let ((cp (point))) 3570 (let ((cp (point)))
3571 3571