annotate scripts/help/lookfor.m @ 15063:36cbcc37fdb8

Refactor configure.ac to make it more understandable. Use common syntax for messages in config.h Correct typos, refer to libraries in all caps, use two spaces after period. Follow Autoconf guidelines and place general tests before specific tests. * configure.ac, m4/acinclude.m4: Use common syntax for messages in config.h Correct typos, refer to libraries in all caps, use two spaces after period. Follow Autoconf guidelines and place general tests before specific tests.
author Rik <rik@octave.org>
date Tue, 31 Jul 2012 10:28:51 -0700
parents 7277fe922e99
children 1de4ec2a856d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13772
diff changeset
1 ## Copyright (C) 2009-2012 S�ren Hauberg
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
2 ##
11104
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 9724
diff changeset
3 ## This file is part of Octave.
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 9724
diff changeset
4 ##
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 9724
diff changeset
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
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 9724
diff changeset
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
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 9724
diff changeset
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 -*-
9724
f22bbc5d56e9 Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents: 9133
diff changeset
20 ## @deftypefn {Command} {} lookfor @var{str}
f22bbc5d56e9 Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents: 9133
diff changeset
21 ## @deftypefnx {Command} {} lookfor -all @var{str}
f22bbc5d56e9 Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents: 9133
diff changeset
22 ## @deftypefnx {Function File} {[@var{func}, @var{helpstring}] =} lookfor (@var{str})
14359
7277fe922e99 doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
23 ## @deftypefnx {Function File} {[@var{func}, @var{helpstring}] =} lookfor ("-all", @var{str})
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
24 ## Search for the string @var{str} in all functions found in the current
9133
c0cef1436788 Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents: 9035
diff changeset
25 ## function search path. By default, @code{lookfor} searches for @var{str}
9035
57649dcecb55 Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents: 8941
diff changeset
26 ## in the first sentence of the help string of each function found. The entire
14359
7277fe922e99 doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
27 ## help text of each function can be searched if the "-all" argument is
9133
c0cef1436788 Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents: 9035
diff changeset
28 ## supplied. All searches are case insensitive.
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
29 ##
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
30 ## Called with no output arguments, @code{lookfor} prints the list of
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
31 ## matching functions to the terminal. Otherwise, the output arguments
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
32 ## @var{func} and @var{helpstring} define the matching functions and the
9133
c0cef1436788 Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents: 9035
diff changeset
33 ## first sentence of each of their help strings.
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
34 ##
9133
c0cef1436788 Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents: 9035
diff changeset
35 ## The ability of @code{lookfor} to correctly identify the first
c0cef1436788 Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents: 9035
diff changeset
36 ## sentence of the help text is dependent on the format of the
c0cef1436788 Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents: 9035
diff changeset
37 ## function's help. All Octave core functions are correctly
c0cef1436788 Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents: 9035
diff changeset
38 ## formatted, but the same can not be guaranteed for external packages and
14359
7277fe922e99 doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
39 ## user-supplied functions. Therefore, the use of the "-all" argument may
9133
c0cef1436788 Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents: 9035
diff changeset
40 ## be necessary to find related functions that are not a part of Octave.
c0cef1436788 Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents: 9035
diff changeset
41 ## @seealso{help, doc, which}
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
42 ## @end deftypefn
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
43
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11104
diff changeset
44 function [out_fun, out_help_text] = lookfor (str, arg2)
13772
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
45
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
46 if (strcmpi (str, "-all"))
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
47 ## The difference between using '-all' and not, is which part of the caches
13772
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
48 ## we search. The cache is organized such that the first column contains
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
49 ## the function name, the second column contains the full help text, and
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
50 ## the third column contains the first sentence of the help text.
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11104
diff changeset
51 str = arg2;
13772
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
52 search_type = 2; # when using caches, search the second column
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
53 else
13772
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
54 search_type = 3; # when using caches, search the third column
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
55 endif
13772
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
56 str = lower (str); # Compare is case insensitive
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
57
8727
5a5dbdacbf5d scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents: 8575
diff changeset
58 ## Search functions, operators, and keywords that come with Octave
8861
31f864877246 doc and lookfor fixes
John W. Eaton <jwe@octave.org>
parents: 8768
diff changeset
59 cache_file = doc_cache_file ();
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
60 if (exist (cache_file, "file"))
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
61 [fun, help_text] = search_cache (str, cache_file, search_type);
8727
5a5dbdacbf5d scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents: 8575
diff changeset
62 had_core_cache = true;
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
63 else
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
64 fun = help_text = {};
8727
5a5dbdacbf5d scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents: 8575
diff changeset
65 had_core_cache = false;
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
66 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
67
8870
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
68 ## Search functions in new path dirs.
8877
2c8b2399247b implement strsplit; deprecate split
Jaroslav Hajek <highegg@gmail.com>
parents: 8870
diff changeset
69 orig_path = strsplit (__pathorig__ (), pathsep ());
8870
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
70
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
71 ## ditto for path.
8877
2c8b2399247b implement strsplit; deprecate split
Jaroslav Hajek <highegg@gmail.com>
parents: 8870
diff changeset
72 new_path = strsplit (path (), pathsep ());
8870
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
73
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
74 ## scratch out directories already covered by orig_path.
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
75 if (had_core_cache)
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
76 new_path = setdiff (new_path, orig_path);
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
77 endif
8866
3149112b9412 improve lookfor performance
John W. Eaton <jwe@octave.org>
parents: 8861
diff changeset
78
8870
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
79 for n = 1:numel (new_path)
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
80 elt = new_path{n};
8940
6994961bf1f4 use doc-cache instead of DOC for doc cache file name
John W. Eaton <jwe@octave.org>
parents: 8877
diff changeset
81 cache_file = fullfile (elt, "doc-cache");
8870
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
82 if (exist (cache_file, "file"))
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
83 ## We have a cache in the directory, then read it and search it!
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
84 [funs, hts] = search_cache (str, cache_file, search_type);
13772
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
85 fun(end+1:end+length (funs)) = funs;
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
86 help_text(end+1:end+length (hts)) = hts;
8870
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
87 else
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
88 ## We don't have a cache. Search files
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
89 funs_in_f = __list_functions__ (elt);
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
90 for m = 1:length (funs_in_f)
13772
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
91 fn = funs_in_f{m};
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
92
8870
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
93 ## Skip files that start with __
13772
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
94 if (length (fn) > 2 && strcmp (fn(1:2), "__"))
8870
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
95 continue;
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
96 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
97
8870
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
98 ## Extract first sentence
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
99 try
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
100 warn_state = warning ();
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
101 unwind_protect
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
102 warning ("off");
13772
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
103 first_sentence = get_first_help_sentence (fn, 1024);
8870
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
104 status = 0;
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
105 unwind_protect_cleanup
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
106 warning (warn_state);
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
107 end_unwind_protect
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
108 catch
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
109 status = 1;
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
110 end_try_catch
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
111
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
112 if (search_type == 2) # search entire help text
8727
5a5dbdacbf5d scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents: 8575
diff changeset
113 try
8870
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
114 warn_state = warning ();
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
115 unwind_protect
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
116 warning ("off");
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
117 [text, fmt] = get_help_text (fn);
8866
3149112b9412 improve lookfor performance
John W. Eaton <jwe@octave.org>
parents: 8861
diff changeset
118 status = 0;
8870
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
119 unwind_protect_cleanup
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
120 warning (warn_state);
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
121 end_unwind_protect
8727
5a5dbdacbf5d scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents: 8575
diff changeset
122 catch
5a5dbdacbf5d scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents: 8575
diff changeset
123 status = 1;
5a5dbdacbf5d scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents: 8575
diff changeset
124 end_try_catch
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
125
8870
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
126 ## Take action depending on help text fmt
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
127 switch (lower (fmt))
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
128 case "plain text"
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
129 status = 0;
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
130 case "texinfo"
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
131 [text, status] = __makeinfo__ (text, "plain text");
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
132 case "html"
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
133 [text, status] = strip_html_tags (text);
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
134 otherwise
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
135 status = 1;
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
136 endswitch
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
137
8870
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
138 elseif (status == 0) # only search the first sentence of the help text
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
139 text = first_sentence;
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
140 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
141
8870
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
142 ## Search the help text, if we can
13772
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
143 if (status == 0 && ! isempty (strfind (lower (text), str)))
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
144 fun(end+1) = fn;
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
145 help_text(end+1) = first_sentence;
8870
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
146 endif
eea0e1b45ec0 optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents: 8866
diff changeset
147 endfor
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
148 endif
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
149 endfor
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
150
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
151 if (nargout == 0)
13772
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
152 ## Print the results (FIXME: it would be nice to break at word boundaries)
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
153 indent = 20;
13772
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
154 term_width = (terminal_size ())(2);
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
155 desc_width = term_width - indent - 2;
13772
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
156 indent_space = blanks (indent);
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
157 for k = 1:length (fun)
13772
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
158 f = fun{k};
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
159 f(end+1:indent-1) = " ";
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
160 puts ([f " "]);
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
161 lf = length (f);
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
162 desc = strtrim (strrep (help_text{k}, "\n", " "));
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
163 ldesc = length (desc);
13772
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
164 printf ("%s\n", desc(1:min (ldesc, desc_width - (lf - indent))));
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
165 for start = (desc_width - (lf - indent) + 1):desc_width:ldesc
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
166 stop = min (start + desc_width, ldesc);
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
167 printf ("%s%s\n", indent_space, strtrim (desc (start:stop)));
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
168 endfor
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
169 endfor
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
170
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
171 else
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
172 ## Return the results instead of displaying them
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
173 out_fun = fun;
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
174 out_help_text = help_text;
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
175 endif
13772
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
176
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
177 endfunction
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
178
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
179 function [funs, help_texts] = search_cache (str, cache_file, search_type)
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
180 load (cache_file);
8941
b8ed0262b11e lookfor.m: also match function names
John W. Eaton <jwe@octave.org>
parents: 8940
diff changeset
181 if (! isempty (cache))
13772
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
182 t1 = strfind (lower (cache (1, :)), str);
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
183 t2 = strfind (lower (cache (search_type, :)), str);
8941
b8ed0262b11e lookfor.m: also match function names
John W. Eaton <jwe@octave.org>
parents: 8940
diff changeset
184 cache_idx = find (! (cellfun ("isempty", t1) & cellfun ("isempty", t2)));
13772
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
185 funs = cache(1, cache_idx);
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
186 help_texts = cache(3, cache_idx);
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
187 else
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
188 funs = help_texts = {};
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
189 endif
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
190 endfunction
13772
ebefc477607b lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
191