Mercurial > hg > octave-nkf
annotate scripts/help/lookfor.m @ 20727:4479d73eac72
Fix error when building annotation objects in gnuplot (bug #46035)
* __gnuplot_draw_figure__.m: ignore uicontextmenu objects.
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Sat, 26 Sep 2015 11:26:18 +0200 |
parents | aa36fb998a4d |
children |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
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 -*- |
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} |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
22 ## @deftypefnx {Function File} {[@var{fcn}, @var{help1str}] =} lookfor (@var{str}) |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
23 ## @deftypefnx {Function File} {[@var{fcn}, @var{help1str}] =} lookfor ("-all", @var{str}) |
20368
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20345
diff
changeset
|
24 ## Search for the string @var{str} in the documentation of all functions in the |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20345
diff
changeset
|
25 ## current function search path. |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
26 ## |
20368
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20345
diff
changeset
|
27 ## By default, @code{lookfor} looks for @var{str} in just the first sentence of |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20345
diff
changeset
|
28 ## the help string for each function found. The entire help text of each |
20391
aa36fb998a4d
maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents:
20368
diff
changeset
|
29 ## function can be searched by using the @qcode{"-all"} argument. All searches |
20368
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20345
diff
changeset
|
30 ## are case insensitive. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
31 ## |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
32 ## When called with no output arguments, @code{lookfor} prints the list of |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
33 ## matching functions to the terminal. Otherwise, the output argument |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
34 ## @var{fcns} contains the function names and @var{help1str} contains the first |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
35 ## sentence from the help string of each function. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
36 ## |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
37 ## Programming Note: The ability of @code{lookfor} to correctly identify the |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
38 ## first sentence of the help text is dependent on the format of the function's |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
39 ## help. All Octave core functions are correctly formatted, but the same can |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
40 ## not be guaranteed for external packages and user-supplied functions. |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
41 ## Therefore, the use of the @qcode{"-all"} argument may be necessary to find |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
42 ## related functions that are not a part of Octave. |
20368
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20345
diff
changeset
|
43 ## |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20345
diff
changeset
|
44 ## The speed of lookup is greatly enhanced by having a cached documentation |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20345
diff
changeset
|
45 ## file. See @code{doc_cache_create} for more information. |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20345
diff
changeset
|
46 ## @seealso{help, doc, which, path, doc_cache_create} |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
47 ## @end deftypefn |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
48 |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
49 function [fcn, help1str] = lookfor (str, arg2) |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
50 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
51 if (strcmpi (str, "-all")) |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
52 ## The difference between using '-all' and not is which part of the caches |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
53 ## we search. The cache is organized such that row |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
54 ## 1) contains the function name |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
55 ## 2) contains the full help text |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
56 ## 3) 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
|
57 str = arg2; |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
58 search_type = 2; # search the second row (full help text) |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
59 else |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
60 search_type = 3; # search the third column (first help sentence) |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
61 endif |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
62 str = lower (str); # Compare is case insensitive |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
63 |
8727
5a5dbdacbf5d
scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
64 ## Search functions, operators, and keywords that come with Octave |
8861 | 65 cache_file = doc_cache_file (); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
66 if (exist (cache_file, "file")) |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
67 [fcnlist, 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
|
68 had_core_cache = true; |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
69 else |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
70 fcnlist = help_text = {}; |
8727
5a5dbdacbf5d
scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
71 had_core_cache = false; |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
72 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
73 |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
74 ## Search functions in new path dirs. |
16724
b7667fcb9fbc
Substitute ostrsplit() for strsplit().
Ben Abbott <bpabbott@mac.com>
parents:
16403
diff
changeset
|
75 orig_path = ostrsplit (__pathorig__ (), pathsep ()); |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
76 |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
77 ## ditto for path. |
16724
b7667fcb9fbc
Substitute ostrsplit() for strsplit().
Ben Abbott <bpabbott@mac.com>
parents:
16403
diff
changeset
|
78 new_path = ostrsplit (path (), pathsep ()); |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
79 |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
80 ## remove directories already covered by orig_path. |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
81 if (had_core_cache) |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
82 new_path = setdiff (new_path, orig_path); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
83 endif |
8866
3149112b9412
improve lookfor performance
John W. Eaton <jwe@octave.org>
parents:
8861
diff
changeset
|
84 |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
85 for n = 1:numel (new_path) |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
86 fcndir = new_path{n}; |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
87 cache_file = fullfile (fcndir, "doc-cache"); |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
88 if (exist (cache_file, "file")) |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
89 ## We have a cache in the directory, then read it and search it! |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
90 [fcns, htext] = search_cache (str, cache_file, search_type); |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
91 fcnlist(end+1:end+length (fcns)) = fcns; |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
92 help_text(end+1:end+length (htext)) = htext; |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
93 |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
94 else |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
95 ## We don't have a cache. Search files. |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
96 for fcn_in_fcndir = (__list_functions__ (fcndir)).' |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
97 fn = fcn_in_fcndir{1}; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
98 |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
99 ## Skip files that start with "__" |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
100 if (strncmp (fn, "__", 2)) |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
101 continue; |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
102 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
103 |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
104 status = 0; |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
105 |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
106 ## Extract first sentence |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
107 try |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
108 warn_state = warning (); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
109 unwind_protect |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
110 warning ("off"); |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
111 first_sentence = get_first_help_sentence (fn, 1024); |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
112 unwind_protect_cleanup |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
113 warning (warn_state); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
114 end_unwind_protect |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
115 catch |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
116 status = 1; |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
117 end_try_catch |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
118 |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
119 if (status) |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
120 ## Error getting first help sentence |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
121 elseif (search_type == 3) |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
122 ## only search the first sentence of the help text |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
123 text = first_sentence; |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
124 elseif (search_type == 2) |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
125 ## search entire help text |
8727
5a5dbdacbf5d
scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
126 try |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
127 warn_state = warning (); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
128 unwind_protect |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
129 warning ("off"); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
130 [text, fmt] = get_help_text (fn); |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
131 switch (lower (fmt)) |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
132 case "plain text" |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
133 status = 0; |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
134 case "texinfo" |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
135 [text, status] = __makeinfo__ (text, "plain text"); |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
136 case "html" |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
137 [text, status] = strip_html_tags (text); |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
138 otherwise |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
139 status = 1; |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
140 endswitch |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
141 unwind_protect_cleanup |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
142 warning (warn_state); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
143 end_unwind_protect |
8727
5a5dbdacbf5d
scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
144 catch |
5a5dbdacbf5d
scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
145 status = 1; |
5a5dbdacbf5d
scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
146 end_try_catch |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
147 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
148 |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
149 ## Search the help text |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
150 if (status == 0 && strfind (lower (text), str)) |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
151 fcnlist(end+1) = fn; |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
152 help_text(end+1) = first_sentence; |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
153 endif |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
154 endfor |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
155 endif |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
156 endfor |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
157 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
158 if (nargout == 0) |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
159 ## 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
|
160 indent = 20; |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
161 term_width = (terminal_size ())(2); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
162 desc_width = term_width - indent - 2; |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
163 indent_space = blanks (indent); |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
164 for k = 1:length (fcnlist) |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
165 f = fcnlist{k}; |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
166 f(end+1:indent-1) = " "; |
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
167 puts ([f " "]); |
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
168 lf = length (f); |
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
169 desc = strtrim (strrep (help_text{k}, "\n", " ")); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
170 ldesc = length (desc); |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
171 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
|
172 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
|
173 stop = min (start + desc_width, ldesc); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
174 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
|
175 endfor |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
176 endfor |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
177 else |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
178 ## Return the results instead of displaying them |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
179 fcn = fcnlist; |
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
180 help1str = help_text; |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
181 endif |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
182 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
183 endfunction |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
184 |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
185 function [fcns, help_texts] = search_cache (str, cache_file, search_type) |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
186 load (cache_file); |
8941
b8ed0262b11e
lookfor.m: also match function names
John W. Eaton <jwe@octave.org>
parents:
8940
diff
changeset
|
187 if (! isempty (cache)) |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
188 t1 = strfind (lower (cache (1, :)), str); |
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
189 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
|
190 cache_idx = find (! (cellfun ("isempty", t1) & cellfun ("isempty", t2))); |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
191 fcns = cache(1, cache_idx); |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
192 help_texts = cache(3, cache_idx); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
193 else |
20345
4c6d70a35192
lookfor.m: Overhaul function and fix bug #44924.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
194 fcns = help_texts = {}; |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
195 endif |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
196 endfunction |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
197 |