blob: 764286425c5f1d65e543de830f461bd6fed2015f [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
7;; This program is free software; you can redistribute it and/or
8;; modify it under the terms of the GNU General Public License
9;; as published by the Free Software Foundation; either version 2
10;; of the License, or (at your option) any later version.
11;;
12;; This program is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16;;
17;; You should have received a copy of the GNU General Public License
18;; along with this program; if not, write to the Free Software
19;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 ;;; Commentary / README
22
23;; these functions allow you to browse the libxml documentation
24;; (using lynx within emacs by default;
25;; ----- Installing
26;; 1. add the following to ~/.emacs (adapt path and remove comments !)
27;; (load ~/elisp/libxml-doc.el)
28;; you can also load this conditionally in a c-mode-hook (preferred)
29;;
30;;(add-hook 'c-mode-hook (lambda()
31;; (load-file "~/elisp/libxml-doc.el")))
32;;
33;; or you can use this if you are using libxml2
34;;(add-hook 'c-mode-hook (lambda()
35;; (save-excursion
36;; (if (search-forward "#include <libxml/" nil t nil)
37;; (load-file "~/elisp/libxml-doc.el"))
38;; )))
39;;
40;; 2. adapt libxmldoc-root:
41;; i.e. (setq libxmldoc-root "~/libxml2-2.0.0/doc/html/")
42;; 3. change the filter-regex: by default, cpp-defines, callbacks and
43;; html-functions are excluded (C-h v libxmldoc-filter-regexp)
44;; 4. consider customizing libxmldoc-browse-url (lynx by default);
45;; cannot use Emacs/W3 4.0pre46 because it has problems with the html
46;; ----- Using
47;; call M-x libxmldoc-lookup-symbol: this will prompt with completion
48;; and then open the browser showing the documentation. If the word
49;; around the point matches a symbol, that is used instead (no completion).
50
51 ;;; ChangeLog:
52;; Wed Jun 21 01:07:12 2000: initial release
53;; Wed Jun 21 01:45:29 2000: added libxmldoc-lookup-symbol-at-point
54;; Wed Jun 21 23:37:58 2000: libxmldoc-lookup-symbol now uses
55;; (thing-at-point 'word) if it matches a symbol
56;; Thu Jun 22 02:37:46 2000: filtering is only done for completion
57;; Thu Jun 22 21:03:41 2000: libxmldoc-browse-url can be customized
58
59;;; TODO:
60;; use command-execute for libxml-browse-url
61
62 ;;; Code:
63
64(defvar libxmldoc-root "~/libxml/www.xmlsoft.org"
65 "The root-directory of the libxml2-documentation (~ will be expanded).")
66(defvar libxmldoc-filter-regexp "^html\\|^\\*\\|^[A-Z_]+\\|^$"
67 "Symbols that match this regular expression will be excluded when doing
68completion.
69 For example:
70 callbacks: \"^\\\\*\"
71 cpp-defines: \"[A-Z_]+\"
72 xml-functions \"^xml\"
73 html-functions \"^html\"
74 sax-functions \".*SAX\"
75 By default, callbacks, cpp-defines and html* are excluded. If you redefine
76 this, you should include \"^$\" as alternative, which removes empty
77 tokens. i.e. removing \"^html\\\\|\" from the above regexp causes html* to
78 be shown.")
79(defvar libxmldoc-browse-url 'browse-url-lynx-emacs
80 "Browser used for browsing documentation. Emacs/W3 4.0pre46 cannot handle
81the html, so lynx-emacs is used by default.")
82(defvar libxmldoc-symbol-history nil
83 "History for looking up libxml-symbols.")
84
85 ;;;; public functions
86
87(defun libxmldoc-lookup-symbol(&optional symbol)
88 "Look up xml-symbol." (interactive)
89 (let ((symbols)
90 (real-symbol symbol)
91 (url))
92 (if symbol
93 (setq symbols (libxmldoc-get-list-of-symbols t))
94 (setq symbols (libxmldoc-get-list-of-symbols nil)))
95 (if (null real-symbol)
96 (if (assoc (thing-at-point 'word) symbols)
97 (setq real-symbol (thing-at-point 'word))
98 (setq real-symbol (completing-read "Libxml: " symbols nil t ""
99 'libxmldoc-symbol-history "" t))))
100 (if (null (assoc real-symbol symbols))
101 (error (concat "libxmldoc: '" real-symbol "' not found !")))
102 (setq url (cdr (assoc real-symbol symbols)))
103;; (minibuffer-message uri)
104 (apply libxmldoc-browse-url (list url))))
105
106;;(defun libxmldoc-lookup-symbol-at-point()
107;; "Look up libxml-symbol at point." (interactive)
108;; (libxmldoc-lookup-symbol (thing-at-point 'word)))
109
110;;;; internal
111
112(defun libxmldoc-get-list-of-symbols(&optional nofilter)
113 "Get the list of html-links in the libxml-documentation."
114 (let ((files (directory-files libxmldoc-root t
115 "^gnome-xml-.*\\.html$" t))
116 (symbols ())
117 (case-fold-search t)
118 (symbol)
119 (uri))
120;; (minibuffer-message "collecting libxml-symbols...")
121 (while (car files)
122 (find-file (car files))
123 (while (re-search-forward
124 "<a[^>]*href[ \t\n]*=[ \t\n]*\"\\([^=>]*\\)\"[^>]*>" nil t nil)
125 (setq uri (concat "file://" (expand-file-name libxmldoc-root) "/"
126 (match-string 1)))
127 (if (not (re-search-forward "\\([^<]*\\)<" nil t nil))
128 (error "regexp error while finding libxml-symbols.."))
129 (setq symbol (match-string 1))
130 (setq case-fold-search nil)
131 (if (or nofilter
132 (null (string-match libxmldoc-filter-regexp symbol)))
133 (add-to-list 'symbols (cons symbol uri)))
134 (setq case-fold-search t)
135 )
136 (kill-buffer (current-buffer))
137 (setq files (cdr files)))
138 symbols))
139
140;;; libxml-doc.el ends here