comparison lisp/speedbar.el @ 22893:322179a8fd20

(speedbar-update-current-file): Added call to `speedbar-center-buffer-smartly' to improve the display. (speedbar-center-buffer-smartly) Fixed off-by-one error in window height calculation. (speedbar-hack-buffer-menu): New function. (speedbar-frame-parameters): Removed scroll bar width. (speedbar-frame-mode): Change pointer shape for X and W32 window-systems only. When window-system is pc, bind the speedbar frame name to "Speedbar", and select that frame so it is displayed. (speedbar-mode): Don't bind default-minibuffer-frame when window-system is pc. (speedbar-this-file-in-vc): Look for RCS/name as well as RCS/name,v. (speedbar-directory-buttons-follow): Support both upper- and lower-case drive letters. Use directory-sep-char instead of a literal backslash. (speedbar-reconfigure-keymaps): Call `easy-menu-remove' before reconfiguring for a new menu bar. (speedbar-previous-menu): New Variable. (speedbar-frame-plist): Remove pointers. (speedbar-refresh): Prevent the mark from being deactivated. (speedbar-buffer-kill-buffer): Refresh speedbar after killing a buffer in the buffer display.
author Eric M. Ludlam <zappo@gnu.org>
date Mon, 03 Aug 1998 17:47:39 +0000
parents ca02f300fc41
children adfc04c48002
comparison
equal deleted inserted replaced
22892:850946452989 22893:322179a8fd20
1 ;;; speedbar --- quick access to files and tags in a frame 1 ;;; speedbar --- quick access to files and tags in a frame
2 2
3 ;;; Copyright (C) 1996, 97, 98 Free Software Foundation 3 ;;; Copyright (C) 1996, 97, 98 Free Software Foundation
4 4
5 ;; Author: Eric M. Ludlam <zappo@gnu.org> 5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; Version: 0.7 6 ;; Version: 0.7.1
7 ;; Keywords: file, tags, tools 7 ;; Keywords: file, tags, tools
8 ;; X-RCS: $Id: speedbar.el,v 1.112 1998/06/16 12:53:18 kwzh Exp kwzh $ 8 ;; X-RCS: $Id: speedbar.el,v 1.4 1998/07/10 16:48:06 kwzh Exp zappo $
9 9
10 ;; This file is part of GNU Emacs. 10 ;; This file is part of GNU Emacs.
11 11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify 12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by 13 ;; it under the terms of the GNU General Public License as published by
804 ;; This lets the user scroll as if we had a scrollbar... well maybe not 804 ;; This lets the user scroll as if we had a scrollbar... well maybe not
805 (define-key speedbar-key-map [mode-line mouse-2] 'speedbar-mouse-hscroll) 805 (define-key speedbar-key-map [mode-line mouse-2] 'speedbar-mouse-hscroll)
806 ;; another handy place users might click to get our menu. 806 ;; another handy place users might click to get our menu.
807 (define-key speedbar-key-map [mode-line down-mouse-1] 807 (define-key speedbar-key-map [mode-line down-mouse-1]
808 'speedbar-emacs-popup-kludge) 808 'speedbar-emacs-popup-kludge)
809
810 ;; We can't switch buffers with the buffer mouse menu. Lets hack it.
811 (define-key speedbar-key-map [C-down-mouse-1] 'speedbar-hack-buffer-menu)
809 812
810 ;; Lastly, we want to track the mouse. Play here 813 ;; Lastly, we want to track the mouse. Play here
811 (define-key speedbar-key-map [mouse-movement] 'speedbar-track-mouse) 814 (define-key speedbar-key-map [mouse-movement] 'speedbar-track-mouse)
812 )) 815 ))
813 816
1004 ;; Get the buffer to play with 1007 ;; Get the buffer to play with
1005 (speedbar-mode) 1008 (speedbar-mode)
1006 (select-frame speedbar-frame) 1009 (select-frame speedbar-frame)
1007 (switch-to-buffer speedbar-buffer) 1010 (switch-to-buffer speedbar-buffer)
1008 (set-window-dedicated-p (selected-window) t)) 1011 (set-window-dedicated-p (selected-window) t))
1012 (if (or (null window-system) (eq window-system 'pc))
1013 (progn
1014 (select-frame speedbar-frame)
1015 (set-frame-name "Speedbar")))
1009 (speedbar-set-timer speedbar-update-speed))))) 1016 (speedbar-set-timer speedbar-update-speed)))))
1010 1017
1011 ;;;###autoload 1018 ;;;###autoload
1012 (defun speedbar-get-focus () 1019 (defun speedbar-get-focus ()
1013 "Change frame focus to or from the speedbar frame. 1020 "Change frame focus to or from the speedbar frame.
1111 (setq truncate-lines t) 1118 (setq truncate-lines t)
1112 (make-local-variable 'frame-title-format) 1119 (make-local-variable 'frame-title-format)
1113 (setq frame-title-format "Speedbar") 1120 (setq frame-title-format "Speedbar")
1114 ;; Set this up special just for the speedbar buffer 1121 ;; Set this up special just for the speedbar buffer
1115 ;; Terminal minibuffer stuff does not require this. 1122 ;; Terminal minibuffer stuff does not require this.
1116 (if (and window-system (null default-minibuffer-frame)) 1123 (if (and window-system (not (eq window-system 'pc))
1124 (null default-minibuffer-frame))
1117 (progn 1125 (progn
1118 (make-local-variable 'default-minibuffer-frame) 1126 (make-local-variable 'default-minibuffer-frame)
1119 (setq default-minibuffer-frame speedbar-attached-frame))) 1127 (setq default-minibuffer-frame speedbar-attached-frame)))
1120 ;; Correct use of `temp-buffer-show-function': Bob Weiner 1128 ;; Correct use of `temp-buffer-show-function': Bob Weiner
1121 (if (and (boundp 'temp-buffer-show-hook) 1129 (if (and (boundp 'temp-buffer-show-hook)
1217 (run-hook-with-args 'temp-buffer-show-hook buffer)) 1225 (run-hook-with-args 'temp-buffer-show-hook buffer))
1218 ((and (boundp 'temp-buffer-show-hook) 1226 ((and (boundp 'temp-buffer-show-hook)
1219 (listp temp-buffer-show-hook)) 1227 (listp temp-buffer-show-hook))
1220 (mapcar (function (lambda (hook) (funcall hook buffer))) 1228 (mapcar (function (lambda (hook) (funcall hook buffer)))
1221 temp-buffer-show-hook)))) 1229 temp-buffer-show-hook))))
1230
1231 (defvar speedbar-previous-menu nil
1232 "The menu before the last `speedbar-reconfigure-keymaps' was called.")
1222 1233
1223 (defun speedbar-reconfigure-keymaps () 1234 (defun speedbar-reconfigure-keymaps ()
1224 "Reconfigure the menu-bar in a speedbar frame. 1235 "Reconfigure the menu-bar in a speedbar frame.
1225 Different menu items are displayed depending on the current display mode 1236 Different menu items are displayed depending on the current display mode
1226 and the existence of packages." 1237 and the existence of packages."
1269 (use-local-map (or localmap 1280 (use-local-map (or localmap
1270 (speedbar-initial-keymap) 1281 (speedbar-initial-keymap)
1271 ;; This creates a small keymap we can glom the 1282 ;; This creates a small keymap we can glom the
1272 ;; menu adjustments into. 1283 ;; menu adjustments into.
1273 (speedbar-make-specialized-keymap))) 1284 (speedbar-make-specialized-keymap)))
1285 ;; Delete the old menu if applicable.
1286 (if speedbar-previous-menu (easy-menu-remove speedbar-previous-menu))
1287 (setq speedbar-previous-menu md)
1288 ;; Now add the new menu
1274 (if (not speedbar-xemacsp) 1289 (if (not speedbar-xemacsp)
1275 (easy-menu-define speedbar-menu-map (current-local-map) 1290 (easy-menu-define speedbar-menu-map (current-local-map)
1276 "Speedbar menu" md) 1291 "Speedbar menu" md)
1277 (if (and (not (assoc "Speedbar" mode-popup-menu))) 1292 (easy-menu-add md (current-local-map))
1278 (easy-menu-add md (current-local-map)))
1279 (set-buffer-menubar (list md)))))) 1293 (set-buffer-menubar (list md))))))
1280 1294
1281 1295
1282 ;;; User Input stuff 1296 ;;; User Input stuff
1283 ;; 1297 ;;
1372 (if (not (bolp)) (forward-char -1)) 1386 (if (not (bolp)) (forward-char -1))
1373 (sit-for 0) 1387 (sit-for 0)
1374 (if (< emacs-major-version 20) 1388 (if (< emacs-major-version 20)
1375 (mouse-major-mode-menu e) 1389 (mouse-major-mode-menu e)
1376 (mouse-major-mode-menu e nil)))) 1390 (mouse-major-mode-menu e nil))))
1391
1392 (defun speedbar-hack-buffer-menu (e)
1393 "Control mouse 1 is buffer menu.
1394 This hack overrides it so that the right thing happens in the main
1395 Emacs frame, not in the speedbar frame.
1396 Argument E is the event causing this activity."
1397 (interactive "e")
1398 (let ((fn (lookup-key global-map (if speedbar-xemacsp
1399 '(control button1)
1400 [C-down-mouse-1])))
1401 (newbuff nil))
1402 (unwind-protect
1403 (save-excursion
1404 (set-window-dedicated-p (selected-window) nil)
1405 (call-interactively fn)
1406 (setq newbuff (current-buffer)))
1407 (switch-to-buffer " SPEEDBAR")
1408 (set-window-dedicated-p (selected-window) t))
1409 (speedbar-with-attached-buffer
1410 (switch-to-buffer newbuff))))
1377 1411
1378 (defun speedbar-next (arg) 1412 (defun speedbar-next (arg)
1379 "Move to the next ARGth line in a speedbar buffer." 1413 "Move to the next ARGth line in a speedbar buffer."
1380 (interactive "p") 1414 (interactive "p")
1381 (forward-line (or arg 1)) 1415 (forward-line (or arg 1))
1485 ;;; Speedbar file activity (aka creeping featurism) 1519 ;;; Speedbar file activity (aka creeping featurism)
1486 ;; 1520 ;;
1487 (defun speedbar-refresh () 1521 (defun speedbar-refresh ()
1488 "Refresh the current speedbar display, disposing of any cached data." 1522 "Refresh the current speedbar display, disposing of any cached data."
1489 (interactive) 1523 (interactive)
1490 (let ((dl speedbar-shown-directories)) 1524 (let ((dl speedbar-shown-directories)
1525 (dm (and (boundp 'deactivate-mark) deactivate-mark)))
1491 (while dl 1526 (while dl
1492 (adelete 'speedbar-directory-contents-alist (car dl)) 1527 (adelete 'speedbar-directory-contents-alist (car dl))
1493 (setq dl (cdr dl)))) 1528 (setq dl (cdr dl)))
1494 (if (<= 1 speedbar-verbosity-level) (message "Refreshing speedbar...")) 1529 (if (<= 1 speedbar-verbosity-level) (message "Refreshing speedbar..."))
1495 (speedbar-update-contents) 1530 (speedbar-update-contents)
1496 (speedbar-stealthy-updates) 1531 (speedbar-stealthy-updates)
1497 ;; Reset the timer in case it got really hosed for some reason... 1532 ;; Reset the timer in case it got really hosed for some reason...
1498 (speedbar-set-timer speedbar-update-speed) 1533 (speedbar-set-timer speedbar-update-speed)
1499 (if (<= 1 speedbar-verbosity-level) 1534 (if (<= 1 speedbar-verbosity-level)
1500 (progn 1535 (progn
1501 (message "Refreshing speedbar...done") 1536 (message "Refreshing speedbar...done")
1502 (sit-for 0) 1537 (sit-for 0)
1503 (message nil)))) 1538 (message nil)))
1539 ;; Protect the highlighted region.
1540 (if (boundp 'deactivate-mark) (setq deactivate-mark dm))))
1504 1541
1505 (defun speedbar-item-load () 1542 (defun speedbar-item-load ()
1506 "Load the item under the cursor or mouse if it is a Lisp file." 1543 "Load the item under the cursor or mouse if it is a Lisp file."
1507 (interactive) 1544 (interactive)
1508 (let ((f (speedbar-line-file))) 1545 (let ((f (speedbar-line-file)))
2644 'speedbar-selected-face))) 2681 'speedbar-selected-face)))
2645 ;; if it's not in there now, whatever... 2682 ;; if it's not in there now, whatever...
2646 )) 2683 ))
2647 (setq speedbar-last-selected-file newcf)) 2684 (setq speedbar-last-selected-file newcf))
2648 (if (not sucf-recursive) 2685 (if (not sucf-recursive)
2649 (speedbar-position-cursor-on-line)) 2686 (progn
2687 (speedbar-center-buffer-smartly)
2688 (speedbar-position-cursor-on-line)
2689 ))
2650 (set-buffer lastb) 2690 (set-buffer lastb)
2651 (select-frame lastf) 2691 (select-frame lastf)
2652 ))) 2692 )))
2653 ;; return that we are done with this activity. 2693 ;; return that we are done with this activity.
2654 t) 2694 t)
2769 optimize this function by overriding it and only doing those checks 2809 optimize this function by overriding it and only doing those checks
2770 that will occur on your system." 2810 that will occur on your system."
2771 (or 2811 (or
2772 ;; RCS file name 2812 ;; RCS file name
2773 (file-exists-p (concat path "RCS/" name ",v")) 2813 (file-exists-p (concat path "RCS/" name ",v"))
2814 (file-exists-p (concat path "RCS/" name))
2774 ;; Local SCCS file name 2815 ;; Local SCCS file name
2775 (file-exists-p (concat path "SCCS/p." name)) 2816 (file-exists-p (concat path "SCCS/p." name))
2776 ;; Remote SCCS file name 2817 ;; Remote SCCS file name
2777 (let ((proj-dir (getenv "PROJECTDIR"))) 2818 (let ((proj-dir (getenv "PROJECTDIR")))
2778 (if proj-dir 2819 (if proj-dir
3174 3215
3175 (defun speedbar-directory-buttons-follow (text token indent) 3216 (defun speedbar-directory-buttons-follow (text token indent)
3176 "Speedbar click handler for default directory buttons. 3217 "Speedbar click handler for default directory buttons.
3177 TEXT is the button clicked on. TOKEN is the directory to follow. 3218 TEXT is the button clicked on. TOKEN is the directory to follow.
3178 INDENT is the current indentation level and is unused." 3219 INDENT is the current indentation level and is unused."
3179 (if (string-match "^[A-Z]:$" token) 3220 (if (string-match "^[A-z]:$" token)
3180 (setq default-directory (concat token "\\")) 3221 (setq default-directory (concat token (char-to-string directory-sep-char)))
3181 (setq default-directory token)) 3222 (setq default-directory token))
3182 ;; Because we leave speedbar as the current buffer, 3223 ;; Because we leave speedbar as the current buffer,
3183 ;; update contents will change directory without 3224 ;; update contents will change directory without
3184 ;; having to touch the attached frame. 3225 ;; having to touch the attached frame.
3185 (speedbar-update-contents) 3226 (speedbar-update-contents)
3272 (defun speedbar-center-buffer-smartly () 3313 (defun speedbar-center-buffer-smartly ()
3273 "Recenter a speedbar buffer so the current indentation level is all visible. 3314 "Recenter a speedbar buffer so the current indentation level is all visible.
3274 This assumes that the cursor is on a file, or tag of a file which the user is 3315 This assumes that the cursor is on a file, or tag of a file which the user is
3275 interested in." 3316 interested in."
3276 (if (<= (count-lines (point-min) (point-max)) 3317 (if (<= (count-lines (point-min) (point-max))
3277 (window-height (selected-window))) 3318 (1- (window-height (selected-window))))
3278 ;; whole buffer fits 3319 ;; whole buffer fits
3279 (let ((cp (point))) 3320 (let ((cp (point)))
3280 (goto-char (point-min)) 3321 (goto-char (point-min))
3281 (recenter 0) 3322 (recenter 0)
3282 (goto-char cp)) 3323 (goto-char cp))
3629 (buffer-substring (point) (save-excursion 3670 (buffer-substring (point) (save-excursion
3630 (end-of-line) 3671 (end-of-line)
3631 (point)))))) 3672 (point))))))
3632 (if (and (get-buffer text) 3673 (if (and (get-buffer text)
3633 (y-or-n-p (format "Kill buffer %s? " text))) 3674 (y-or-n-p (format "Kill buffer %s? " text)))
3634 (kill-buffer text))))))) 3675 (kill-buffer text))
3676 (speedbar-refresh))))))
3635 3677
3636 (defun speedbar-buffer-revert-buffer () 3678 (defun speedbar-buffer-revert-buffer ()
3637 "Revert the buffer the cursor is on in the speedbar buffer." 3679 "Revert the buffer the cursor is on in the speedbar buffer."
3638 (interactive) 3680 (interactive)
3639 (save-excursion 3681 (save-excursion