Mercurial > hg > octave-lyh
annotate scripts/help/help.m @ 10687:a8ce6bdecce5
Improve documentation strings.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Tue, 08 Jun 2010 20:22:38 -0700 |
parents | 69a715c81eab |
children | 2c356a35d7f5 |
rev | line source |
---|---|
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
1 ## Copyright (C) 2009 S�ren Hauberg |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
2 ## |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
3 ## This program is free software; you can redistribute it and/or modify it |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
4 ## under the terms of the GNU General Public License as published by |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
5 ## the Free Software Foundation; either version 3 of the License, or (at |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
6 ## your option) any later version. |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
7 ## |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
8 ## This program is distributed in the hope that it will be useful, but |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
11 ## General Public License for more details. |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
12 ## |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
13 ## You should have received a copy of the GNU General Public License |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
14 ## along with this program; see the file COPYING. If not, see |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
15 ## <http://www.gnu.org/licenses/>. |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
16 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
17 ## -*- texinfo -*- |
10625
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
18 ## @deftypefn {Function File} {} help @var{name} |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
19 ## Display the help text for @var{name}. |
10625
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
20 ## If invoked without any arguments, @code{help} displays instructions |
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
21 ## on how to access help from the command line. |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
22 ## |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
23 ## For example, the command @kbd{help help} prints a short message |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
24 ## describing the @code{help} command. |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
25 ## |
10625
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
26 ## @deftypefnx {Function File} {@var{text} =} help (@var{name}) |
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
27 ## Return the help text for the function, @var{name}. |
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
28 ## |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
29 ## The help command can give you information about operators, but not the |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
30 ## comma and semicolons that are used as command separators. To get help |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
31 ## for those, you must type @kbd{help comma} or @kbd{help semicolon}. |
9133
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
8768
diff
changeset
|
32 ## @seealso{doc, lookfor, which} |
10625
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
33 ## @end deftypefn |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
34 |
10632
69a715c81eab
help.m: avoid unnecessary use of varargout
John W. Eaton <jwe@octave.org>
parents:
10625
diff
changeset
|
35 function retval = help (name) |
8748
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
36 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
37 if (nargin == 0) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
38 |
8748
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
39 puts ("\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
40 For help with individual commands and functions type\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
41 \n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
42 help NAME\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
43 \n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
44 (replace NAME with the name of the command or function you would\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
45 like to learn more about).\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
46 \n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
47 For a more detailed introduction to GNU Octave, please consult the\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
48 manual. To read the manual from the prompt type\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
49 \n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
50 doc\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
51 \n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
52 GNU Octave is supported and developed by its user community.\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
53 For more information visit http://www.octave.org.\n\n"); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
54 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
55 elseif (nargin == 1 && ischar (name)) |
8748
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
56 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
57 ## Get help text |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
58 [text, format] = get_help_text (name); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
59 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
60 ## Take action depending on help text format |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
61 switch (lower (format)) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
62 case "plain text" |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
63 status = 0; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
64 case "texinfo" |
8768
e0fbf17a17bb
__makeinfo__.m: rename from makeinfo.m
John W. Eaton <jwe@octave.org>
parents:
8748
diff
changeset
|
65 [text, status] = __makeinfo__ (text, "plain text"); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
66 case "html" |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
67 [text, status] = strip_html_tags (text); |
8631
52956d669506
Display sensible error message when the help text of an undocumented function is requested
Soren Hauberg <hauberg@gmail.com>
parents:
8630
diff
changeset
|
68 case "not documented" |
52956d669506
Display sensible error message when the help text of an undocumented function is requested
Soren Hauberg <hauberg@gmail.com>
parents:
8630
diff
changeset
|
69 error ("help: `%s' is not documented\n", name); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
70 case "not found" |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
71 do_contents (name); |
10549 | 72 return; |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
73 otherwise |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
74 error ("help: internal error: unsupported help text format: '%s'\n", format); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
75 endswitch |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
76 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
77 ## Print text |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
78 if (status != 0) |
8768
e0fbf17a17bb
__makeinfo__.m: rename from makeinfo.m
John W. Eaton <jwe@octave.org>
parents:
8748
diff
changeset
|
79 warning ("help: Texinfo formatting filter exited abnormally; raw Texinfo source of help text follows...\n"); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
80 endif |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
81 |
10625
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
82 if (nargout == 0) |
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
83 which (name); |
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
84 printf ("\n%s\n%s", text, __additional_help_message__ ()); |
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
85 else |
10632
69a715c81eab
help.m: avoid unnecessary use of varargout
John W. Eaton <jwe@octave.org>
parents:
10625
diff
changeset
|
86 retval = text; |
10625
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
87 endif |
8748
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
88 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
89 else |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
90 error ("help: invalid input\n"); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
91 endif |
8748
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
92 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
93 endfunction |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
94 |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
95 function do_contents (name) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
96 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
97 found = false; |
8630
540165304f00
Allow displaying 'Contents.m' files.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
98 |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
99 dlist = find_dir_in_path (name, "all"); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
100 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
101 for i = 1:numel (dlist) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
102 fname = make_absolute_filename (fullfile (dlist{i}, "Contents.m")); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
103 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
104 [text, format] = get_help_text_from_file (fname); |
8630
540165304f00
Allow displaying 'Contents.m' files.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
105 |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
106 ## Take action depending on help text format |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
107 switch (lower (format)) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
108 case "plain text" |
10549 | 109 status = 0; |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
110 case "texinfo" |
10549 | 111 [text, status] = __makeinfo__ (text, "plain text"); |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
112 case "html" |
10549 | 113 [text, status] = strip_html_tags (text); |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
114 endswitch |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
115 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
116 if (! isempty (text)) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
117 found = true; |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
118 ## Print text. |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
119 if (status != 0) |
10549 | 120 warning ("help: Texinfo formatting filter exited abnormally; raw Texinfo source of help text follows...\n"); |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
121 endif |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
122 printf ("%s:\n\n%s\n", fname, text); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
123 endif |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
124 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
125 endfor |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
126 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
127 if (found) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
128 puts (__additional_help_message__ ()); |
10445
62f8ae5ab2cc
warn about missing matlab funcs in help
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
129 else |
62f8ae5ab2cc
warn about missing matlab funcs in help
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
130 feval (missing_function_hook, name); |
8630
540165304f00
Allow displaying 'Contents.m' files.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
131 endif |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
132 |
8630
540165304f00
Allow displaying 'Contents.m' files.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
133 endfunction |