Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 1 | ;;; libxml-doc.el - look up libxml-symbols and start browser on documentation |
Daniel Veillard | c310d56 | 2000-06-23 18:32:15 +0000 | [diff] [blame] | 2 | |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 3 | ;; Author: Felix Natter <fnatter@gmx.net>, Geert Kloosterman <geertk@ai.rug.nl> |
Daniel Veillard | c310d56 | 2000-06-23 18:32:15 +0000 | [diff] [blame] | 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 !) |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 27 | ;; (autoload 'libxmldoc-lookup-symbol "~/elisp/libxml-doc" |
| 28 | ;; "Look up libxml-symbols and start browser on documentation." t) |
| 29 | ;; or put this file in load-path and use this: |
| 30 | ;; (autoload 'libxmldoc-lookup-symbol "libxml-doc" |
| 31 | ;; "Look up libxml-symbols and start browser on documentation." t) |
Daniel Veillard | c310d56 | 2000-06-23 18:32:15 +0000 | [diff] [blame] | 32 | ;; 2. adapt libxmldoc-root: |
| 33 | ;; i.e. (setq libxmldoc-root "~/libxml2-2.0.0/doc/html/") |
| 34 | ;; 3. change the filter-regex: by default, cpp-defines, callbacks and |
| 35 | ;; html-functions are excluded (C-h v libxmldoc-filter-regexp) |
| 36 | ;; 4. consider customizing libxmldoc-browse-url (lynx by default); |
| 37 | ;; cannot use Emacs/W3 4.0pre46 because it has problems with the html |
| 38 | ;; ----- Using |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 39 | ;; call M-x libxmldoc-lookup-symbol: this will prompt with completion and |
| 40 | ;; then open the browser showing the documentation. If the word around the |
| 41 | ;; point matches a symbol, that is used instead. You can also call |
| 42 | ;; libxmldoc-lookup-symbol noninteractively and pass the symbol. |
| 43 | |
| 44 | ;; Note: |
| 45 | ;; an alternative to libxml-doc is emacs tags: |
| 46 | ;; $ cd libxml2-2.3.8 |
| 47 | ;; $ etags *.c *.h |
| 48 | ;; $ emacs |
| 49 | ;; M-. (M-x find-tag) ... or |
| 50 | ;; M-x tags-search ... RET M-, M-, ... |
| 51 | ;; (for more information: info emacs RET m Tags RET) |
| 52 | |
Daniel Veillard | c310d56 | 2000-06-23 18:32:15 +0000 | [diff] [blame] | 53 | |
| 54 | ;;; ChangeLog: |
| 55 | ;; Wed Jun 21 01:07:12 2000: initial release |
| 56 | ;; Wed Jun 21 01:45:29 2000: added libxmldoc-lookup-symbol-at-point |
| 57 | ;; Wed Jun 21 23:37:58 2000: libxmldoc-lookup-symbol now uses |
| 58 | ;; (thing-at-point 'word) if it matches a symbol |
| 59 | ;; Thu Jun 22 02:37:46 2000: filtering is only done for completion |
| 60 | ;; Thu Jun 22 21:03:41 2000: libxmldoc-browse-url can be customized |
| 61 | |
Daniel Veillard | 8a367d4 | 2001-06-07 14:01:34 +0000 | [diff] [blame] | 62 | ;; Thu May 31 2001 (Geert): |
| 63 | ;; - Changed the `gnome-xml-' html file prefix into `libxml-'. |
| 64 | ;; - Changed the 'word match from thing-at-point into 'symbol. |
| 65 | ;; With 'word, identifiers with an underscore (e.g. BAD_CAST) |
| 66 | ;; don't get matched. |
| 67 | |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 68 | ;; Fri Jun 8 16:29:18 2001, Sat Jun 23 16:19:47 2001: |
| 69 | ;; complete rewrite of libxmldoc-lookup-symbol |
| 70 | ;; by Felix Natter <fnatter@gmx.net>, Geert Kloosterman <geertk@ai.rug.nl>: |
Daniel Veillard | 8a367d4 | 2001-06-07 14:01:34 +0000 | [diff] [blame] | 71 | ;; - Now keeps the list of symbols between calls to speed things up. |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 72 | ;; - filtering is only used when no symbol is passed and |
| 73 | ;; thing-at-point does not match a symbol and "*" + thing-at-point |
| 74 | ;; does not match a symbol (this is used to catch callbacks) and |
| 75 | ;; libxmldoc-filter-regexp is non-nil. |
| 76 | ;; Sat Jun 23 16:20:34 2001: update the docstrings |
| 77 | ;; Sat Jun 23 16:22:54 2001 (Geert Kloosterman <geertk@ai.rug.nl>): |
| 78 | ;; update README: use autoload instead of load+c-mode-hook |
Daniel Veillard | 8a367d4 | 2001-06-07 14:01:34 +0000 | [diff] [blame] | 79 | |
Daniel Veillard | c310d56 | 2000-06-23 18:32:15 +0000 | [diff] [blame] | 80 | ;;; TODO: |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 81 | ;; - use command-execute for libxmldoc-browse-url |
| 82 | ;; - keep (match-string 1) in a variable (libxmldoc-get-list-of-symbols) |
| 83 | ;; - check the (require ..)-statements |
Daniel Veillard | c310d56 | 2000-06-23 18:32:15 +0000 | [diff] [blame] | 84 | |
| 85 | ;;; Code: |
| 86 | |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 87 | (provide 'libxmldoc) |
| 88 | |
| 89 | (require 'browse-url) |
| 90 | (require 'term) |
| 91 | |
| 92 | (defvar libxmldoc-root "~/src/libxml2-2.3.8/doc/html" |
Daniel Veillard | c310d56 | 2000-06-23 18:32:15 +0000 | [diff] [blame] | 93 | "The root-directory of the libxml2-documentation (~ will be expanded).") |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 94 | (defvar libxmldoc-filter-regexp "^html\\|^\\*\\|^[A-Z_]+" |
Daniel Veillard | c310d56 | 2000-06-23 18:32:15 +0000 | [diff] [blame] | 95 | "Symbols that match this regular expression will be excluded when doing |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 96 | completion and no symbol is specified. |
Daniel Veillard | c310d56 | 2000-06-23 18:32:15 +0000 | [diff] [blame] | 97 | For example: |
| 98 | callbacks: \"^\\\\*\" |
| 99 | cpp-defines: \"[A-Z_]+\" |
| 100 | xml-functions \"^xml\" |
| 101 | html-functions \"^html\" |
| 102 | sax-functions \".*SAX\" |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 103 | By default, callbacks, cpp-defines and html* are excluded. |
| 104 | Set this to nil if you don't want filtering.") |
Daniel Veillard | c310d56 | 2000-06-23 18:32:15 +0000 | [diff] [blame] | 105 | (defvar libxmldoc-browse-url 'browse-url-lynx-emacs |
| 106 | "Browser used for browsing documentation. Emacs/W3 4.0pre46 cannot handle |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 107 | the html (and would be too slow), so lynx-emacs is used by default.") |
Daniel Veillard | c310d56 | 2000-06-23 18:32:15 +0000 | [diff] [blame] | 108 | (defvar libxmldoc-symbol-history nil |
| 109 | "History for looking up libxml-symbols.") |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 110 | (defvar libxmldoc-symbols nil |
| 111 | "The list of libxml-symbols.") |
Daniel Veillard | 8a367d4 | 2001-06-07 14:01:34 +0000 | [diff] [blame] | 112 | |
Daniel Veillard | c310d56 | 2000-06-23 18:32:15 +0000 | [diff] [blame] | 113 | ;;;; public functions |
| 114 | |
| 115 | (defun libxmldoc-lookup-symbol(&optional symbol) |
| 116 | "Look up xml-symbol." (interactive) |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 117 | (let |
| 118 | ;; this is necessary so that filtering is done case-sensitively |
| 119 | ((case-fold-search nil)) |
Daniel Veillard | 8a367d4 | 2001-06-07 14:01:34 +0000 | [diff] [blame] | 120 | |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 121 | ;; Build up a symbol list if neccesary |
| 122 | (if (null libxmldoc-symbols) |
| 123 | (setq libxmldoc-symbols (libxmldoc-get-list-of-symbols))) |
| 124 | |
| 125 | (cond |
| 126 | ((not (null symbol)) ;; symbol is specified as argument |
| 127 | (if (not (assoc symbol libxmldoc-symbols)) |
| 128 | (setq symbol nil))) |
| 129 | ((assoc (thing-at-point 'symbol) libxmldoc-symbols) |
| 130 | (setq symbol (thing-at-point 'symbol))) |
| 131 | ;; this is needed to catch callbacks |
| 132 | ;; note: this could be rewritten to use (thing-at-point 'word) |
| 133 | ((assoc (concat "*" (thing-at-point 'symbol)) libxmldoc-symbols) |
| 134 | (setq symbol (concat "*" (thing-at-point 'symbol)))) |
| 135 | ) |
Daniel Veillard | 8a367d4 | 2001-06-07 14:01:34 +0000 | [diff] [blame] | 136 | |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 137 | ;; omit "" t) from call to completing-read for the sake of xemacs |
| 138 | (setq symbol |
| 139 | (completing-read "Libxml: " (if (or symbol |
| 140 | (null libxmldoc-filter-regexp)) |
| 141 | libxmldoc-symbols |
| 142 | (mapcar |
| 143 | '(lambda(key,value) |
| 144 | (if (null (string-match |
| 145 | libxmldoc-filter-regexp |
| 146 | (car key,value))) |
| 147 | key,value)) |
| 148 | libxmldoc-symbols)) |
| 149 | nil t symbol |
| 150 | 'libxmldoc-symbol-history)) |
| 151 | |
| 152 | |
| 153 | ;; start browser |
| 154 | (apply libxmldoc-browse-url |
| 155 | (list (cdr (assoc symbol libxmldoc-symbols)))))) |
Daniel Veillard | c310d56 | 2000-06-23 18:32:15 +0000 | [diff] [blame] | 156 | |
| 157 | ;;;; internal |
| 158 | |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 159 | (defun libxmldoc-get-list-of-symbols() |
Daniel Veillard | c310d56 | 2000-06-23 18:32:15 +0000 | [diff] [blame] | 160 | "Get the list of html-links in the libxml-documentation." |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 161 | (let ((files |
| 162 | (directory-files |
| 163 | libxmldoc-root t |
| 164 | (concat "^" (if (file-exists-p (concat libxmldoc-root |
| 165 | "/libxml-parser.html")) |
| 166 | "libxml-" |
| 167 | "gnome-xml-") |
| 168 | ".*\\.html$") t)) |
Daniel Veillard | 8a367d4 | 2001-06-07 14:01:34 +0000 | [diff] [blame] | 169 | (symbols ()) |
| 170 | (case-fold-search t) |
Daniel Veillard | 8a367d4 | 2001-06-07 14:01:34 +0000 | [diff] [blame] | 171 | (uri)) |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 172 | (message "collecting libxml-symbols...") |
Daniel Veillard | 8a367d4 | 2001-06-07 14:01:34 +0000 | [diff] [blame] | 173 | (while (car files) |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 174 | (with-temp-buffer |
| 175 | (insert-file-contents (car files)) |
| 176 | (goto-char (point-min)) |
| 177 | (while (re-search-forward |
| 178 | "<a[^>]*href[ \t\n]*=[ \t\n]*\"\\([^=>]*\\)\"[^>]*>" nil t nil) |
| 179 | (setq uri (concat "file://" (expand-file-name libxmldoc-root) "/" |
| 180 | (match-string 1))) |
| 181 | (if (not (re-search-forward "\\([^<]*\\)<" nil t nil)) |
| 182 | (error "regexp error while getting libxml-symbols..")) |
| 183 | ;; this needs add-to-list because i.e. xmlChar appears often |
| 184 | (if (not (string-equal "" (match-string 1))) |
| 185 | (add-to-list 'symbols (cons (match-string 1) uri)))) |
| 186 | ;; (setq symbols (cons (cons (match-string 1) uri) symbols))) |
| 187 | ) |
| 188 | (setq files (cdr files))) |
| 189 | symbols)) |
Daniel Veillard | c310d56 | 2000-06-23 18:32:15 +0000 | [diff] [blame] | 190 | |
| 191 | ;;; libxml-doc.el ends here |
Daniel Veillard | ca98976 | 2001-06-23 17:39:29 +0000 | [diff] [blame^] | 192 | |
Daniel Veillard | 8a367d4 | 2001-06-07 14:01:34 +0000 | [diff] [blame] | 193 | ;;; Local Variables: |
| 194 | ;;; indent-tabs-mode: nil |
| 195 | ;;; End: |