Mercurial > hg > octave-nkf
annotate scripts/help/lookfor.m @ 17804:f3e25230b1f3
use QCoreApplication if starting with --no-gui
* octave-gui.cc (octave_start_gui): Use QApplication when starting
the GUI and QCoreApplication if not.
(octave_cli_thread::run): Call QCoreApplication::exit instead of
QApplication::exit.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 30 Oct 2013 02:08:41 -0400 |
parents | d63878346099 |
children | 4197fc428c7d |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
1 ## Copyright (C) 2009-2013 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}) |
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 |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17243
diff
changeset
|
27 ## help text of each function can be searched if the @qcode{"-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 |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17243
diff
changeset
|
39 ## user-supplied functions. Therefore, the use of the @qcode{"-all"} |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17243
diff
changeset
|
40 ## argument may be necessary to find related functions that are not a part of |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17243
diff
changeset
|
41 ## Octave. |
9133
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9035
diff
changeset
|
42 ## @seealso{help, doc, which} |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
43 ## @end deftypefn |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
44 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11104
diff
changeset
|
45 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
|
46 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
47 if (strcmpi (str, "-all")) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
48 ## 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
|
49 ## 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
|
50 ## 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
|
51 ## 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
|
52 str = arg2; |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
53 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
|
54 else |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
55 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
|
56 endif |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
57 str = lower (str); # Compare is case insensitive |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
58 |
8727
5a5dbdacbf5d
scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
59 ## Search functions, operators, and keywords that come with Octave |
8861 | 60 cache_file = doc_cache_file (); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
61 if (exist (cache_file, "file")) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
62 [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
|
63 had_core_cache = true; |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
64 else |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
65 fun = help_text = {}; |
8727
5a5dbdacbf5d
scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
66 had_core_cache = false; |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
67 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
68 |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
69 ## Search functions in new path dirs. |
16724
b7667fcb9fbc
Substitute ostrsplit() for strsplit().
Ben Abbott <bpabbott@mac.com>
parents:
16403
diff
changeset
|
70 orig_path = ostrsplit (__pathorig__ (), pathsep ()); |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
71 |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
72 ## ditto for path. |
16724
b7667fcb9fbc
Substitute ostrsplit() for strsplit().
Ben Abbott <bpabbott@mac.com>
parents:
16403
diff
changeset
|
73 new_path = ostrsplit (path (), pathsep ()); |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
74 |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
75 ## scratch out directories already covered by orig_path. |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
76 if (had_core_cache) |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
77 new_path = setdiff (new_path, orig_path); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
78 endif |
8866
3149112b9412
improve lookfor performance
John W. Eaton <jwe@octave.org>
parents:
8861
diff
changeset
|
79 |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
80 for n = 1:numel (new_path) |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
81 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
|
82 cache_file = fullfile (elt, "doc-cache"); |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
83 if (exist (cache_file, "file")) |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
84 ## 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
|
85 [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
|
86 fun(end+1:end+length (funs)) = funs; |
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
87 help_text(end+1:end+length (hts)) = hts; |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
88 else |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
89 ## We don't have a cache. Search files |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
90 funs_in_f = __list_functions__ (elt); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
91 for m = 1:length (funs_in_f) |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
92 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
|
93 |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
94 ## Skip files that start with __ |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
95 if (length (fn) > 2 && strcmp (fn(1:2), "__")) |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
96 continue; |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
97 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
98 |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
99 ## Extract first sentence |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
100 try |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
101 warn_state = warning (); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
102 unwind_protect |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
103 warning ("off"); |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
104 first_sentence = get_first_help_sentence (fn, 1024); |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
105 status = 0; |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
106 unwind_protect_cleanup |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
107 warning (warn_state); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
108 end_unwind_protect |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
109 catch |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
110 status = 1; |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
111 end_try_catch |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
112 |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
113 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
|
114 try |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
115 warn_state = warning (); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
116 unwind_protect |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
117 warning ("off"); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
118 [text, fmt] = get_help_text (fn); |
8866
3149112b9412
improve lookfor performance
John W. Eaton <jwe@octave.org>
parents:
8861
diff
changeset
|
119 status = 0; |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
120 unwind_protect_cleanup |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
121 warning (warn_state); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
122 end_unwind_protect |
8727
5a5dbdacbf5d
scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
123 catch |
5a5dbdacbf5d
scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
124 status = 1; |
5a5dbdacbf5d
scripts/help/lookfor.m: Adapt to new cache scheme.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
125 end_try_catch |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
126 |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
127 ## Take action depending on help text fmt |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
128 switch (lower (fmt)) |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
129 case "plain text" |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
130 status = 0; |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
131 case "texinfo" |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
132 [text, status] = __makeinfo__ (text, "plain text"); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
133 case "html" |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
134 [text, status] = strip_html_tags (text); |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
135 otherwise |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
136 status = 1; |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
137 endswitch |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
138 |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
139 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
|
140 text = first_sentence; |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
141 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
142 |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
143 ## Search the help text, if we can |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
144 if (status == 0 && ! isempty (strfind (lower (text), str))) |
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
145 fun(end+1) = fn; |
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
146 help_text(end+1) = first_sentence; |
8870
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
147 endif |
eea0e1b45ec0
optimize string manipulation in lookfor
Jaroslav Hajek <highegg@gmail.com>
parents:
8866
diff
changeset
|
148 endfor |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
149 endif |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
150 endfor |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
151 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
152 if (nargout == 0) |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
153 ## 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
|
154 indent = 20; |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
155 term_width = (terminal_size ())(2); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
156 desc_width = term_width - indent - 2; |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
157 indent_space = blanks (indent); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
158 for k = 1:length (fun) |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
159 f = fun{k}; |
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
160 f(end+1:indent-1) = " "; |
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
161 puts ([f " "]); |
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
162 lf = length (f); |
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
163 desc = strtrim (strrep (help_text{k}, "\n", " ")); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
164 ldesc = length (desc); |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
165 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
|
166 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
|
167 stop = min (start + desc_width, ldesc); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
168 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
|
169 endfor |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
170 endfor |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
171 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
172 else |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
173 ## Return the results instead of displaying them |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
174 out_fun = fun; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
175 out_help_text = help_text; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
176 endif |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
177 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
178 endfunction |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
179 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
180 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
|
181 load (cache_file); |
8941
b8ed0262b11e
lookfor.m: also match function names
John W. Eaton <jwe@octave.org>
parents:
8940
diff
changeset
|
182 if (! isempty (cache)) |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
183 t1 = strfind (lower (cache (1, :)), str); |
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
184 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
|
185 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
|
186 funs = cache(1, cache_idx); |
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
187 help_texts = cache(3, cache_idx); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
188 else |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
189 funs = help_texts = {}; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
190 endif |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
191 endfunction |
13772
ebefc477607b
lookfor.m: Make search case insensitive.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
192 |