Mercurial > hg > octave-nkf
annotate scripts/help/lookfor.m @ 11523:fd0a3ac60b0e
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 14 Jan 2011 05:47:45 -0500 |
parents | c776f063fefe |
children | c792872f8942 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2009-2011 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 -*- |
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}) |
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9133
diff
changeset
|
23 ## @deftypefnx {Function File} {[@var{func}, @var{helpstring}] =} lookfor ('-all', @var{str}) |
9133
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9035
diff
changeset
|
24 ## Search for the string @var{str} in all functions found in the current |
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 |
9133
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9035
diff
changeset
|
27 ## help text of each function can be searched if the '-all' argument is |
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. |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
29 ## |
9133
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9035
diff
changeset
|
30 ## Called with no output arguments, @code{lookfor} prints the list of |
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9035
diff
changeset
|
31 ## matching functions to the terminal. Otherwise, the output arguments |
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9035
diff
changeset
|
32 ## @var{func} and @var{helpstring} define the matching functions and the |
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. |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
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 |
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9035
diff
changeset
|
39 ## user-supplied functions. Therefore, the use of the '-all' argument may |
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) |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
45 if (strcmpi (str, "-all")) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
46 ## The difference between using '-all' and not, is which part of the caches |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
47 ## we search. The cache is organised such that its first column contains |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
48 ## the function name, its second column contains the full help text, and its |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
49 ## 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
|
50 str = arg2; |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
51 search_type = 2; # when using caches, search its second column |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
52 else |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
53 search_type = 3; # when using caches, search its third column |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
54 endif |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
55 str = lower (str); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
56 |
8727
5a5dbdacbf5d
scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
57 ## Search functions, operators, and keywords that come with Octave |
8861 | 58 cache_file = doc_cache_file (); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
59 if (exist (cache_file, "file")) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
60 [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
|
61 had_core_cache = true; |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
62 else |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
63 fun = help_text = {}; |
8727
5a5dbdacbf5d
scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
64 had_core_cache = false; |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
65 endif |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
66 |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
67 ## Search functions in new path dirs. |
8877
2c8b2399247b
implement strsplit; deprecate split
Jaroslav Hajek <highegg@gmail.com>
parents:
8870
diff
changeset
|
68 orig_path = strsplit (__pathorig__ (), pathsep ()); |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
69 |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
70 ## ditto for path. |
8877
2c8b2399247b
implement strsplit; deprecate split
Jaroslav Hajek <highegg@gmail.com>
parents:
8870
diff
changeset
|
71 new_path = strsplit (path (), pathsep ()); |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
72 |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
73 ## scratch out directories already covered by orig_path. |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
74 if (had_core_cache) |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
75 new_path = setdiff (new_path, orig_path); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
76 endif |
8866
3149112b9412
improve lookfor performance
John W. Eaton <jwe@octave.org>
parents:
8861
diff
changeset
|
77 |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
78 for n = 1:numel (new_path) |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
79 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
|
80 cache_file = fullfile (elt, "doc-cache"); |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
81 if (exist (cache_file, "file")) |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
82 ## 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
|
83 [funs, hts] = search_cache (str, cache_file, search_type); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
84 fun (end+1:end+length (funs)) = funs; |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
85 help_text (end+1:end+length (hts)) = hts; |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
86 else |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
87 ## We don't have a cache. Search files |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
88 funs_in_f = __list_functions__ (elt); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
89 for m = 1:length (funs_in_f) |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
90 fn = funs_in_f {m}; |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
91 |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
92 ## Skip files that start with __ |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
93 if (length (fn) > 2 && strcmp (fn (1:2), "__")) |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
94 continue; |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
95 endif |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
96 |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
97 ## Extract first sentence |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
98 try |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
99 warn_state = warning (); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
100 unwind_protect |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
101 warning ("off"); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
102 first_sentence = get_first_help_sentence (fn); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
103 status = 0; |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
104 unwind_protect_cleanup |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
105 warning (warn_state); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
106 end_unwind_protect |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
107 catch |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
108 status = 1; |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
109 end_try_catch |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
110 |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
111 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
|
112 try |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
113 warn_state = warning (); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
114 unwind_protect |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
115 warning ("off"); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
116 [text, fmt] = get_help_text (fn); |
8866
3149112b9412
improve lookfor performance
John W. Eaton <jwe@octave.org>
parents:
8861
diff
changeset
|
117 status = 0; |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
118 unwind_protect_cleanup |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
119 warning (warn_state); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
120 end_unwind_protect |
8727
5a5dbdacbf5d
scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
121 catch |
5a5dbdacbf5d
scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
122 status = 1; |
5a5dbdacbf5d
scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
123 end_try_catch |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
124 |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
125 ## Take action depending on help text fmt |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
126 switch (lower (fmt)) |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
127 case "plain text" |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
128 status = 0; |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
129 case "texinfo" |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
130 [text, status] = __makeinfo__ (text, "plain text"); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
131 case "html" |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
132 [text, status] = strip_html_tags (text); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
133 otherwise |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
134 status = 1; |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
135 endswitch |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
136 |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
137 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
|
138 text = first_sentence; |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
139 endif |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
140 |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
141 ## Search the help text, if we can |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
142 if (status == 0 && !isempty (strfind (text, str))) |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
143 fun (end+1) = fn; |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
144 help_text (end+1) = first_sentence; |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
145 endif |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
146 endfor |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
147 endif |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
148 endfor |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
149 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
150 if (nargout == 0) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
151 ## Print the results (FIXME: improve this to make it look better. |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
152 indent = 20; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
153 term_width = terminal_size() (2); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
154 desc_width = term_width - indent - 2; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
155 indent_space = repmat (" ", 1, indent); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
156 for k = 1:length (fun) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
157 f = fun {k}; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
158 f (end+1:indent) = " "; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
159 printf (f); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
160 desc = strtrim (strrep (help_text {k}, "\n", " ")); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
161 ldesc = length (desc); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
162 printf ("%s\n", desc (1:min (desc_width, ldesc))); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
163 for start = desc_width+1:desc_width:ldesc |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
164 stop = min (start + desc_width, ldesc); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
165 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
|
166 endfor |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
167 endfor |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
168 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
169 else |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
170 ## Return the results instead of displaying them |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
171 out_fun = fun; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
172 out_help_text = help_text; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
173 endif |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
174 endfunction |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
175 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
176 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
|
177 load (cache_file); |
8941
b8ed0262b11e
lookfor.m: also match function names
John W. Eaton <jwe@octave.org>
parents:
8940
diff
changeset
|
178 if (! isempty (cache)) |
b8ed0262b11e
lookfor.m: also match function names
John W. Eaton <jwe@octave.org>
parents:
8940
diff
changeset
|
179 t1 = strfind (cache (1, :), str); |
b8ed0262b11e
lookfor.m: also match function names
John W. Eaton <jwe@octave.org>
parents:
8940
diff
changeset
|
180 t2 = strfind (cache (search_type, :), str); |
b8ed0262b11e
lookfor.m: also match function names
John W. Eaton <jwe@octave.org>
parents:
8940
diff
changeset
|
181 cache_idx = find (! (cellfun ("isempty", t1) & cellfun ("isempty", t2))); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
182 funs = cache (1, cache_idx); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
183 help_texts = cache (3, cache_idx); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
184 else |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
185 funs = help_texts = {}; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
186 endif |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
187 endfunction |