blob: 0ffec25ab7921b35f5971a82b049f97fa72a4526 [file] [log] [blame]
Daniel Veillardc310d562000-06-23 18:32:15 +00001 ;;; libxml-doc.el - look up libxml-symbols and start browser on documentation
2
3;; Author: Felix Natter <fnatter@gmx.net>
4;; Created: Jun 21 2000
5;; Keywords: libxml documentation
6
Daniel Veillard8a367d42001-06-07 14:01:34 +00007;; 2001-05-31: Adapted by Geert Kloosterman <geertk@ai.rug.nl>
8
Daniel Veillardc310d562000-06-23 18:32:15 +00009;; This program is free software; you can redistribute it and/or
10;; modify it under the terms of the GNU General Public License
11;; as published by the Free Software Foundation; either version 2
12;; of the License, or (at your option) any later version.
13;;
14;; This program is distributed in the hope that it will be useful,
15;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;; GNU General Public License for more details.
18;;
19;; You should have received a copy of the GNU General Public License
20;; along with this program; if not, write to the Free Software
21;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23 ;;; Commentary / README
24
25;; these functions allow you to browse the libxml documentation
26;; (using lynx within emacs by default;
27;; ----- Installing
28;; 1. add the following to ~/.emacs (adapt path and remove comments !)
29;; (load ~/elisp/libxml-doc.el)
30;; you can also load this conditionally in a c-mode-hook (preferred)
31;;
32;;(add-hook 'c-mode-hook (lambda()
Daniel Veillard8a367d42001-06-07 14:01:34 +000033;; (load-file "~/elisp/libxml-doc.el")))
Daniel Veillardc310d562000-06-23 18:32:15 +000034;;
35;; or you can use this if you are using libxml2
36;;(add-hook 'c-mode-hook (lambda()
Daniel Veillard8a367d42001-06-07 14:01:34 +000037;; (save-excursion
38;; (if (search-forward "#include <libxml/" nil t nil)
39;; (load-file "~/elisp/libxml-doc.el"))
40;; )))
Daniel Veillardc310d562000-06-23 18:32:15 +000041;;
42;; 2. adapt libxmldoc-root:
43;; i.e. (setq libxmldoc-root "~/libxml2-2.0.0/doc/html/")
44;; 3. change the filter-regex: by default, cpp-defines, callbacks and
45;; html-functions are excluded (C-h v libxmldoc-filter-regexp)
46;; 4. consider customizing libxmldoc-browse-url (lynx by default);
47;; cannot use Emacs/W3 4.0pre46 because it has problems with the html
48;; ----- Using
49;; call M-x libxmldoc-lookup-symbol: this will prompt with completion
50;; and then open the browser showing the documentation. If the word
51;; around the point matches a symbol, that is used instead (no completion).
52
53 ;;; ChangeLog:
54;; Wed Jun 21 01:07:12 2000: initial release
55;; Wed Jun 21 01:45:29 2000: added libxmldoc-lookup-symbol-at-point
56;; Wed Jun 21 23:37:58 2000: libxmldoc-lookup-symbol now uses
57;; (thing-at-point 'word) if it matches a symbol
58;; Thu Jun 22 02:37:46 2000: filtering is only done for completion
59;; Thu Jun 22 21:03:41 2000: libxmldoc-browse-url can be customized
60
Daniel Veillard8a367d42001-06-07 14:01:34 +000061;; Thu May 31 2001 (Geert):
62;; - Changed the `gnome-xml-' html file prefix into `libxml-'.
63;; - Changed the 'word match from thing-at-point into 'symbol.
64;; With 'word, identifiers with an underscore (e.g. BAD_CAST)
65;; don't get matched.
66
67;; Sat Jun 02 2001 (Geert):
68;; - Cleaned up URI construction: no extraneous '/' in the URI when
69;; `libxmldoc-root' ends with a '/'.
70;; - Now keeps the list of symbols between calls to speed things up.
71;; Every filter gets it's own list of symbols. This way it's
72;; possible to use different values of `libxmldoc-filter-regexp' in
73;; different buffers.
74;; - Fixed symbols for function pointers: now skips '*' when
75;; fetching identifiers from the html files.
76
Daniel Veillardc310d562000-06-23 18:32:15 +000077;;; TODO:
78;; use command-execute for libxml-browse-url
79
80 ;;; Code:
81
82(defvar libxmldoc-root "~/libxml/www.xmlsoft.org"
83 "The root-directory of the libxml2-documentation (~ will be expanded).")
84(defvar libxmldoc-filter-regexp "^html\\|^\\*\\|^[A-Z_]+\\|^$"
85 "Symbols that match this regular expression will be excluded when doing
86completion.
87 For example:
88 callbacks: \"^\\\\*\"
89 cpp-defines: \"[A-Z_]+\"
90 xml-functions \"^xml\"
91 html-functions \"^html\"
92 sax-functions \".*SAX\"
93 By default, callbacks, cpp-defines and html* are excluded. If you redefine
94 this, you should include \"^$\" as alternative, which removes empty
95 tokens. i.e. removing \"^html\\\\|\" from the above regexp causes html* to
96 be shown.")
97(defvar libxmldoc-browse-url 'browse-url-lynx-emacs
98 "Browser used for browsing documentation. Emacs/W3 4.0pre46 cannot handle
99the html, so lynx-emacs is used by default.")
100(defvar libxmldoc-symbol-history nil
101 "History for looking up libxml-symbols.")
102
Daniel Veillard8a367d42001-06-07 14:01:34 +0000103;; GJK: Keep the results from libxmldoc-get-list-of-symbols between
104;; calls to speed things up.
105(defvar libxmldoc-symbols-alist nil
106 "Alist which stores a symbol list for each `libxmldoc-filter-regexp'. The
107never matching regex \"$^\" is used as key when no filtering is needed.")
108
Daniel Veillardc310d562000-06-23 18:32:15 +0000109 ;;;; public functions
110
111(defun libxmldoc-lookup-symbol(&optional symbol)
112 "Look up xml-symbol." (interactive)
113 (let ((symbols)
Daniel Veillard8a367d42001-06-07 14:01:34 +0000114 (real-symbol symbol)
115 (url)
116 ;; We don't want filtering when there's a symbol specified.
117 ;; Use the never matching regex "$^" as a key when using no filter.
118 (filter (if symbol "$^" libxmldoc-filter-regexp))
119 (no-filter (if symbol t nil)))
120
121 ;; Build up a symbol list if neccesary.
122 (if (not (assoc filter libxmldoc-symbols-alist))
123 (add-to-list 'libxmldoc-symbols-alist
124 (cons filter
125 (libxmldoc-get-list-of-symbols no-filter))))
126
127 ;; Use the appropriate symbol list.
128 (setq symbols (cdr (assoc filter libxmldoc-symbols-alist)))
129
130 (if (null real-symbol)
131 (if (assoc (thing-at-point 'symbol) symbols)
132 (setq real-symbol (thing-at-point 'symbol))
133 (setq real-symbol (completing-read "Libxml: " symbols nil t ""
134 'libxmldoc-symbol-history "" t))))
135 (if (null (assoc real-symbol symbols))
136 (error (concat "libxmldoc: '" real-symbol "' not found !")))
137 (setq url (cdr (assoc real-symbol symbols)))
138;; (minibuffer-message uri)
139 (apply libxmldoc-browse-url (list url))))
Daniel Veillardc310d562000-06-23 18:32:15 +0000140
141;;(defun libxmldoc-lookup-symbol-at-point()
142;; "Look up libxml-symbol at point." (interactive)
143;; (libxmldoc-lookup-symbol (thing-at-point 'word)))
144
145;;;; internal
146
147(defun libxmldoc-get-list-of-symbols(&optional nofilter)
148 "Get the list of html-links in the libxml-documentation."
149 (let ((files (directory-files libxmldoc-root t
Daniel Veillard8a367d42001-06-07 14:01:34 +0000150 "^libxml-.*\\.html$" t))
151 (symbols ())
152 (case-fold-search t)
153 (symbol)
154 (uri))
155;; (minibuffer-message "collecting libxml-symbols...")
156 (while (car files)
157 (find-file (car files))
158 (while (re-search-forward
159 "<a[^>]*href[ \t\n]*=[ \t\n]*\"\\([^=>]*\\)\"[^>]*>" nil t nil)
160 (setq uri (concat "file://"
161 (expand-file-name (match-string 1)
162 libxmldoc-root)))
163 (if (not (re-search-forward "\\([^<]*\\)<" nil t nil)) ; GJK: no '*'
164 (error "regexp error while finding libxml-symbols.."))
165 (setq symbol (match-string 1))
166 (setq case-fold-search nil)
167 (if (or nofilter
168 (null (string-match libxmldoc-filter-regexp symbol)))
169 (add-to-list 'symbols (cons symbol uri)))
170 (setq case-fold-search t)
171 )
172 (kill-buffer (current-buffer))
173 (setq files (cdr files)))
174 symbols))
Daniel Veillardc310d562000-06-23 18:32:15 +0000175
176;;; libxml-doc.el ends here
Daniel Veillard8a367d42001-06-07 14:01:34 +0000177
178;;; Local Variables:
179;;; indent-tabs-mode: nil
180;;; End: