Source

ecb / ecb-speedbar.el

Diff from to

ecb-speedbar.el

-;;; ecb-speedbar.el --- 
+;;; ecb-speedbar.el --- Integration of speedbar into ECB
 
-;; $Id$
+;; Copyright (C) 2000 - 2003 Jesper Nordenberg,
+;;                           Klaus Berndl,
+;;                           Kevin A. Burton,
+;;                           Free Software Foundation, Inc.
 
-;; Copyright (C) 2000-2003 Free Software Foundation, Inc.
-;; Copyright (C) 2000-2003 Kevin A. Burton (burton@openprivacy.org)
-
-;; Author: Kevin A. Burton (burton@openprivacy.org)
-;;         Klaus berndl (klaus.berndl@sdm.de)
-;; Maintainer: Kevin A. Burton (burton@openprivacy.org)
-;;             Klaus berndl (klaus.berndl@sdm.de)
-;; Location: http://relativity.yi.org
-;; Keywords: 
-
-;; This file is [not yet] part of GNU Emacs.
+;; Author: Jesper Nordenberg <mayhem@home.se>
+;;         Klaus Berndl <klaus.berndl@sdm.de>
+;;         Kevin A. Burton <burton@openprivacy.org>
+;; Maintainer: Klaus Berndl <klaus.berndl@sdm.de>
+;;             Kevin A. Burton <burton@openprivacy.org>
+;; Keywords: browser, code, programming, tools
+;; Created: 2002
 
 ;; 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 of the License, or any later version.
-;;
+;; 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; if not, write to the Free Software Foundation, Inc., 59 Temple
-;; Place - Suite 330, Boston, MA 02111-1307, USA.
+;; GNU Emacs; see the file COPYING.  If not, write to the Free Software
+;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+;; $Id$
 
 ;;; Commentary:
 
 
 ;;; History:
 
