Mercurial > octave-nkf
annotate libinterp/interpfcn/oct-hist.cc @ 15814:1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
* oct-hist.cc (do_history): Return hlist variable. Don't output to
octave_stdout unless requested. (Fhistory): Update docstring. Return
hlist as a cell string if nargout > 0
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Tue, 18 Dec 2012 14:29:15 -0500 |
parents | 049e8bbff782 |
children | dbb7896f15c7 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
3 Copyright (C) 1993-2012 John W. Eaton |
1 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1 | 20 |
2939 | 21 */ |
22 | |
23 /* | |
24 | |
1 | 25 The functions listed below were adapted from similar functions from |
26 GNU Bash, the Bourne Again SHell, copyright (C) 1987, 1989, 1991 Free | |
27 Software Foundation, Inc. | |
28 | |
29 do_history edit_history_readline | |
30 do_edit_history edit_history_add_hist | |
31 | |
32 */ | |
33 | |
240 | 34 #ifdef HAVE_CONFIG_H |
1192 | 35 #include <config.h> |
1 | 36 #endif |
37 | |
1343 | 38 #include <cstdlib> |
39 #include <cstring> | |
40 | |
1750 | 41 #include <string> |
42 | |
3503 | 43 #include <fstream> |
1350 | 44 |
1 | 45 #include <sys/types.h> |
46 #include <unistd.h> | |
1350 | 47 |
1799 | 48 #include "cmd-hist.h" |
1802 | 49 #include "file-ops.h" |
3016 | 50 #include "lo-mappers.h" |
2926 | 51 #include "oct-env.h" |
5305 | 52 #include "oct-time.h" |
1755 | 53 #include "str-vec.h" |
54 | |
2492 | 55 #include <defaults.h> |
1352 | 56 #include "defun.h" |
1 | 57 #include "error.h" |
3016 | 58 #include "gripes.h" |
1 | 59 #include "input.h" |
1742 | 60 #include "oct-hist.h" |
1750 | 61 #include "oct-obj.h" |
1352 | 62 #include "pager.h" |
3018 | 63 #include "parse.h" |
1352 | 64 #include "sighandlers.h" |
1690 | 65 #include "sysdep.h" |
1750 | 66 #include "toplev.h" |
1352 | 67 #include "unwind-prot.h" |
68 #include "utils.h" | |
2205 | 69 #include "variables.h" |
1 | 70 |
3018 | 71 // TRUE means input is coming from temporary history file. |
72 bool input_from_tmp_history_file = false; | |
168 | 73 |
5305 | 74 static std::string |
1 | 75 default_history_file (void) |
76 { | |
3523 | 77 std::string file; |
1 | 78 |
3523 | 79 std::string env_file = octave_env::getenv ("OCTAVE_HISTFILE"); |
1755 | 80 |
2926 | 81 if (! env_file.empty ()) |
6141 | 82 file = env_file; |
1 | 83 |
1755 | 84 if (file.empty ()) |
7272 | 85 file = file_ops::concat (octave_env::get_home_directory (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
86 ".octave_hist"); |
1 | 87 |
88 return file; | |
89 } | |
90 | |
5305 | 91 static int |
92 default_history_size (void) | |
93 { | |
94 int size = 1024; | |
95 | |
96 std::string env_size = octave_env::getenv ("OCTAVE_HISTSIZE"); | |
97 | |
98 if (! env_size.empty ()) | |
99 { | |
100 int val; | |
101 | |
102 if (sscanf (env_size.c_str (), "%d", &val) == 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
103 size = val > 0 ? val : 0; |
5305 | 104 } |
105 | |
106 return size; | |
107 } | |
108 | |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
109 static std::string |
5305 | 110 default_history_timestamp_format (void) |
111 { | |
112 return | |
113 std::string ("# Octave " OCTAVE_VERSION ", %a %b %d %H:%M:%S %Y %Z <") | |
114 + octave_env::get_user_name () | |
115 + std::string ("@") | |
116 + octave_env::get_host_name () | |
117 + std::string (">"); | |
118 } | |
119 | |
5794 | 120 // The format of the timestamp marker written to the history file when |
121 // Octave exits. | |
122 static std::string Vhistory_timestamp_format_string | |
123 = default_history_timestamp_format (); | |
124 | |
581 | 125 // Display, save, or load history. Stolen and modified from bash. |
126 // | |
127 // Arg of -w FILENAME means write file, arg of -r FILENAME | |
128 // means read file, arg of -q means don't number lines. Arg of N | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
129 // means only display that many items. |
581 | 130 |
15814
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
131 static string_vector |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
132 do_history (int argc, const string_vector& argv, bool output = true) |
1 | 133 { |
134 int numbered_output = 1; | |
135 | |
12990
07dc4839c05f
properly save and restore command history file name in history command (bug #32524)
John W. Eaton <jwe@octave.org>
parents:
12989
diff
changeset
|
136 unwind_protect frame; |
15814
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
137 string_vector hlist; |
12990
07dc4839c05f
properly save and restore command history file name in history command (bug #32524)
John W. Eaton <jwe@octave.org>
parents:
12989
diff
changeset
|
138 |
07dc4839c05f
properly save and restore command history file name in history command (bug #32524)
John W. Eaton <jwe@octave.org>
parents:
12989
diff
changeset
|
139 frame.add_fcn (command_history::set_file, command_history::file ()); |
07dc4839c05f
properly save and restore command history file name in history command (bug #32524)
John W. Eaton <jwe@octave.org>
parents:
12989
diff
changeset
|
140 |
1755 | 141 int i; |
142 for (i = 1; i < argc; i++) | |
1 | 143 { |
3523 | 144 std::string option = argv[i]; |
2435 | 145 |
146 if (option == "-r" || option == "-w" || option == "-a" | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
147 || option == "-n") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
148 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
149 if (i < argc - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
150 command_history::set_file (argv[i+1]); |
1 | 151 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
152 if (option == "-a") |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
153 // Append 'new' lines to file. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
154 command_history::append (); |
2435 | 155 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
156 else if (option == "-w") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
157 // Write entire history. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
158 command_history::write (); |
777 | 159 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
160 else if (option == "-r") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
161 // Read entire file. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
162 command_history::read (); |
777 | 163 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
164 else if (option == "-n") |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
165 // Read 'new' history from file. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
166 command_history::read_range (); |
777 | 167 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
168 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
169 panic_impossible (); |
2435 | 170 |
15814
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
171 return hlist; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
172 } |
1755 | 173 else if (argv[i] == "-q") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
174 numbered_output = 0; |
1755 | 175 else if (argv[i] == "--") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
176 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
177 i++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
178 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
179 } |
1 | 180 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
181 break; |
1 | 182 } |
183 | |
1799 | 184 int limit = -1; |
1 | 185 |
1755 | 186 if (i < argc) |
1 | 187 { |
1755 | 188 if (sscanf (argv[i].c_str (), "%d", &limit) != 1) |
1 | 189 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
190 if (argv[i][0] == '-') |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
191 error ("history: unrecognized option '%s'", argv[i].c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
192 else |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
193 error ("history: bad non-numeric arg '%s'", argv[i].c_str ()); |
1799 | 194 |
15814
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
195 return hlist; |
1 | 196 } |
197 | |
198 if (limit < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
199 limit = -limit; |
1799 | 200 } |
1 | 201 |
15814
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
202 hlist = command_history::list (limit, numbered_output); |
1 | 203 |
1799 | 204 int len = hlist.length (); |
205 | |
15814
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
206 if (output) |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
207 for (i = 0; i < len; i++) |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
208 octave_stdout << hlist[i] << "\n"; |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
209 |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
210 return hlist; |
1 | 211 } |
212 | |
581 | 213 // Read the edited history lines from STREAM and return them |
214 // one at a time. This can read unlimited length lines. The | |
2434 | 215 // caller should free the storage. |
581 | 216 |
1 | 217 static char * |
3551 | 218 edit_history_readline (std::fstream& stream) |
1 | 219 { |
220 char c; | |
221 int line_len = 128; | |
222 int lindex = 0; | |
223 char *line = new char [line_len]; | |
224 line[0] = '\0'; | |
225 | |
226 while (stream.get (c)) | |
227 { | |
228 if (lindex + 2 >= line_len) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
229 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
230 char *tmp_line = new char [line_len += 128]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
231 strcpy (tmp_line, line); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
232 delete [] line; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
233 line = tmp_line; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
234 } |
1 | 235 |
236 if (c == '\n') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
237 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
238 line[lindex++] = '\n'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
239 line[lindex++] = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
240 return line; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
241 } |
1 | 242 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
243 line[lindex++] = c; |
1 | 244 } |
245 | |
246 if (! lindex) | |
247 { | |
248 delete [] line; | |
529 | 249 return 0; |
1 | 250 } |
251 | |
252 if (lindex + 2 >= line_len) | |
253 { | |
254 char *tmp_line = new char [lindex+3]; | |
255 strcpy (tmp_line, line); | |
256 delete [] line; | |
257 line = tmp_line; | |
258 } | |
259 | |
1358 | 260 // Finish with newline if none in file. |
1 | 261 |
262 line[lindex++] = '\n'; | |
263 line[lindex++] = '\0'; | |
264 return line; | |
265 } | |
266 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
267 // Use 'command' to replace the last entry in the history list, which, |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
268 // by this time, is 'run_history blah...'. The intent is that the |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
269 // new command becomes the history entry, and that 'fc' should never |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
270 // appear in the history list. This way you can do 'run_history' to |
581 | 271 // your heart's content. |
272 | |
64 | 273 static void |
3523 | 274 edit_history_repl_hist (const std::string& command) |
64 | 275 { |
1799 | 276 if (! command.empty ()) |
277 { | |
2926 | 278 string_vector hlist = command_history::list (); |
64 | 279 |
1799 | 280 int len = hlist.length (); |
64 | 281 |
1799 | 282 if (len > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
283 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
284 int i = len - 1; |
64 | 285 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
286 std::string histent = command_history::get_entry (i); |
64 | 287 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
288 if (! histent.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
289 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
290 std::string cmd = command; |
64 | 291 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
292 int cmd_len = cmd.length (); |
64 | 293 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
294 if (cmd[cmd_len - 1] == '\n') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
295 cmd.resize (cmd_len - 1); |
64 | 296 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
297 if (! cmd.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
298 command_history::replace_entry (i, cmd); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
299 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
300 } |
64 | 301 } |
302 } | |
303 | |
1 | 304 static void |
3523 | 305 edit_history_add_hist (const std::string& line) |
1 | 306 { |
1799 | 307 if (! line.empty ()) |
1 | 308 { |
3523 | 309 std::string tmp = line; |
1 | 310 |
1799 | 311 int len = tmp.length (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
312 |
1799 | 313 if (len > 0 && tmp[len-1] == '\n') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
314 tmp.resize (len - 1); |
1799 | 315 |
316 if (! tmp.empty ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
317 command_history::add (tmp); |
1 | 318 } |
319 } | |
320 | |
3536 | 321 static std::string |
1755 | 322 mk_tmp_hist_file (int argc, const string_vector& argv, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
323 int insert_curr, const char *warn_for) |
1 | 324 { |
3523 | 325 std::string retval; |
1 | 326 |
2926 | 327 string_vector hlist = command_history::list (); |
1 | 328 |
1799 | 329 int hist_count = hlist.length (); |
1 | 330 |
1358 | 331 // The current command line is already part of the history list by |
332 // the time we get to this point. Delete it from the list. | |
1 | 333 |
334 hist_count -= 2; | |
1799 | 335 |
64 | 336 if (! insert_curr) |
2926 | 337 command_history::remove (hist_count); |
1799 | 338 |
1 | 339 hist_count--; |
340 | |
1358 | 341 // If no numbers have been specified, the default is to edit the |
342 // last command in the history list. | |
1 | 343 |
344 int hist_end = hist_count; | |
345 int hist_beg = hist_count; | |
346 int reverse = 0; | |
347 | |
1358 | 348 // Process options. |
1 | 349 |
350 int usage_error = 0; | |
351 if (argc == 3) | |
352 { | |
1755 | 353 if (sscanf (argv[1].c_str (), "%d", &hist_beg) != 1 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
354 || sscanf (argv[2].c_str (), "%d", &hist_end) != 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
355 usage_error = 1; |
1 | 356 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
357 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
358 hist_beg--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
359 hist_end--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
360 } |
1 | 361 } |
362 else if (argc == 2) | |
363 { | |
1755 | 364 if (sscanf (argv[1].c_str (), "%d", &hist_beg) != 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
365 usage_error = 1; |
1 | 366 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
367 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
368 hist_beg--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
369 hist_end = hist_beg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
370 } |
1 | 371 } |
372 | |
373 if (hist_beg < 0 || hist_end < 0 || hist_beg > hist_count | |
374 || hist_end > hist_count) | |
375 { | |
64 | 376 error ("%s: history specification out of range", warn_for); |
1799 | 377 return retval; |
1 | 378 } |
379 | |
380 if (usage_error) | |
381 { | |
64 | 382 usage ("%s [first] [last]", warn_for); |
1799 | 383 return retval; |
1 | 384 } |
385 | |
386 if (hist_end < hist_beg) | |
387 { | |
388 int t = hist_end; | |
389 hist_end = hist_beg; | |
390 hist_beg = t; | |
391 reverse = 1; | |
392 } | |
393 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
394 std::string name = octave_tempnam ("", "oct-"); |
1 | 395 |
3551 | 396 std::fstream file (name.c_str (), std::ios::out); |
64 | 397 |
1 | 398 if (! file) |
399 { | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
400 error ("%s: couldn't open temporary file '%s'", warn_for, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
401 name.c_str ()); |
1799 | 402 return retval; |
1 | 403 } |
404 | |
405 if (reverse) | |
406 { | |
407 for (int i = hist_end; i >= hist_beg; i--) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
408 file << hlist[i] << "\n"; |
1 | 409 } |
410 else | |
411 { | |
412 for (int i = hist_beg; i <= hist_end; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
413 file << hlist[i] << "\n"; |
1 | 414 } |
415 | |
416 file.close (); | |
417 | |
1755 | 418 return name; |
64 | 419 } |
420 | |
10411 | 421 static void |
422 unlink_cleanup (const char *file) | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
423 { |
10411 | 424 gnulib::unlink (file); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
425 } |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
426 |
1755 | 427 static void |
428 do_edit_history (int argc, const string_vector& argv) | |
64 | 429 { |
3523 | 430 std::string name = mk_tmp_hist_file (argc, argv, 0, "edit_history"); |
64 | 431 |
1755 | 432 if (name.empty ()) |
64 | 433 return; |
434 | |
1358 | 435 // Call up our favorite editor on the file of commands. |
1 | 436 |
5794 | 437 std::string cmd = VEDITOR; |
4469 | 438 cmd.append (" \""); |
1799 | 439 cmd.append (name); |
4469 | 440 cmd.append ("\""); |
1 | 441 |
1358 | 442 // Ignore interrupts while we are off editing commands. Should we |
443 // maybe avoid using system()? | |
1 | 444 |
2705 | 445 volatile octave_interrupt_handler old_interrupt_handler |
2554 | 446 = octave_ignore_interrupts (); |
1443 | 447 |
1799 | 448 system (cmd.c_str ()); |
1443 | 449 |
2554 | 450 octave_set_interrupt_handler (old_interrupt_handler); |
1 | 451 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
452 // Write the commands to the history file since source_file |
1358 | 453 // disables command line history while it executes. |
1 | 454 |
3551 | 455 std::fstream file (name.c_str (), std::ios::in); |
1 | 456 |
457 char *line; | |
64 | 458 int first = 1; |
529 | 459 while ((line = edit_history_readline (file)) != 0) |
1 | 460 { |
1358 | 461 // Skip blank lines. |
1 | 462 |
463 if (line[0] == '\n') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
464 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
465 delete [] line; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
466 continue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
467 } |
1 | 468 |
64 | 469 if (first) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
470 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
471 first = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
472 edit_history_repl_hist (line); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
473 } |
64 | 474 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
475 edit_history_add_hist (line); |
1 | 476 } |
477 | |
478 file.close (); | |
479 | |
1358 | 480 // Turn on command echo, so the output from this will make better |
481 // sense. | |
1 | 482 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
483 unwind_protect frame; |
3018 | 484 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
485 frame.add_fcn (unlink_cleanup, name.c_str ()); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
486 frame.protect_var (Vecho_executing_commands); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
487 frame.protect_var (input_from_tmp_history_file); |
3018 | 488 |
2205 | 489 Vecho_executing_commands = ECHO_CMD_LINE; |
3018 | 490 input_from_tmp_history_file = true; |
1 | 491 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
492 source_file (name); |
1 | 493 } |
494 | |
1755 | 495 static void |
496 do_run_history (int argc, const string_vector& argv) | |
64 | 497 { |
3523 | 498 std::string name = mk_tmp_hist_file (argc, argv, 1, "run_history"); |
64 | 499 |
1755 | 500 if (name.empty ()) |
64 | 501 return; |
502 | |
1799 | 503 // Turn on command echo so the output from this will make better |
1358 | 504 // sense. |
64 | 505 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
506 unwind_protect frame; |
3018 | 507 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
508 frame.add_fcn (unlink_cleanup, name.c_str ()); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
509 frame.protect_var (Vecho_executing_commands); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
510 frame.protect_var (input_from_tmp_history_file); |
3018 | 511 |
2205 | 512 Vecho_executing_commands = ECHO_CMD_LINE; |
3018 | 513 input_from_tmp_history_file = true; |
64 | 514 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
515 source_file (name); |
64 | 516 } |
517 | |
5305 | 518 void |
8273
2c1ba965b486
skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
519 initialize_history (bool read_history_file) |
5794 | 520 { |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
521 command_history::initialize (read_history_file, |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
522 default_history_file (), |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
523 default_history_size (), |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
524 octave_env::getenv ("OCTAVE_HISTCONTROL")); |
5794 | 525 } |
526 | |
527 void | |
5305 | 528 octave_history_write_timestamp (void) |
529 { | |
530 octave_localtime now; | |
531 | |
532 std::string timestamp = now.strftime (Vhistory_timestamp_format_string); | |
533 | |
534 if (! timestamp.empty ()) | |
535 command_history::add (timestamp); | |
536 } | |
537 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8286
diff
changeset
|
538 DEFUN (edit_history, args, , |
3332 | 539 "-*- texinfo -*-\n\ |
11547 | 540 @deftypefn {Command} {} edit_history [@var{first}] [@var{last}]\n\ |
3332 | 541 If invoked with no arguments, @code{edit_history} allows you to edit the\n\ |
10840 | 542 history list using the editor named by the variable @w{@env{EDITOR}}. The\n\ |
3332 | 543 commands to be edited are first copied to a temporary file. When you\n\ |
544 exit the editor, Octave executes the commands that remain in the file.\n\ | |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
545 It is often more convenient to use @code{edit_history} to define functions\n\ |
3332 | 546 rather than attempting to enter them directly on the command line.\n\ |
547 By default, the block of commands is executed as soon as you exit the\n\ | |
548 editor. To avoid executing any commands, simply delete all the lines\n\ | |
549 from the buffer before exiting the editor.\n\ | |
550 \n\ | |
551 The @code{edit_history} command takes two optional arguments specifying\n\ | |
552 the history numbers of first and last commands to edit. For example,\n\ | |
553 the command\n\ | |
529 | 554 \n\ |
3332 | 555 @example\n\ |
556 edit_history 13\n\ | |
557 @end example\n\ | |
558 \n\ | |
559 @noindent\n\ | |
560 extracts all the commands from the 13th through the last in the history\n\ | |
561 list. The command\n\ | |
562 \n\ | |
563 @example\n\ | |
564 edit_history 13 169\n\ | |
565 @end example\n\ | |
566 \n\ | |
567 @noindent\n\ | |
568 only extracts commands 13 through 169. Specifying a larger number for\n\ | |
569 the first command than the last command reverses the list of commands\n\ | |
570 before placing them in the buffer to be edited. If both arguments are\n\ | |
571 omitted, the previous command in the history list is used.\n\ | |
9035
57649dcecb55
Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
572 @seealso{run_history}\n\ |
11547 | 573 @end deftypefn") |
529 | 574 { |
2086 | 575 octave_value_list retval; |
529 | 576 |
1755 | 577 int argc = args.length () + 1; |
578 | |
1968 | 579 string_vector argv = args.make_argv ("edit_history"); |
1755 | 580 |
581 if (error_state) | |
582 return retval; | |
529 | 583 |
584 do_edit_history (argc, argv); | |
585 | |
586 return retval; | |
587 } | |
588 | |
15814
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
589 DEFUN (history, args, nargout, |
3332 | 590 "-*- texinfo -*-\n\ |
15814
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
591 @deftypefn {Command} history options\n\ |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
592 @deftypefnx {Built-in Function} {@var{h} = } history (@var{opt1}, @var{opt2}, @dots{})\n\ |
3332 | 593 If invoked with no arguments, @code{history} displays a list of commands\n\ |
594 that you have executed. Valid options are:\n\ | |
595 \n\ | |
596 @table @code\n\ | |
597 @item -w @var{file}\n\ | |
598 Write the current history to the file @var{file}. If the name is\n\ | |
599 omitted, use the default history file (normally @file{~/.octave_hist}).\n\ | |
529 | 600 \n\ |
3332 | 601 @item -r @var{file}\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
602 Read the file @var{file}, appending its contents to the current\n\ |
11405
51b6193e90bb
Documentation fixes
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11368
diff
changeset
|
603 history list. If the name is omitted, use the default history file\n\ |
3332 | 604 (normally @file{~/.octave_hist}).\n\ |
605 \n\ | |
3499 | 606 @item @var{n}\n\ |
9035
57649dcecb55
Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
607 Display only the most recent @var{n} lines of history.\n\ |
3332 | 608 \n\ |
609 @item -q\n\ | |
610 Don't number the displayed lines of history. This is useful for cutting\n\ | |
9035
57649dcecb55
Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
611 and pasting commands using the X Window System.\n\ |
3332 | 612 @end table\n\ |
613 \n\ | |
614 For example, to display the five most recent commands that you have\n\ | |
615 typed without displaying line numbers, use the command\n\ | |
616 @kbd{history -q 5}.\n\ | |
15814
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
617 \n\ |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
618 If invoked with a single output argument, the history will be saved to that\n\ |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
619 argument as a cell string and will not be output to screen.\n\ |
11547 | 620 @end deftypefn") |
529 | 621 { |
2086 | 622 octave_value_list retval; |
529 | 623 |
1755 | 624 int argc = args.length () + 1; |
625 | |
1968 | 626 string_vector argv = args.make_argv ("history"); |
1755 | 627 |
628 if (error_state) | |
629 return retval; | |
529 | 630 |
15814
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
631 string_vector hlist; |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
632 if (nargout > 0) |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
633 { |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
634 argv.append (std::string ("-q")); |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
635 argc++; |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
636 hlist = do_history (argc, argv, false); |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
637 retval(0) = Cell (hlist); |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
638 } |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
639 else |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
640 do_history (argc, argv, true); |
529 | 641 |
642 return retval; | |
643 } | |
644 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8286
diff
changeset
|
645 DEFUN (run_history, args, , |
3332 | 646 "-*- texinfo -*-\n\ |
11547 | 647 @deftypefn {Command} {} run_history [@var{first}] [@var{last}]\n\ |
3332 | 648 Similar to @code{edit_history}, except that the editor is not invoked,\n\ |
649 and the commands are simply executed as they appear in the history list.\n\ | |
9035
57649dcecb55
Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
650 @seealso{edit_history}\n\ |
11547 | 651 @end deftypefn") |
529 | 652 { |
2086 | 653 octave_value_list retval; |
529 | 654 |
1755 | 655 int argc = args.length () + 1; |
656 | |
1968 | 657 string_vector argv = args.make_argv ("run_history"); |
1755 | 658 |
659 if (error_state) | |
660 return retval; | |
529 | 661 |
662 do_run_history (argc, argv); | |
663 | |
664 return retval; | |
665 } | |
666 | |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
667 DEFUN (history_control, args, nargout, |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
668 "-*- texinfo -*-\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
669 @deftypefn {Built-in Function} {@var{val} =} history_control ()\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
670 @deftypefnx {Built-in Function} {@var{old_val} =} history_control (@var{new_val})\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
671 Query or set the internal variable that specifies how commands are saved\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
672 to the history list. The default value is an empty character string,\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
673 but may be overridden by the environment variable\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
674 @w{@env{OCTAVE_HISTCONTROL}}.\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
675 \n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
676 The value of @code{history_control} is a colon-separated list of values\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11547
diff
changeset
|
677 controlling how commands are saved on the history list. If the list\n\ |
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11547
diff
changeset
|
678 of values includes @code{ignorespace}, lines which begin with a space\n\ |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
679 character are not saved in the history list. A value of @code{ignoredups}\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
680 causes lines matching the previous history entry to not be saved.\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
681 A value of @code{ignoreboth} is shorthand for @code{ignorespace} and\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
682 @code{ignoredups}. A value of @code{erasedups} causes all previous lines\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
683 matching the current line to be removed from the history list before that\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
684 line is saved. Any value not in the above list is ignored. If\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
685 @code{history_control} is the empty string, all commands are saved on\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
686 the history list, subject to the value of @code{saving_history}.\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
687 @seealso{history_file, history_size, history_timestamp_format_string, saving_history}\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
688 @end deftypefn") |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
689 { |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
690 std::string old_history_control = command_history::histcontrol (); |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
691 |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
692 std::string tmp = old_history_control; |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
693 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
694 octave_value retval = set_internal_variable (tmp, args, nargout, |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
695 "history_control"); |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
696 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
697 if (tmp != old_history_control) |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
698 command_history::process_histcontrol (tmp); |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
699 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
700 return retval; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
701 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
702 |
5794 | 703 DEFUN (history_size, args, nargout, |
704 "-*- texinfo -*-\n\ | |
10840 | 705 @deftypefn {Built-in Function} {@var{val} =} history_size ()\n\ |
5794 | 706 @deftypefnx {Built-in Function} {@var{old_val} =} history_size (@var{new_val})\n\ |
707 Query or set the internal variable that specifies how many entries\n\ | |
708 to store in the history file. The default value is @code{1024},\n\ | |
10840 | 709 but may be overridden by the environment variable @w{@env{OCTAVE_HISTSIZE}}.\n\ |
8286
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8273
diff
changeset
|
710 @seealso{history_file, history_timestamp_format_string, saving_history}\n\ |
5794 | 711 @end deftypefn") |
3016 | 712 { |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
713 int old_history_size = command_history::size (); |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
714 |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
715 int tmp = old_history_size; |
5800 | 716 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
717 octave_value retval = set_internal_variable (tmp, args, nargout, |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
718 "history_size", -1, |
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
719 std::numeric_limits<int>::max ()); |
5800 | 720 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
721 if (tmp != old_history_size) |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
722 command_history::set_size (tmp); |
5800 | 723 |
724 return retval; | |
3016 | 725 } |
726 | |
5794 | 727 DEFUN (history_file, args, nargout, |
728 "-*- texinfo -*-\n\ | |
10840 | 729 @deftypefn {Built-in Function} {@var{val} =} history_file ()\n\ |
5794 | 730 @deftypefnx {Built-in Function} {@var{old_val} =} history_file (@var{new_val})\n\ |
731 Query or set the internal variable that specifies the name of the\n\ | |
732 file used to store command history. The default value is\n\ | |
9134
a3739e27b017
Update section 2.4 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9035
diff
changeset
|
733 @file{~/.octave_hist}, but may be overridden by the environment\n\ |
10840 | 734 variable @w{@env{OCTAVE_HISTFILE}}.\n\ |
5794 | 735 @seealso{history_size, saving_history, history_timestamp_format_string}\n\ |
736 @end deftypefn") | |
5305 | 737 { |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
738 std::string old_history_file = command_history::file (); |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
739 |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
740 std::string tmp = old_history_file; |
5305 | 741 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
742 octave_value retval = set_internal_variable (tmp, args, nargout, |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
743 "history_file"); |
5305 | 744 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
745 if (tmp != old_history_file) |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
746 command_history::set_file (tmp); |
5305 | 747 |
5800 | 748 return retval; |
3016 | 749 } |
750 | |
5794 | 751 DEFUN (history_timestamp_format_string, args, nargout, |
752 "-*- texinfo -*-\n\ | |
10840 | 753 @deftypefn {Built-in Function} {@var{val} =} history_timestamp_format_string ()\n\ |
5794 | 754 @deftypefnx {Built-in Function} {@var{old_val} =} history_timestamp_format_string (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12990
diff
changeset
|
755 @deftypefnx {Built-in Function} {} history_timestamp_format_string (@var{new_val}, \"local\")\n\ |
6653 | 756 Query or set the internal variable that specifies the format string\n\ |
5794 | 757 for the comment line that is written to the history file when Octave\n\ |
758 exits. The format string is passed to @code{strftime}. The default\n\ | |
759 value is\n\ | |
5305 | 760 \n\ |
761 @example\n\ | |
762 \"# Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>\"\n\ | |
763 @end example\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12990
diff
changeset
|
764 \n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12990
diff
changeset
|
765 When called from inside a function with the \"local\" option, the variable is\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12990
diff
changeset
|
766 changed locally for the function and any subroutines it calls. The original\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12990
diff
changeset
|
767 variable value is restored when exiting the function.\n\ |
5794 | 768 @seealso{strftime, history_file, history_size, saving_history}\n\ |
769 @end deftypefn") | |
770 { | |
771 return SET_INTERNAL_VARIABLE (history_timestamp_format_string); | |
772 } | |
5305 | 773 |
5794 | 774 DEFUN (saving_history, args, nargout, |
775 "-*- texinfo -*-\n\ | |
10840 | 776 @deftypefn {Built-in Function} {@var{val} =} saving_history ()\n\ |
5794 | 777 @deftypefnx {Built-in Function} {@var{old_val} =} saving_history (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12990
diff
changeset
|
778 @deftypefnx {Built-in Function} {} saving_history (@var{new_val}, \"local\")\n\ |
5794 | 779 Query or set the internal variable that controls whether commands entered\n\ |
780 on the command line are saved in the history file.\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12990
diff
changeset
|
781 \n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12990
diff
changeset
|
782 When called from inside a function with the \"local\" option, the variable is\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12990
diff
changeset
|
783 changed locally for the function and any subroutines it calls. The original\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12990
diff
changeset
|
784 variable value is restored when exiting the function.\n\ |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
785 @seealso{history_control, history_file, history_size, history_timestamp_format_string}\n\ |
5794 | 786 @end deftypefn") |
787 { | |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
788 bool old_saving_history = ! command_history::ignoring_entries (); |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
789 |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
790 bool tmp = old_saving_history; |
5794 | 791 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
792 octave_value retval = set_internal_variable (tmp, args, nargout, |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
793 "saving_history"); |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
794 |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
795 if (tmp != old_saving_history) |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
796 command_history::ignore_entries (! tmp); |
5794 | 797 |
798 return retval; | |
3016 | 799 } |