1 ;;; octave-hlp.el --- getting help on Octave symbols using info
3 ;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 ;; Free Software Foundation, Inc.
6 ;; Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
7 ;; Author: John Eaton <jwe@bevo.che.wisc.edu>
8 ;; Maintainer: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 3, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
30 ;; Provides the command `octave-help' which allows index lookup of a
31 ;; symbol in the Octave-related info files, as specified by the list
32 ;; `octave-help-files'.
34 ;; Other features may be added in future versions.
41 (defvar octave-help-files
'("octave")
42 "List of info files with documentation for Octave.
43 Default is (\"octave\").")
45 (defvar octave-help-lookup-alist nil
46 "Alist of Octave index entries for lookup.")
48 (defvar octave-help-completion-alist nil
49 "Alist of Octave index entries for completion.
50 The entries are of the form (VAR . VAR), where VAR runs through all
51 different keys in `octave-help-lookup-alist'.")
54 (defun octave-help (key)
55 "Get help on Octave symbols from the Octave info files.
56 Look up KEY in the function, operator and variable indices of the files
57 specified by `octave-help-files'.
58 If KEY is not a string, prompt for it with completion."
61 (completing-read (format "Describe Octave symbol: ")
62 (octave-help-get-completion-alist)
64 (if (get-buffer "*info*")
65 (set-buffer "*info*"))
66 (if (zerop (length key
))
67 (Info-find-node (car octave-help-files
) "Top")
68 (let ((alist (copy-alist (octave-help-get-lookup-alist)))
70 (while (setq entry
(car alist
))
71 (if (string-match key
(car entry
))
72 (add-to-list 'matches entry
))
73 (setq alist
(cdr alist
)))
76 (setq Info-index-alternatives matches
)
77 (Info-index-next 0))))))
79 (defun octave-help-get-lookup-alist ()
80 "Build the index lookup alist from all Octave info files.
81 The files specified by `octave-help-files' are searched."
82 (if octave-help-lookup-alist
84 (message "Building help lookup alist...")
85 (let ((files octave-help-files
) file key node
)
86 (save-window-excursion
88 (setq file
(car files
))
89 (Info-goto-node (concat "(" file
")"))
95 (while (re-search-forward
96 "^\\* \\([^(:]+\\)[^:]*: *\\(.+\\)\\.$"
98 (setq key
(match-string 1)
99 node
(concat "(" file
")" (match-string 2)))
100 (and (string-match "\\(.*\\>\\) *$" key
)
101 (setq key
(replace-match "\\1" t nil key
)))
102 (add-to-list 'octave-help-lookup-alist
105 (concat (concat "(" file
")")
108 (and (setq node
(Info-extract-pointer "next" t
))
110 (concat "\\(Function\\|Operator\\|Variable\\) "
113 (Info-goto-node node
)))
115 (setq files
(cdr files
)))))
116 (message "Building help lookup alist...done"))
117 octave-help-lookup-alist
)
119 (defun octave-help-get-completion-alist ()
120 "Build the index completion alist from all Octave info files.
121 The files specified by `octave-help-files' are searched."
122 (if octave-help-completion-alist
124 (message "Building help completion alist...")
125 (let ((alist (octave-help-get-lookup-alist)) entry
)
127 (setq entry
(car alist
))
128 (add-to-list 'octave-help-completion-alist
129 (cons (car entry
) (car entry
)))
130 (setq alist
(cdr alist
))))
131 (message "Building help completion alist...done"))
132 octave-help-completion-alist
)
136 (provide 'octave-hlp
)
138 ;;; arch-tag: df5ef8fa-76c9-44e5-9835-cb5a502c6282
139 ;;; octave-hlp.el ends here