Mercurial > hg > octave-nkf
annotate scripts/help/help.m @ 20509:c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Fri, 03 Jul 2015 16:53:08 +0100 |
parents | 7503499a252b |
children |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19793
diff
changeset
|
1 ## Copyright (C) 2009-2015 Søren Hauberg |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
2 ## |
11104 | 3 ## This file is part of Octave. |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
6 ## 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
|
7 ## 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
|
8 ## your option) any later version. |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
9 ## |
11104 | 10 ## Octave is distributed in the hope that it will be useful, but |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
12 ## 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
|
13 ## General Public License for more details. |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
14 ## |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
11104 | 16 ## along with Octave; see the file COPYING. If not, see |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
18 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
12344
68ac95d2460c
Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
20 ## @deftypefn {Command} {} help @var{name} |
11567 | 21 ## @deftypefnx {Command} {} help @code{--list} |
15026
ae42d5a67ed9
help.m: Added option '.' (dot); 'help .' lists all operators
Sergey Dudoladov <sergey.dudoladov@gmail.com>
parents:
14363
diff
changeset
|
22 ## @deftypefnx {Command} {} help @code{.} |
19389
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
23 ## @deftypefnx {Command} {} help |
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
24 ## Display the help text for @var{name}. |
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
25 ## |
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
26 ## For example, the command @kbd{help help} prints a short message describing |
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
27 ## the @code{help} command. |
11565
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
28 ## |
20368
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
29 ## Given the single argument @code{--list}, list all operators, keywords, |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
30 ## built-in functions, and loadable functions available in the current session |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
31 ## of Octave. |
11565
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
32 ## |
20368
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
33 ## Given the single argument @code{.}, list all operators available in the |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
34 ## current session of Octave. |
15026
ae42d5a67ed9
help.m: Added option '.' (dot); 'help .' lists all operators
Sergey Dudoladov <sergey.dudoladov@gmail.com>
parents:
14363
diff
changeset
|
35 ## |
20368
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
36 ## If invoked without any arguments, @code{help} display instructions on how to |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
37 ## access help from the command line. |
11565
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
38 ## |
19389
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
39 ## The help command can provide information about most operators, for example |
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
40 ## @code{help +}, but not the comma and semicolon characters which are used |
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
41 ## by the Octave interpreter as command separators. For help on either of |
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
42 ## these type @kbd{help comma} or @kbd{help semicolon}. |
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
43 ## @seealso{doc, lookfor, which, info} |
10625
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
44 ## @end deftypefn |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
45 |
10632
69a715c81eab
help.m: avoid unnecessary use of varargout
John W. Eaton <jwe@octave.org>
parents:
10625
diff
changeset
|
46 function retval = help (name) |
8748
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
47 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
48 if (nargin == 0) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
49 |
15227
fbecbce45898
also return help text as a string when nargin = 0 (bug #37183)
John W. Eaton <jwe@octave.org>
parents:
15026
diff
changeset
|
50 text = "\n\ |
8748
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
51 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
|
52 \n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
53 help NAME\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
54 \n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
55 (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
|
56 like to learn more about).\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
57 \n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
58 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
|
59 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
|
60 \n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
61 doc\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
62 \n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
63 GNU Octave is supported and developed by its user community.\n\ |
15227
fbecbce45898
also return help text as a string when nargin = 0 (bug #37183)
John W. Eaton <jwe@octave.org>
parents:
15026
diff
changeset
|
64 For more information visit http://www.octave.org.\n\n"; |
fbecbce45898
also return help text as a string when nargin = 0 (bug #37183)
John W. Eaton <jwe@octave.org>
parents:
15026
diff
changeset
|
65 |
fbecbce45898
also return help text as a string when nargin = 0 (bug #37183)
John W. Eaton <jwe@octave.org>
parents:
15026
diff
changeset
|
66 if (nargout == 0) |
fbecbce45898
also return help text as a string when nargin = 0 (bug #37183)
John W. Eaton <jwe@octave.org>
parents:
15026
diff
changeset
|
67 puts (text); |
fbecbce45898
also return help text as a string when nargin = 0 (bug #37183)
John W. Eaton <jwe@octave.org>
parents:
15026
diff
changeset
|
68 else |
fbecbce45898
also return help text as a string when nargin = 0 (bug #37183)
John W. Eaton <jwe@octave.org>
parents:
15026
diff
changeset
|
69 retval = text; |
fbecbce45898
also return help text as a string when nargin = 0 (bug #37183)
John W. Eaton <jwe@octave.org>
parents:
15026
diff
changeset
|
70 endif |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
71 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
72 elseif (nargin == 1 && ischar (name)) |
8748
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
73 |
11565
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
74 if (strcmp (name, "--list")) |
19389
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
75 list = do_list_functions (); |
11565
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
76 if (nargout == 0) |
19389
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
77 printf ("%s", list); |
11565
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
78 else |
19389
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
79 retval = list; |
11565
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
80 endif |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
81 return; |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
82 endif |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
83 |
15026
ae42d5a67ed9
help.m: Added option '.' (dot); 'help .' lists all operators
Sergey Dudoladov <sergey.dudoladov@gmail.com>
parents:
14363
diff
changeset
|
84 if (strcmp (name, ".")) |
19389
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
85 list = do_list_operators (); |
15026
ae42d5a67ed9
help.m: Added option '.' (dot); 'help .' lists all operators
Sergey Dudoladov <sergey.dudoladov@gmail.com>
parents:
14363
diff
changeset
|
86 if (nargout == 0) |
19389
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
87 printf ("%s", list); |
15026
ae42d5a67ed9
help.m: Added option '.' (dot); 'help .' lists all operators
Sergey Dudoladov <sergey.dudoladov@gmail.com>
parents:
14363
diff
changeset
|
88 else |
19389
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
89 retval = list; |
15026
ae42d5a67ed9
help.m: Added option '.' (dot); 'help .' lists all operators
Sergey Dudoladov <sergey.dudoladov@gmail.com>
parents:
14363
diff
changeset
|
90 endif |
ae42d5a67ed9
help.m: Added option '.' (dot); 'help .' lists all operators
Sergey Dudoladov <sergey.dudoladov@gmail.com>
parents:
14363
diff
changeset
|
91 return; |
ae42d5a67ed9
help.m: Added option '.' (dot); 'help .' lists all operators
Sergey Dudoladov <sergey.dudoladov@gmail.com>
parents:
14363
diff
changeset
|
92 endif |
ae42d5a67ed9
help.m: Added option '.' (dot); 'help .' lists all operators
Sergey Dudoladov <sergey.dudoladov@gmail.com>
parents:
14363
diff
changeset
|
93 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
94 ## Get help text |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
95 [text, format] = get_help_text (name); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11567
diff
changeset
|
96 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
97 ## Take action depending on help text format |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
98 switch (lower (format)) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
99 case "plain text" |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
100 status = 0; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
101 case "texinfo" |
8768
e0fbf17a17bb
__makeinfo__.m: rename from makeinfo.m
John W. Eaton <jwe@octave.org>
parents:
8748
diff
changeset
|
102 [text, status] = __makeinfo__ (text, "plain text"); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
103 case "html" |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
104 [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
|
105 case "not documented" |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
106 error ("help: '%s' is not documented\n", name); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
107 case "not found" |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
108 do_contents (name); |
10549 | 109 return; |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
110 otherwise |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
111 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
|
112 endswitch |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11567
diff
changeset
|
113 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
114 ## Print text |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
115 if (status != 0) |
8768
e0fbf17a17bb
__makeinfo__.m: rename from makeinfo.m
John W. Eaton <jwe@octave.org>
parents:
8748
diff
changeset
|
116 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
|
117 endif |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
118 |
10625
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
119 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
|
120 which (name); |
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
121 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
|
122 else |
10632
69a715c81eab
help.m: avoid unnecessary use of varargout
John W. Eaton <jwe@octave.org>
parents:
10625
diff
changeset
|
123 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
|
124 endif |
8748
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
125 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
126 else |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
127 error ("help: invalid input\n"); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
128 endif |
8748
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
129 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
130 endfunction |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
131 |
15026
ae42d5a67ed9
help.m: Added option '.' (dot); 'help .' lists all operators
Sergey Dudoladov <sergey.dudoladov@gmail.com>
parents:
14363
diff
changeset
|
132 function retval = do_list_operators () |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
133 |
15026
ae42d5a67ed9
help.m: Added option '.' (dot); 'help .' lists all operators
Sergey Dudoladov <sergey.dudoladov@gmail.com>
parents:
14363
diff
changeset
|
134 retval = sprintf ("*** operators:\n\n%s\n\n", |
19389
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
135 list_in_columns (__operators__ ())); |
15026
ae42d5a67ed9
help.m: Added option '.' (dot); 'help .' lists all operators
Sergey Dudoladov <sergey.dudoladov@gmail.com>
parents:
14363
diff
changeset
|
136 endfunction |
ae42d5a67ed9
help.m: Added option '.' (dot); 'help .' lists all operators
Sergey Dudoladov <sergey.dudoladov@gmail.com>
parents:
14363
diff
changeset
|
137 |
11565
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
138 function retval = do_list_functions () |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
139 |
15026
ae42d5a67ed9
help.m: Added option '.' (dot); 'help .' lists all operators
Sergey Dudoladov <sergey.dudoladov@gmail.com>
parents:
14363
diff
changeset
|
140 operators = do_list_operators (); |
11565
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
141 |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
142 keywords = sprintf ("*** keywords:\n\n%s\n\n", |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
143 list_in_columns (__keywords__ ())); |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
144 |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
145 builtins = sprintf ("*** builtins:\n\n%s\n\n", |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
146 list_in_columns (__builtins__ ())); |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
147 |
16724
b7667fcb9fbc
Substitute ostrsplit() for strsplit().
Ben Abbott <bpabbott@mac.com>
parents:
16403
diff
changeset
|
148 dirs = ostrsplit (path, pathsep); |
11565
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
149 flist = ""; |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
150 for i = 2:numel (dirs) |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
151 files = sort ({dir(fullfile (dirs{i}, "*.m")).name, ... |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
152 dir(fullfile (dirs{i}, "*.oct")).name, ... |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
153 dir(fullfile (dirs{i}, "*.mex")).name}); |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
154 |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
155 if (! isempty (files)) |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
156 flist = sprintf ("%s*** functions in %s:\n\n%s\n\n", |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
157 flist, dirs{i}, list_in_columns (files)); |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
158 endif |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
159 endfor |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
160 |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16724
diff
changeset
|
161 retval = [operators, keywords, builtins, flist]; |
11565
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
162 |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
163 endfunction |
21c3e1370b82
implement --list option for help function
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
164 |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
165 function do_contents (name) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
166 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
167 found = false; |
8630
540165304f00
Allow displaying 'Contents.m' files.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
168 |
18109
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18104
diff
changeset
|
169 dlist = dir_in_loadpath (name, "all"); |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
170 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
171 for i = 1:numel (dlist) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
172 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
|
173 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
174 [text, format] = get_help_text_from_file (fname); |
8630
540165304f00
Allow displaying 'Contents.m' files.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
175 |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
176 ## Take action depending on help text format |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
177 switch (lower (format)) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
178 case "plain text" |
10549 | 179 status = 0; |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
180 case "texinfo" |
10549 | 181 [text, status] = __makeinfo__ (text, "plain text"); |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
182 case "html" |
10549 | 183 [text, status] = strip_html_tags (text); |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
184 endswitch |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
185 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
186 if (! isempty (text)) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
187 found = true; |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
188 ## Print text. |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
189 if (status != 0) |
10549 | 190 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
|
191 endif |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
192 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
|
193 endif |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
194 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
195 endfor |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
196 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
197 if (found) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
198 puts (__additional_help_message__ ()); |
10445
62f8ae5ab2cc
warn about missing matlab funcs in help
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
199 else |
11215
8b2a47a99701
help: print message if function not found
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
200 msg = feval (missing_function_hook, name); |
8b2a47a99701
help: print message if function not found
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
201 |
8b2a47a99701
help: print message if function not found
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
202 if (isempty (msg)) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
203 msg = sprintf ("'%s' not found", name); |
11215
8b2a47a99701
help: print message if function not found
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
204 endif |
8b2a47a99701
help: print message if function not found
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
205 |
8b2a47a99701
help: print message if function not found
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
206 error ("help: %s\n", msg); |
8630
540165304f00
Allow displaying 'Contents.m' files.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
207 endif |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
208 |
8630
540165304f00
Allow displaying 'Contents.m' files.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
209 endfunction |
13763
85d63b6e49cf
help.m: Add functional tests
Rik <octave@nomad.inbox5.com>
parents:
12344
diff
changeset
|
210 |
85d63b6e49cf
help.m: Add functional tests
Rik <octave@nomad.inbox5.com>
parents:
12344
diff
changeset
|
211 |
14214
2fe0f5fa8cc3
Replace to-be-deprecated findstr occurrences with strfind.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
212 %!assert (! isempty (strfind (help ("ls"), "List directory contents"))) |
19389
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
213 %!assert (! isempty (strfind (help ("."), "||"))) |
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
214 |
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
215 ## Test input validation |
13763
85d63b6e49cf
help.m: Add functional tests
Rik <octave@nomad.inbox5.com>
parents:
12344
diff
changeset
|
216 %!error <invalid input> help (42) |
19389
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
217 %!error <invalid input> help ("abc", "def") |
09bc8304f182
doc: Improvements to help() and info() docstrings.
Rik <rik@octave.org>
parents:
18109
diff
changeset
|
218 %!error <'_!UNLIKELY_FCN!_' not found> help ("_!UNLIKELY_FCN!_") |
14214
2fe0f5fa8cc3
Replace to-be-deprecated findstr occurrences with strfind.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
219 |