annotate lisp/progmodes/octave-hlp.el @ 79537:bb68325eec9b

*** empty log message ***
author Juanma Barranquero <lekktu@gmail.com>
date Tue, 04 Dec 2007 15:43:26 +0000
parents c1ec1c8a8d2e
children a1342e6e097a f55f9811f5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17517
8f952e921136 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 17149
diff changeset
1 ;;; octave-hlp.el --- getting help on Octave symbols using info
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 68773
diff changeset
3 ;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007
64699
629afbe74e61 Update copyright for release of 22.1 for progmodes directory.
Nick Roberts <nickrob@snap.net.nz>
parents: 64085
diff changeset
4 ;; Free Software Foundation, Inc.
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
65152
7a3342784b7e Change Author and Maintainer address.
Eli Zaretskii <eliz@gnu.org>
parents: 64699
diff changeset
6 ;; Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Author: John Eaton <jwe@bevo.che.wisc.edu>
65152
7a3342784b7e Change Author and Maintainer address.
Eli Zaretskii <eliz@gnu.org>
parents: 64699
diff changeset
8 ;; Maintainer: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; Keywords: languages
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
78234
c1ec1c8a8d2e Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
15 ;; the Free Software Foundation; either version 3, or (at your option)
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; any later version.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
26 ;; Boston, MA 02110-1301, USA.
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;; Commentary:
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; Provides the command `octave-help' which allows index lookup of a
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; symbol in the Octave-related info files, as specified by the list
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; `octave-help-files'.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; Other features may be added in future versions.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;;; Code:
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37
16904
2bc5f76917e0 Require octave-mod, not octave.
Richard M. Stallman <rms@gnu.org>
parents: 16903
diff changeset
38 (require 'octave-mod)
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 (require 'info)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 (defvar octave-help-files '("octave")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 "List of info files with documentation for Octave.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 Default is (\"octave\").")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 (defvar octave-help-lookup-alist nil
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 "Alist of Octave index entries for lookup.")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 (defvar octave-help-completion-alist nil
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 "Alist of Octave index entries for completion.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 The entries are of the form (VAR . VAR), where VAR runs through all
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 different keys in `octave-help-lookup-alist'.")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;;;###autoload
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (defun octave-help (key)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 "Get help on Octave symbols from the Octave info files.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 Look up KEY in the function, operator and variable indices of the files
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 specified by `octave-help-files'.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 If KEY is not a string, prompt for it with completion."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (interactive
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (list
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (completing-read (format "Describe Octave symbol: ")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (octave-help-get-completion-alist)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 nil t)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (if (get-buffer "*info*")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (set-buffer "*info*"))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (if (zerop (length key))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (Info-find-node (car octave-help-files) "Top")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (let ((alist (copy-alist (octave-help-get-lookup-alist)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 entry matches)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (while (setq entry (car alist))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (if (string-match key (car entry))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (add-to-list 'matches entry))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (setq alist (cdr alist)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (if matches
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (progn
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (setq Info-index-alternatives matches)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (Info-index-next 0))))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (defun octave-help-get-lookup-alist ()
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 "Build the index lookup alist from all Octave info files.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 The files specified by `octave-help-files' are searched."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (if octave-help-lookup-alist
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ()
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 17517
diff changeset
84 (message "Building help lookup alist...")
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (let ((files octave-help-files) file key node)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 (save-window-excursion
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (while files
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 (setq file (car files))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 (Info-goto-node (concat "(" file ")"))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 (condition-case nil
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (progn
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 (Info-index "")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 (while
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 (progn
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (while (re-search-forward
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 "^\\* \\([^(:]+\\)[^:]*: *\\(.+\\)\\.$"
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 nil t)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (setq key (match-string 1)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 node (concat "(" file ")" (match-string 2)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 (and (string-match "\\(.*\\>\\) *$" key)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (setq key (replace-match "\\1" t nil key)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (add-to-list 'octave-help-lookup-alist
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (list key
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 node
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (concat (concat "(" file ")")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 Info-current-node)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 0)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (and (setq node (Info-extract-pointer "next" t))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 (string-match
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 (concat "\\(Function\\|Operator\\|Variable\\) "
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 "\\<Index\\>")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 node)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (Info-goto-node node)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (error nil))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (setq files (cdr files)))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (message "Building help lookup alist...done"))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 octave-help-lookup-alist)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (defun octave-help-get-completion-alist ()
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 "Build the index completion alist from all Octave info files.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 The files specified by `octave-help-files' are searched."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (if octave-help-completion-alist
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 ()
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (message "Building help completion alist...")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (let ((alist (octave-help-get-lookup-alist)) entry)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (while alist
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (setq entry (car alist))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (add-to-list 'octave-help-completion-alist
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (cons (car entry) (car entry)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (setq alist (cdr alist))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 17517
diff changeset
131 (message "Building help completion alist...done"))
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 octave-help-completion-alist)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133
17149
b6b657de23f3 Provide octave-hlp.
Karl Heuer <kwzh@gnu.org>
parents: 16904
diff changeset
134 ;;; provide ourself
b6b657de23f3 Provide octave-hlp.
Karl Heuer <kwzh@gnu.org>
parents: 16904
diff changeset
135
b6b657de23f3 Provide octave-hlp.
Karl Heuer <kwzh@gnu.org>
parents: 16904
diff changeset
136 (provide 'octave-hlp)
b6b657de23f3 Provide octave-hlp.
Karl Heuer <kwzh@gnu.org>
parents: 16904
diff changeset
137
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49598
diff changeset
138 ;;; arch-tag: df5ef8fa-76c9-44e5-9835-cb5a502c6282
16904
2bc5f76917e0 Require octave-mod, not octave.
Richard M. Stallman <rms@gnu.org>
parents: 16903
diff changeset
139 ;;; octave-hlp.el ends here