Initial Commit
[packages] / xemacs-packages / speedbar / sb-ant.el
1 ;;; sb-ant.el --- provide speedbar menus for ANT Project files
2
3 ;; Copyright (c) 2001, 2003 Ole Arndt
4 ;; Author: Ole Arndt <arndt@tivano.com>
5 ;; based on sb-html.el by:
6 ;; Created: Tue Sep 09 09:45:00 2001
7
8 ;; Copyright (c) 2001 Richard Y. Kim
9 ;; Author: Richard Y. Kim, <ryk@dspwiz.com>
10 ;; Maintainer: Richard Y. Kim, <ryk@dspwiz.com>
11 ;; Created: Mon Apr 09 09:44:06 2001
12 ;; Version: $Id: sb-ant.el,v 1.3 2005/09/30 20:25:50 zappo Exp $
13 ;; Keywords: speedbar, html
14
15 ;; This program is free software; you can redistribute it and/or
16 ;; modify it under the terms of the GNU General Public License as
17 ;; published by the Free Software Foundation; either version 2 of
18 ;; the License, or (at your option) any later version.
19
20 ;; This program is distributed in the hope that it will be
21 ;; useful, but WITHOUT ANY WARRANTY; without even the implied
22 ;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
23 ;; PURPOSE.  See the GNU General Public License for more details.
24
25 ;; You should have received a copy of the GNU General Public
26 ;; License along with this program; if not, write to the Free
27 ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
28 ;; MA 02110-1301 USA
29
30 ;; This small add-on to speedbar provides an alternate way to view ANT
31 ;; project files. It simply lists all the available targets.
32 ;;
33 ;; This code is a simple modification of sb-html.el which comes
34 ;; with speedbar.
35
36 ;; Installation procedure:
37 ;;
38 ;;   Install speedbar 0.12 or later.
39 ;;   Add the following to your ~/.emacs file:
40 ;;   (eval-after-load "speedbar" '(load-library "sb-ant"))
41 ;;
42
43 ;;; Code:
44
45 (require 'speedbar)
46 (require 'sb-texinfo)   ; for speedbar-format-texinfo-list
47
48 ;; Attach these new functions to handle texinfo-mode.
49 (add-to-list 'speedbar-dynamic-tags-function-list
50              '(speedbar-fetch-dynamic-ant-project . speedbar-insert-ant-project-list))
51
52 ;; This returns t if the major mode of the current buffer is not
53 ;; 'xml-mode. If it is 'xml-mode, then this returns a
54 ;; list where each element is (LEVEL TARGETNAME . MARKER). 
55 ;; LEVLE is always 0,  NAME is the name of the target. MARKER is
56 ;; emacs marker that points to the beginning of the section. The
57 ;; elements in the list returned are in ascending order of the
58 ;; MARKER. This function along with it's parter,
59 ;; speedbar-insert-ant-project-list, are designed to be added to the
60 ;; speedbar-dynamic-tags-function-list list.
61 ;;
62 ;; This function is based on `speedbar-fetch-dynamic-html'.
63 (defun speedbar-fetch-dynamic-ant-project ( filename )
64   (set-buffer (find-file-noselect filename))
65   (if (not (or (eq major-mode 'xml-mode)
66                (eq major-mode 'sgml-mode)
67                (eq major-mode 'ant-mode)))
68       t
69     (condition-case nil
70         (save-excursion
71
72           ;; Set speedbar-tag-hierarchy-method to nil so that
73           ;; speedbar-create-tag-hierarchy won't reorder the list.
74           ;; Make it buffer local so that the global value is not touched.
75           (make-local-variable 'speedbar-tag-hierarchy-method)
76           (setq speedbar-tag-hierarchy-method nil)
77
78           (set (make-local-variable
79                 'speedbar-generic-list-group-expand-button-type)
80                'expandtag)
81           (set (make-local-variable
82                 'speedbar-generic-list-tag-button-type)
83                'statictag)
84
85           (let ((case-fold-search t)    ; ant tags are case insensitive
86                 pos-beg title level alist beg)
87             (goto-char (point-min))
88             ;; regexp below will not work if `>' appears within an attribute
89             ;; value, e.g., <h1 foo="I'm a weird value >"> ... </h1>
90             (while (re-search-forward "<target[^>]*name\\s-*=\\s-*\"\\([^\"]*\\)\"[^>]*>" nil t)
91               (setq beg (match-end 0))
92               (goto-char (match-beginning 0))
93               (setq pos-beg (point-marker))
94               (setq level 0)
95               (setq title (match-string 1))
96               (re-search-forward (concat "</target" ""))
97               (setq alist (cons (cons level (cons title pos-beg)) alist)))
98             (nreverse alist)))
99       (error t))))
100
101 (fset 'speedbar-format-ant-project-list 'speedbar-format-texinfo-list)
102
103 (defun speedbar-insert-ant-project-list (indent lst)
104   (speedbar-insert-generic-list indent (speedbar-format-ant-project-list lst indent)
105                                 'speedbar-tag-expand
106                                 'speedbar-tag-find))
107
108 (provide 'sb-ant)
109
110 ;;; sb-ant.el ends here