-
-;; - Fri Jul 04 2003 5:28 PM (klaus.berndl@sdm.de): removed the
-;;   speedbar-version check because this is done now globally in ecb.el.
-;;
-;; - Mon Jun 23 2003 11:54 AM (klaus.berndl@sdm.de): Added speedbar-mechanism
-;;   for parsing files not supported by semantic but by imenu and/or etags.
-;;
-;; - Thu Dec 19 2002 6:54 PM (klaus.berndl@sdm.de): Full integrated in ECB and
-;;   fixed some bugs. Now the speedbar integration seems to work very well.
-;;
-;; - Sat Dec 15 2001 03:10 AM (burton@openprivacy.org): only sync up the eshell
-;;   if the current file is in a different dir than the speedbar.
-;;
-;; - Fri Dec 14 2001 10:11 PM (burton@openprivacy.org): when we hit <ENTER> on a
-;;   file in the speedbar window, a new window is created.
-;;
-;; - Sun Nov 18 2001 01:46 AM (burton@openprivacy.org): BUG: we need to set
-;;   dframe-activate-frame to the current frame and NOT use an invisible
-;;   frame. This is important because when I select a buffer in ECB it can't
-;;   use the invisible frame. :(
-;;
-;; - Sat Nov 10 2001 09:30 PM (burton@openprivacy.org): implementation of
-;;   ecb-delete-other-windows-in-editwindow-20
-
+;; For the ChangeLog of this file see the CVS-repository. For a complete
+;; history of the ECB-package see the file NEWS.
 
 ;;; Code:
 
   ;; Klaus Berndl <klaus.berndl@sdm.de>: We must use an around-advice because
   ;; we need exactly the information if the *clicked* item is a file or not.
   ;; This is only available before the original speedbar-click actions because
-  ;; speedbar seems to do some inteligent stuff like autom. using the first
+  ;; speedbar seems to do some intelligent stuff like autom. using the first
   ;; file if a clicked directory contains any.
   (let ((item (and (fboundp 'speedbar-line-file)
                    (speedbar-line-file))))
     ad-do-it
-    (if (and (equal (selected-frame) ecb-frame)
+    (if (and ecb-minor-mode
+             (equal (selected-frame) ecb-frame)
              (window-live-p (get-buffer-window ecb-speedbar-buffer-name))
              (and item
                   (file-exists-p item)
 
 (defadvice speedbar-frame-mode (around ecb)
   "During running speedbar within ECB this command is disabled!"
-  (message "This command is disabled during running speedbar within ECB!"))
+  (if ecb-minor-mode
+      (message "This command is disabled during running speedbar within ECB!")
+    ad-do-it))
 
 
 (defadvice speedbar-get-focus (around ecb)
 Change window focus to or from the ECB-speedbar-window. If the selected window
 is not speedbar-window, then the speedbar-window is selected. If the
 speedbar-window is active, then select the edit-window."
-  (if (equal (current-buffer) (get-buffer ecb-speedbar-buffer-name))
-      (ecb-select-edit-window)
-    (ecb-speedbar-select-speedbar-window)))
+  (if ecb-minor-mode
+      (if (equal (current-buffer) (get-buffer ecb-speedbar-buffer-name))
+          (ecb-select-edit-window)
+        (ecb-speedbar-select-speedbar-window))
+    ad-do-it))
 
 ;; Klaus Berndl <klaus.berndl@sdm.de>: This implementation is done to make
 ;; clear where the bug is fixed...a better impl. can be seen in
     (mouse-set-point e)))
   
 
-(defun ecb-speedbar-enable-advices ()
-  (dolist (elem ecb-speedbar-adviced-functions)
-    (ad-enable-advice (car elem) (cdr elem) 'ecb)
-    (ad-activate (car elem))))
-
-(defun ecb-speedbar-disable-advices ()
-  (dolist (elem ecb-speedbar-adviced-functions)
-    (ad-disable-advice (car elem) (cdr elem) 'ecb)
-    (ad-activate (car elem))))
-
 (defconst ecb-speedbar-buffer-name " SPEEDBAR"
   "Name of the ECB speedbar buffer.")
 
 (defvar ecb-speedbar-select-frame-method-old nil)
 
 (defun ecb-speedbar-activate()
-  "Make sure the speedbar is running. WARNING: This could be dependend on the
+  "Make sure the speedbar is running. WARNING: This could be dependent on the
 current speedbar implementation but normally it should work with recent
 speedbar versions >= 0.14beta1. But be aware: If the speedbar impl changes in
 future this could break."
 
   ;; enable the advices for speedbar
-  (ecb-speedbar-enable-advices)
+  (ecb-enable-advices ecb-speedbar-adviced-functions)
   
   ;;disable automatic speedbar updates... let the ECB handle this with
   ;;ecb-current-buffer-sync
 
 (defun ecb-speedbar-deactivate ()
   "Reset things as before activating speedbar by ECB"
-  (ecb-speedbar-disable-advices)
+  (ecb-disable-advices ecb-speedbar-adviced-functions)
   
   (setq speedbar-frame nil)
   (setq dframe-attached-frame nil)
   (speedbar-update-contents))
 
 (defun ecb-speedbar-current-buffer-sync()
-  "Update the speedbar so that we sync up with the current file."
+  "Update the speedbar so that it's synced up with the current file."
   (interactive)
 
   ;;only operate if the current frame is the ECB frame and the
 ;; semantic-grammar available) but which can be parsed by imenu and/or etags
 ;; via speedbar.
 
+(defun ecb-speedbar-sb-token-p (token)
+  "Return not nil if TOKEN is a semantic-token generated from a speedbar tag."
+  (semantic-token-get token 'ecb-speedbar-token))
+
 (require 'tree-buffer)
 (require 'ecb-face)
 (defun ecb-create-non-semantic-tree (node tag-list)
 called recursive for the elements of a group.
 
 Return NODE."
-  (let ((new-node nil))
+  (let ((new-node nil)
+        (new-token nil))
     (dolist (tag tag-list)
       (cond ((null tag) nil)            ;this would be a separator
             ((speedbar-generic-list-tag-p tag)
+             ;; the semantic token for this tag
+             (setq new-token (list (car tag)
+                                   (intern (car tag))
+                                   nil nil nil
+                                   (make-vector 2 (cdr tag))))
+             (semantic-token-put new-token 'ecb-speedbar-token t)
              (tree-node-new (progn
                               (set-text-properties
                                0 (length (car tag))
                                `(face ,ecb-method-non-semantic-face) (car tag))
                               (car tag))
                             0
-                            (list (car tag)
-                                  (intern (car tag))
-                                  nil nil nil
-                                  (make-vector 2 (cdr tag)))
+                            new-token
                             t
                             node))
             ((speedbar-generic-list-positioned-group-p tag)
+             ;; the semantic token for this tag
+             (setq new-token (list (car tag)
+                                   (intern (car tag))
+                                   nil nil nil
+                                   (make-vector 2 (car (cdr tag)))))
+             (semantic-token-put new-token 'ecb-speedbar-token t)
              (ecb-create-non-semantic-tree
               (setq new-node
                     (tree-node-new (progn
                                       `(face ,ecb-method-non-semantic-face) (car tag))
                                      (car tag))
                                    0
-                                   (list (car tag)
-                                         (intern (car tag))
-                                         nil nil nil
-                                         (make-vector 2 (car (cdr tag))))
+                                   new-token
                                    nil node))
               (cdr (cdr tag)))
              (tree-node-set-expanded new-node