From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Stewart Newsgroups: gmane.emacs.devel Subject: Integrate sr-speedbar.el with speedbar.el Date: Sat, 20 Dec 2008 00:44:11 +0800 Message-ID: <87abasw1wk.fsf@debian.domain> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1229705078 22424 80.91.229.12 (19 Dec 2008 16:44:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 19 Dec 2008 16:44:38 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Dec 19 17:45:43 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LDiTu-0006lr-G4 for ged-emacs-devel@m.gmane.org; Fri, 19 Dec 2008 17:45:43 +0100 Original-Received: from localhost ([127.0.0.1]:52978 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LDiSi-00067f-6L for ged-emacs-devel@m.gmane.org; Fri, 19 Dec 2008 11:44:28 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LDiSc-00067M-Fl for emacs-devel@gnu.org; Fri, 19 Dec 2008 11:44:22 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LDiSa-00067A-3z for emacs-devel@gnu.org; Fri, 19 Dec 2008 11:44:21 -0500 Original-Received: from [199.232.76.173] (port=34738 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LDiSZ-000677-Ue for emacs-devel@gnu.org; Fri, 19 Dec 2008 11:44:19 -0500 Original-Received: from ti-out-0910.google.com ([209.85.142.191]:42954) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LDiSY-0004qy-UT for emacs-devel@gnu.org; Fri, 19 Dec 2008 11:44:19 -0500 Original-Received: by ti-out-0910.google.com with SMTP id u5so716213tia.10 for ; Fri, 19 Dec 2008 08:44:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:subject:date :message-id:user-agent:mime-version:content-type; bh=SbZozwf1GINeeEezC2kj8EnWPzHWPBZ9kfRLZHsFwd8=; b=BfKQstjGr73RxnRvb81GmbExBY2+n3HJNnfrGNU/GcNjPeCUP50ddbADQTxySWF5oF IR3kMQ3KBN8PYe8q3/ohhvhlDlFWhRDRdMZfg69LGcjVke+WGeB8zLzCYkkhMaMMBrCv 236gLNYcV39gGdkf495lgV8aYpYA6KVJXZ750= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:user-agent:mime-version :content-type; b=AXcnwhQ1nuUyjFKK9OfdDgwCqCdygMI0J0Ro0Wn9z3h74dd8QS90rAllw/Ev32P6gi tVlL14KSb4nw7Z0PABcZODEWc2qDH2Bts/UPftLvGr2hOUTin+JL20f8XTQO2hdxHud1 eEDI7YeOh2E9YvW0UWY8p32DeCL9iIdyZoT00= Original-Received: by 10.110.39.20 with SMTP id m20mr3184126tim.12.1229705056786; Fri, 19 Dec 2008 08:44:16 -0800 (PST) Original-Received: from smtp.gmail.com ([222.212.142.186]) by mx.google.com with ESMTPS id 14sm5116502tim.30.2008.12.19.08.44.14 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 19 Dec 2008 08:44:15 -0800 (PST) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:107065 Archived-At: --=-=-= Hi all, Speedbar is very useful for file browser or other programming. But this have a big problem is, speedbar is show in other frame. So need switch between two frame, not very convenient. And have a exist extension sr-speedbar.el (write by "Sebastian Rose") can make speedbar show in same frame. Find it at: http://www.emacswiki.org/emacs/download/sr-speedbar.el I'm another developer of sr-speedbar. I have attached newest version of sr-speedbar. I want to integrate sr-speedbar with speedbar. "Sebastian Rose" and me were sign copyright of FSF. Any suggestion? -- Andy --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=sr-speedbar.el Content-Transfer-Encoding: quoted-printable Content-Description: sr-speedbar.el ;;; sr-speedbar.el --- Same frame speedbar ;; Author: Sebastian Rose ;; Maintainer: Sebastian Rose ;; Andy Stewart ;; Copyright (C) 2008, Sebastain Rose, all rights reserved. ;; Created: 2008 ;; Version: 0.0.7 ;; Last-Updated: 2008-12-17 21:58:59 ;; URL: http://www.emacswiki.org/emacs/download/sr-speedbar.el ;; Keywords: speedbar ;; Compatibility: GNU Emacs 23.0.60.1 ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth ;; Floor, Boston, MA 02110-1301, USA. ;; Features that might be requried by this library: ;; ;; `speedbar' ;; ;;; Installation: ;; ;; Copy sr-speedbar.el to your load-path and add to your ~/.emacs ;; ;; (require 'sr-speedbar) ;; (global-set-key (kbd "s-s") 'sr-speedbar-togge) ;; ;; ... or any key binding you like. ;; ;;; Commentary: ;; ;; The sr-speedbar.el was created just because I could not believe what I ;; read on http://www.emacswiki.org/cgi-bin/wiki/Speedbar. They wrote there ;; that it is not possible to show the speedbar in the same frame. But, as ;; we all know, ecb had this already. So I started as some kind of joke :) ;; But when I found it useful and use it all the time. ;; ;; Now you type windows key with 's' will show the speedbar in an extra win= dow, ;; same frame. Currently speedbar always shows up on the right. You can cus= tomize ;; the initial width of the speedbar window further down for console/DOS and ;; X/Win/MacOS seperatly. ;; ;; Enjoy! ;; ;;; Customize: ;; ;; `sr-speedbar-width-x' is the `sr-speedbar' window width under WINDOW sys= tem. ;; `sr-speedbar-width-console' is the `sr-speedbar' window width under CONS= OLE. ;; `sr-speedbar-delete-windows' whether delete other window before showing = up. ;; `sr-speedbar-skip-other-window-p' whether skip `sr-speedbar' window when= use ;; command `other-window' select window in cyclic ordering of windows. ;; ;; All above setup can customize by: ;; M-x customize-group RET sr-speedbar RET ;; ;;; Change log: ;; ;; * 17 Dec 2008 ;; * Andy Stewart: ;; * Add new option `sr-speedbar-skip-other-window-p' and new advice ;; for `other-window', make user skip select `sr-speedbar' window ;; when use command `other-window'. ;; * Fix the name of advice, make more clear. ;; * Fix the bug `sr-speedbar-select-window' when no live window exist. ;; * Fix doc. ;; ;; * 16 Dec 2008: ;; * Andy Stewart: ;; * Fix the bug of `sr-speedbar-refresh', use `default-directory' ;; get refresh directory instead through function in `dired'. ;; * Fix `window-live-p' bug, check window valid value before use ;; `window-live-p' test `sr-speedbar-window'. ;; * Fix `buffer-live-p' bug, check buffer valid value before use ;; `buffer-live-p' test `speedbar-buffer'. ;; * Add advice `pop-to-buffer' to make function `display-buffer' ;; can pop-up window when just have two windows (one is `sr-speedbar' ;; window) in current frame. ;; * Add group `sr-speedbar'. ;; More better customize interface through `customize-group'. ;; ;; * 28 SEP 2008: ;; * Andy Stewart: ;; * Fix a bug, when `sr-speedbar-toggle' many times, window width ;; will increment automatically. ;; * Use around advices replace, make code simple. ;; * Use `sr-speedbar-open' replace `sr-speedbar-no-separate-frame'. ;; * Clean up code. ;; ;; * 28 SEP 2008: ;; * Sebastian: ;; * set `sr-speedbar-delete-windows' to nil to avoid ;; the removal of other windows. ;; ;; * 26 JUN 2008: ;; * Sebastain: ;; * Added Andy Stewart's patch to refresh the speedbar's contents. ;; Thank's for this one! ;; ;; * Init: ;; * Sebastian: ;; * Added some lines to get it working: ;; * splitting the window and remember it, ;; * changing the way speedbar finds a file. ;; * File view of speedbar is now working all right. ;; * C-x 1 in other window deletes speedbar-window, just calling ;; M-x sr-speedbar-no-separate-frame again is fine now. ;; * Toggle speedbar works, width is save when toggeling. ;; * Recalc speedbar width if window-width - speedbar-width <=3D 0 ;; * Speedbar window is now dedicated to speedbar-buffer. ;; ;;; Acknowledgements: ;; ;; All emacsers ... :) ;; ;;; TODO ;; ;; ;; ;;; Require (require 'speedbar) ;;; Code: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Constant ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defconst sr-speedbar-version "0.0.7" "Current version") (defconst sr-speedbar-buffer-name "*SPEEDBAR*" "The buffer name of sr-speedbar.") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defvar sr-speedbar-width nil "Intial width of speedbar-window") (defvar sr-speedbar-window nil "Speedbar window") (defvar sr-speedbar-last-refresh-dictionary nil "The last refresh dictionary record of 'sr-speedbar-refresh'.") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Advices ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defadvice delete-other-windows (around sr-speedbar-delete-other-window-adv= ice activate) "This advice to make `sr-speedbar' window can't deleted by command `delete-other-windows'." (let (sr-speedbar-active-p) (if (and sr-speedbar-window (window-live-p sr-speedbar-window)) (setq sr-speedbar-active-p t)) ad-do-it (if sr-speedbar-active-p (sr-speedbar-open)))) (defadvice delete-window (around sr-speedbar-delete-window-advice activate) "This advice to make `sr-speedbar' window can't deleted by command `delete-window'." (let (sr-speedbar-active-p) (if (and sr-speedbar-window (window-live-p sr-speedbar-window)) (setq sr-speedbar-active-p t)) ad-do-it (when sr-speedbar-active-p (sr-speedbar-open) (message "Please use `sr-speedbar-toggle' to kill me!")))) (defadvice pop-to-buffer (before sr-speedbar-pop-to-buffer-advice activate) "Default, function `display-buffer' can't display buffer in select window if current window is `dedicated'. So function `display-buffer' conflict with `sr-speedbar' window, because `sr-speedbar' window is `dedicated' window. That is to say, when current frame just have two window: `sr-speedbar' wind= ow and another window, any functions that use `display-buffer' can't split win= dows to display buffer, even option `pop-up-windows' is enable. And the example function that can occur above problem is `pop-to-buffer'. This advice is to fix this problem when current frame just have `sr-speedba= r' window and another window." (when (and pop-up-windows ;`pop-up-windows' is enable (two-windows-p) ;just have two window in current fr= ame sr-speedbar-window (window-live-p sr-speedbar-window) ;and have one is `sr-speedb= ar' window. (not (equal sr-speedbar-buffer-name (buffer-name (window-buffe= r))))) ;not in `sr-speedbar' window (split-window-vertically) (windmove-down))) (defadvice other-window (after sr-speedbar-other-window-advice) "Default, can use `other-window' select window in cyclic ordering of wind= ows. But sometimes we don't want select `sr-speedbar' window use `other-window'. Just want make `sr-speedbar' window as a view sidebar. This advice can make `other-window' skip `sr-speedbar' window." (let ((count (ad-get-arg 0))) (when (and sr-speedbar-window (window-live-p sr-speedbar-window) (eq sr-speedbar-window (selected-window))) (other-window count)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; User Customization ;;;;;;;;;;;;;;;;;;;;;;;;;= ;;;;; (defgroup sr-speedbar nil "Same frame speedbar." :group 'speedbar) (defcustom sr-speedbar-width-x 24 "Initial width of sr-speedbar-window under window system." :type 'integer :group 'sr-speedbar) (defcustom sr-speedbar-width-console 24 "Initial width of sr-speedbar-window on console." :type 'integer :group 'sr-speedbar) (defcustom sr-speedbar-delete-windows nil "Allow the speedbar to delte other windows before showing up. If nil, speedbar will not touch your window configuration. Otherwise delete-other-windows will be called before showing the speedbar." :type 'boolean :group 'sr-speedbar) (defcustom sr-speedbar-skip-other-window-p nil "Default, can use `other-window' select window in cyclic ordering of wind= ows. But sometimes we don't want select `sr-speedbar' window use `other-window'. Just want make `sr-speedbar' window as a view sidebar. So please trun on this option if you want skip `sr-speedbar' window with `o= ther-window'. Default is nil." :type 'boolean :set (lambda (symbol value) (set symbol value) (if value (ad-enable-advice 'other-window 'after 'sr-speedbar-other-wind= ow-advice) (ad-disable-advice 'other-window 'after 'sr-speedbar-other-windo= w-advice)) (ad-activate 'other-window)) :group 'sr-speedbar) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive functions ;;;;;;;;;;;;;;;;;;;;;;= ;;;;;;;; (defun sr-speedbar-toggle () "Toggle visibility of sr-speedbar by resizing the sr-speedbar-window to a= minimal width or the last width when visible. Use this function to create or toggle visib= ility of a speedbar-window. It will be created if neccessary." (interactive) (if (and sr-speedbar-window speedbar-buffer (window-live-p sr-speedbar-window) ;when `sr-speedbar-window' vi= sible (buffer-live-p speedbar-buffer)) ;and contain `speedbar-buffer' (sr-speedbar-close) ;close `sr-speedbar' window (sr-speedbar-open) ;otherwise, open `sr-speedbar= ' window in same frame )) (defun sr-speedbar-open () "Create `sr-speedbar' window." (interactive) (let ((current-window (selected-window))) ;; Ensure only one window is there ;; when `sr-speedbar-delete-windows' is non-nil (if sr-speedbar-delete-windows (delete-other-windows)) ;; Skip `other-window' advice. (if sr-speedbar-skip-other-window-p (ad-enable-advice 'other-window 'after 'sr-speedbar-other-window-ad= vice) (ad-disable-advice 'other-window 'after 'sr-speedbar-other-window-adv= ice)) (ad-activate 'other-window) ;; Switch buffer (if (or (not speedbar-buffer) (not (buffer-live-p speedbar-buffer))) (progn (if (<=3D (current-window-take-width) sr-speedbar-width) ;if curr= ent window width is narrower than `sr-speedbar-width' (sr-speedbar-recalculate-width)) ;recalcula= te width of `sr-speedbar' (sr-speedbar-get-window) ;get `sr-speedbar' window that spli= t current window (setq speedbar-buffer (get-buffer-create sr-speedbar-buffer-name) speedbar-frame (selected-frame) dframe-attached-frame (selected-frame) speedbar-select-frame-method 'attached speedbar-verbosity-level 0 ;don't say anything, i don't lik= e ... :) speedbar-last-selected-file nil) (set-buffer speedbar-buffer) (buffer-disable-undo speedbar-buffer) ;make disable in speedbar b= uffer, otherwise will occur `undo-outer-limit' error (speedbar-mode) (speedbar-reconfigure-keymaps) (speedbar-update-contents) (speedbar-set-timer 1) (add-hook 'speedbar-before-visiting-file-hook 'sr-speedbar-before= -visiting-file-hook t) (add-hook 'speedbar-before-visiting-tag-hook 'sr-speedbar-before-= visiting-tag-hook t) (add-hook 'speedbar-visiting-file-hook 'sr-speedbar-visiting-file= -hook t) (add-hook 'speedbar-visiting-tag-hook 'sr-speedbar-visiting-tag-h= ook t) (add-hook 'kill-buffer-hook 'sr-speedbar-kill-buffer-hook) ;add `= kill-buffer-hook' ;; (make-local-hook 'kill-buffer-hook) ; depricated. uncomment fo= r emacs 21 ) (if (or (not sr-speedbar-window) (not (window-live-p sr-speedbar-window))) (sr-speedbar-get-window) ;get `sr-speedbar' window that spli= t current window )) (set-window-buffer sr-speedbar-window (get-buffer sr-speedbar-buffer-na= me)) (set-window-dedicated-p sr-speedbar-window t) ;make `sr-speedbar-window= ' dedicated to speedbar-buffer. (select-window current-window) (bury-buffer speedbar-buffer))) (defun sr-speedbar-close () "Close `sr-speedbar' window and save window width." (interactive) (let ((current-window (selected-window))) (sr-speedbar-select-window) (if (> (current-window-take-width) 1) ;if width of `sr-speedbar-window'= is a valid value (setq sr-speedbar-width (current-window-take-width))) ;remember it = make next restore same width (bury-buffer) (if (and current-window (window-live-p current-window)) (select-window current-window)))) (defun sr-speedbar-select-window () "Force the windows that contain `sr-speedbar'." (interactive) (if (and sr-speedbar-window (window-live-p sr-speedbar-window)) (select-window sr-speedbar-window) (message "No sr-speedbar window is exist."))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utils functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;= ;; (defun sr-speedbar-recalculate-width () "Calculate the speedbar width with respect of window system" (if (and window-system (not (string=3D "pc" window-system))) (setq sr-speedbar-width sr-speedbar-width-x) (setq sr-speedbar-width sr-speedbar-width-console))) (or sr-speedbar-width (sr-speedbar-recalculate-width)) ;init calculate-width (defun sr-speedbar-get-window () "Get `sr-speedbar' window." (setq sr-speedbar-window (split-window (selected-window) (- (current-window-take-width) sr-speedbar-widt= h) t))) (defun sr-speedbar-before-visiting-file-hook () "Function that hook `speedbar-before-visiting-file-hook'." (select-window (previous-window))) (defun sr-speedbar-before-visiting-tag-hook () "Function that hook `speedbar-before-visiting-tag-hook'." (select-window (previous-window))) (defun sr-speedbar-visiting-file-hook () "Function that hook `speedbar-visiting-file-hook'." (select-window (previous-window))) (defun sr-speedbar-visiting-tag-hook () "Function that hook `speedbar-visiting-tag-hook'." (select-window (previous-window))) (defun sr-speedbar-kill-buffer-hook () "Function that hook `kill-buffer-hook'." (when (eq (current-buffer) speedbar-buffer) (setq speedbar-frame nil dframe-attached-frame nil speedbar-buffer nil) (speedbar-set-timer nil) (remove-hook 'speedbar-before-visiting-file-hook 'sr-speedbar-before-vi= siting-file-hook) (remove-hook 'speedbar-before-visiting-tag-hook 'sr-speedbar-before-vis= iting-tag-hook) (remove-hook 'speedbar-visiting-file-hook 'sr-speedbar-visiting-file-ho= ok) (remove-hook 'speedbar-visiting-tag-hook 'sr-speedbar-visiting-tag-hook= ))) (defun sr-speedbar-refresh () "Refresh the context of speedbar." (when (and (not (equal default-directory sr-speedbar-last-refresh-diction= ary)) ;if directory is change (not (equal sr-speedbar-buffer-name (buffer-name (window-buffe= r))))) ;and is not in speedbar buffer (setq sr-speedbar-last-refresh-dictionary default-directory) (speedbar-refresh))) (add-hook 'speedbar-timer-hook 'sr-speedbar-refresh) ;automatic update cont= ext of speedbar, (defun current-window-take-width (&optional window) "Return the width that WINDOW take up, Not the value of `window-width', it return usable columns available for WIN= DOW. If WINDOW is nil, get current window." (let ((edges (window-edges window))) (- (nth 2 edges) (nth 0 edges)))) (defun two-windows-p () "Return non-nil if just have two window in current frame." (let ((base-window (selected-window)) next-base-window) (if (eq base-window (minibuffer-window)) ;select next window if in `min= ibuffer' (setq base-window (next-window base-window))) (setq next-base-window (next-window base-window)) (and (not (eq base-window next-base-window)) ;not just one wind= ow (eq base-window (next-window next-base-window)) ;two window equal = each other ))) (provide 'sr-speedbar) ;;; sr-speedbar.el ends here --=-=-=--