Mercurial > hg > octave-nkf
annotate src/oct-hist.cc @ 12385:c468c5b902b3 release-3-4-x ss-3-3-92
version is now 3.3.92
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 06 Feb 2011 06:27:19 -0500 |
parents | 12df7854fa7c |
children | f96b9b9f141b |
rev | line source |
---|---|
1 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1993-2011 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 | |
5794 | 91 // Where history is saved. |
92 static std::string Vhistory_file = default_history_file (); | |
93 | |
5305 | 94 static int |
95 default_history_size (void) | |
96 { | |
97 int size = 1024; | |
98 | |
99 std::string env_size = octave_env::getenv ("OCTAVE_HISTSIZE"); | |
100 | |
101 if (! env_size.empty ()) | |
102 { | |
103 int val; | |
104 | |
105 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
|
106 size = val > 0 ? val : 0; |
5305 | 107 } |
108 | |
109 return size; | |
110 } | |
111 | |
5794 | 112 // The number of lines to keep in the history file. |
113 static int Vhistory_size = default_history_size (); | |
114 | |
5305 | 115 static std::string |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
116 default_history_control (void) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
117 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
118 std::string retval; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
119 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
120 std::string env_histcontrol = octave_env::getenv ("OCTAVE_HISTCONTROL"); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
121 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
122 if (! env_histcontrol.empty ()) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
123 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
124 return env_histcontrol; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
125 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
126 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
127 return retval; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
128 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
129 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
130 // The number of lines to keep in the history file. |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
131 static std::string Vhistory_control = default_history_control (); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
132 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
133 static std::string |
5305 | 134 default_history_timestamp_format (void) |
135 { | |
136 return | |
137 std::string ("# Octave " OCTAVE_VERSION ", %a %b %d %H:%M:%S %Y %Z <") | |
138 + octave_env::get_user_name () | |
139 + std::string ("@") | |
140 + octave_env::get_host_name () | |
141 + std::string (">"); | |
142 } | |
143 | |
5794 | 144 // The format of the timestamp marker written to the history file when |
145 // Octave exits. | |
146 static std::string Vhistory_timestamp_format_string | |
147 = default_history_timestamp_format (); | |
148 | |
149 // TRUE if we are saving history. | |
150 bool Vsaving_history = true; | |
151 | |
581 | 152 // Display, save, or load history. Stolen and modified from bash. |
153 // | |
154 // Arg of -w FILENAME means write file, arg of -r FILENAME | |
155 // 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
|
156 // means only display that many items. |
581 | 157 |
1755 | 158 static void |
159 do_history (int argc, const string_vector& argv) | |
1 | 160 { |
161 int numbered_output = 1; | |
162 | |
1755 | 163 int i; |
164 for (i = 1; i < argc; i++) | |
1 | 165 { |
3523 | 166 std::string option = argv[i]; |
2435 | 167 |
168 if (option == "-r" || option == "-w" || option == "-a" | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
169 || option == "-n") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
170 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
171 if (i < argc - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
172 command_history::set_file (argv[i+1]); |
1 | 173 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
174 if (option == "-a") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
175 // Append `new' lines to file. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
176 command_history::append (); |
2435 | 177 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
178 else if (option == "-w") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
179 // Write entire history. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
180 command_history::write (); |
777 | 181 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
182 else if (option == "-r") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
183 // Read entire file. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
184 command_history::read (); |
777 | 185 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
186 else if (option == "-n") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
187 // Read `new' history from file. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
188 command_history::read_range (); |
777 | 189 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
190 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
191 panic_impossible (); |
2435 | 192 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
193 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
194 } |
1755 | 195 else if (argv[i] == "-q") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
196 numbered_output = 0; |
1755 | 197 else if (argv[i] == "--") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
198 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
199 i++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
200 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
201 } |
1 | 202 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
203 break; |
1 | 204 } |
205 | |
1799 | 206 int limit = -1; |
1 | 207 |
1755 | 208 if (i < argc) |
1 | 209 { |
1755 | 210 if (sscanf (argv[i].c_str (), "%d", &limit) != 1) |
1 | 211 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
212 if (argv[i][0] == '-') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
213 error ("history: unrecognized option `%s'", argv[i].c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
214 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
215 error ("history: bad non-numeric arg `%s'", argv[i].c_str ()); |
1799 | 216 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
217 return; |
1 | 218 } |
219 | |
220 if (limit < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
221 limit = -limit; |
1799 | 222 } |
1 | 223 |
2926 | 224 string_vector hlist = command_history::list (limit, numbered_output); |
1 | 225 |
1799 | 226 int len = hlist.length (); |
227 | |
2095 | 228 for (i = 0; i < len; i++) |
229 octave_stdout << hlist[i] << "\n"; | |
1 | 230 } |
231 | |
581 | 232 // Read the edited history lines from STREAM and return them |
233 // one at a time. This can read unlimited length lines. The | |
2434 | 234 // caller should free the storage. |
581 | 235 |
1 | 236 static char * |
3551 | 237 edit_history_readline (std::fstream& stream) |
1 | 238 { |
239 char c; | |
240 int line_len = 128; | |
241 int lindex = 0; | |
242 char *line = new char [line_len]; | |
243 line[0] = '\0'; | |
244 | |
245 while (stream.get (c)) | |
246 { | |
247 if (lindex + 2 >= line_len) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
248 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
249 char *tmp_line = new char [line_len += 128]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
250 strcpy (tmp_line, line); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
251 delete [] line; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
252 line = tmp_line; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
253 } |
1 | 254 |
255 if (c == '\n') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
256 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
257 line[lindex++] = '\n'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
258 line[lindex++] = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
259 return line; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
260 } |
1 | 261 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
262 line[lindex++] = c; |
1 | 263 } |
264 | |
265 if (! lindex) | |
266 { | |
267 delete [] line; | |
529 | 268 return 0; |
1 | 269 } |
270 | |
271 if (lindex + 2 >= line_len) | |
272 { | |
273 char *tmp_line = new char [lindex+3]; | |
274 strcpy (tmp_line, line); | |
275 delete [] line; | |
276 line = tmp_line; | |
277 } | |
278 | |
1358 | 279 // Finish with newline if none in file. |
1 | 280 |
281 line[lindex++] = '\n'; | |
282 line[lindex++] = '\0'; | |
283 return line; | |
284 } | |
285 | |
581 | 286 // Use `command' to replace the last entry in the history list, which, |
287 // by this time, is `run_history blah...'. The intent is that the | |
1799 | 288 // new command becomes the history entry, and that `fc' should never |
581 | 289 // appear in the history list. This way you can do `run_history' to |
290 // your heart's content. | |
291 | |
64 | 292 static void |
3523 | 293 edit_history_repl_hist (const std::string& command) |
64 | 294 { |
1799 | 295 if (! command.empty ()) |
296 { | |
2926 | 297 string_vector hlist = command_history::list (); |
64 | 298 |
1799 | 299 int len = hlist.length (); |
64 | 300 |
1799 | 301 if (len > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
302 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
303 int i = len - 1; |
64 | 304 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
305 std::string histent = command_history::get_entry (i); |
64 | 306 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
307 if (! histent.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
308 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
309 std::string cmd = command; |
64 | 310 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
311 int cmd_len = cmd.length (); |
64 | 312 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
313 if (cmd[cmd_len - 1] == '\n') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
314 cmd.resize (cmd_len - 1); |
64 | 315 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
316 if (! cmd.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
317 command_history::replace_entry (i, cmd); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
318 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
319 } |
64 | 320 } |
321 } | |
322 | |
1 | 323 static void |
3523 | 324 edit_history_add_hist (const std::string& line) |
1 | 325 { |
1799 | 326 if (! line.empty ()) |
1 | 327 { |
3523 | 328 std::string tmp = line; |
1 | 329 |
1799 | 330 int len = tmp.length (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
331 |
1799 | 332 if (len > 0 && tmp[len-1] == '\n') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
333 tmp.resize (len - 1); |
1799 | 334 |
335 if (! tmp.empty ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
336 command_history::add (tmp); |
1 | 337 } |
338 } | |
339 | |
3536 | 340 static std::string |
1755 | 341 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
|
342 int insert_curr, const char *warn_for) |
1 | 343 { |
3523 | 344 std::string retval; |
1 | 345 |
2926 | 346 string_vector hlist = command_history::list (); |
1 | 347 |
1799 | 348 int hist_count = hlist.length (); |
1 | 349 |
1358 | 350 // The current command line is already part of the history list by |
351 // the time we get to this point. Delete it from the list. | |
1 | 352 |
353 hist_count -= 2; | |
1799 | 354 |
64 | 355 if (! insert_curr) |
2926 | 356 command_history::remove (hist_count); |
1799 | 357 |
1 | 358 hist_count--; |
359 | |
1358 | 360 // If no numbers have been specified, the default is to edit the |
361 // last command in the history list. | |
1 | 362 |
363 int hist_end = hist_count; | |
364 int hist_beg = hist_count; | |
365 int reverse = 0; | |
366 | |
1358 | 367 // Process options. |
1 | 368 |
369 int usage_error = 0; | |
370 if (argc == 3) | |
371 { | |
1755 | 372 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
|
373 || 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
|
374 usage_error = 1; |
1 | 375 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
376 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
377 hist_beg--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
378 hist_end--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
379 } |
1 | 380 } |
381 else if (argc == 2) | |
382 { | |
1755 | 383 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
|
384 usage_error = 1; |
1 | 385 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
386 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
387 hist_beg--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
388 hist_end = hist_beg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
389 } |
1 | 390 } |
391 | |
392 if (hist_beg < 0 || hist_end < 0 || hist_beg > hist_count | |
393 || hist_end > hist_count) | |
394 { | |
64 | 395 error ("%s: history specification out of range", warn_for); |
1799 | 396 return retval; |
1 | 397 } |
398 | |
399 if (usage_error) | |
400 { | |
64 | 401 usage ("%s [first] [last]", warn_for); |
1799 | 402 return retval; |
1 | 403 } |
404 | |
405 if (hist_end < hist_beg) | |
406 { | |
407 int t = hist_end; | |
408 hist_end = hist_beg; | |
409 hist_beg = t; | |
410 reverse = 1; | |
411 } | |
412 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
413 std::string name = octave_tempnam ("", "oct-"); |
1 | 414 |
3551 | 415 std::fstream file (name.c_str (), std::ios::out); |
64 | 416 |
1 | 417 if (! file) |
418 { | |
1755 | 419 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
|
420 name.c_str ()); |
1799 | 421 return retval; |
1 | 422 } |
423 | |
424 if (reverse) | |
425 { | |
426 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
|
427 file << hlist[i] << "\n"; |
1 | 428 } |
429 else | |
430 { | |
431 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
|
432 file << hlist[i] << "\n"; |
1 | 433 } |
434 | |
435 file.close (); | |
436 | |
1755 | 437 return name; |
64 | 438 } |
439 | |
10411 | 440 static void |
441 unlink_cleanup (const char *file) | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
442 { |
10411 | 443 gnulib::unlink (file); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
444 } |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
445 |
1755 | 446 static void |
447 do_edit_history (int argc, const string_vector& argv) | |
64 | 448 { |
3523 | 449 std::string name = mk_tmp_hist_file (argc, argv, 0, "edit_history"); |
64 | 450 |
1755 | 451 if (name.empty ()) |
64 | 452 return; |
453 | |
1358 | 454 // Call up our favorite editor on the file of commands. |
1 | 455 |
5794 | 456 std::string cmd = VEDITOR; |
4469 | 457 cmd.append (" \""); |
1799 | 458 cmd.append (name); |
4469 | 459 cmd.append ("\""); |
1 | 460 |
1358 | 461 // Ignore interrupts while we are off editing commands. Should we |
462 // maybe avoid using system()? | |
1 | 463 |
2705 | 464 volatile octave_interrupt_handler old_interrupt_handler |
2554 | 465 = octave_ignore_interrupts (); |
1443 | 466 |
1799 | 467 system (cmd.c_str ()); |
1443 | 468 |
2554 | 469 octave_set_interrupt_handler (old_interrupt_handler); |
1 | 470 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
471 // Write the commands to the history file since source_file |
1358 | 472 // disables command line history while it executes. |
1 | 473 |
3551 | 474 std::fstream file (name.c_str (), std::ios::in); |
1 | 475 |
476 char *line; | |
64 | 477 int first = 1; |
529 | 478 while ((line = edit_history_readline (file)) != 0) |
1 | 479 { |
1358 | 480 // Skip blank lines. |
1 | 481 |
482 if (line[0] == '\n') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
483 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
484 delete [] line; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
485 continue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
486 } |
1 | 487 |
64 | 488 if (first) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
489 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
490 first = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
491 edit_history_repl_hist (line); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
492 } |
64 | 493 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
494 edit_history_add_hist (line); |
1 | 495 } |
496 | |
497 file.close (); | |
498 | |
1358 | 499 // Turn on command echo, so the output from this will make better |
500 // sense. | |
1 | 501 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
502 unwind_protect frame; |
3018 | 503 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
504 frame.add_fcn (unlink_cleanup, name.c_str ()); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
505 frame.protect_var (Vecho_executing_commands); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
506 frame.protect_var (input_from_tmp_history_file); |
3018 | 507 |
2205 | 508 Vecho_executing_commands = ECHO_CMD_LINE; |
3018 | 509 input_from_tmp_history_file = true; |
1 | 510 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
511 source_file (name); |
1 | 512 } |
513 | |
1755 | 514 static void |
515 do_run_history (int argc, const string_vector& argv) | |
64 | 516 { |
3523 | 517 std::string name = mk_tmp_hist_file (argc, argv, 1, "run_history"); |
64 | 518 |
1755 | 519 if (name.empty ()) |
64 | 520 return; |
521 | |
1799 | 522 // Turn on command echo so the output from this will make better |
1358 | 523 // sense. |
64 | 524 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
525 unwind_protect frame; |
3018 | 526 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
527 frame.add_fcn (unlink_cleanup, name.c_str ()); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
528 frame.protect_var (Vecho_executing_commands); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
529 frame.protect_var (input_from_tmp_history_file); |
3018 | 530 |
2205 | 531 Vecho_executing_commands = ECHO_CMD_LINE; |
3018 | 532 input_from_tmp_history_file = true; |
64 | 533 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
534 source_file (name); |
64 | 535 } |
536 | |
5305 | 537 void |
8273
2c1ba965b486
skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
538 initialize_history (bool read_history_file) |
5794 | 539 { |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
540 command_history::initialize (read_history_file, Vhistory_file, Vhistory_size, |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
541 Vhistory_control); |
5794 | 542 } |
543 | |
544 void | |
5305 | 545 octave_history_write_timestamp (void) |
546 { | |
547 octave_localtime now; | |
548 | |
549 std::string timestamp = now.strftime (Vhistory_timestamp_format_string); | |
550 | |
551 if (! timestamp.empty ()) | |
552 command_history::add (timestamp); | |
553 } | |
554 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8286
diff
changeset
|
555 DEFUN (edit_history, args, , |
3332 | 556 "-*- texinfo -*-\n\ |
11547 | 557 @deftypefn {Command} {} edit_history [@var{first}] [@var{last}]\n\ |
3332 | 558 If invoked with no arguments, @code{edit_history} allows you to edit the\n\ |
10840 | 559 history list using the editor named by the variable @w{@env{EDITOR}}. The\n\ |
3332 | 560 commands to be edited are first copied to a temporary file. When you\n\ |
561 exit the editor, Octave executes the commands that remain in the file.\n\ | |
562 It is often more convenient to use @code{edit_history} to define functions \n\ | |
563 rather than attempting to enter them directly on the command line.\n\ | |
564 By default, the block of commands is executed as soon as you exit the\n\ | |
565 editor. To avoid executing any commands, simply delete all the lines\n\ | |
566 from the buffer before exiting the editor.\n\ | |
567 \n\ | |
568 The @code{edit_history} command takes two optional arguments specifying\n\ | |
569 the history numbers of first and last commands to edit. For example,\n\ | |
570 the command\n\ | |
529 | 571 \n\ |
3332 | 572 @example\n\ |
573 edit_history 13\n\ | |
574 @end example\n\ | |
575 \n\ | |
576 @noindent\n\ | |
577 extracts all the commands from the 13th through the last in the history\n\ | |
578 list. The command\n\ | |
579 \n\ | |
580 @example\n\ | |
581 edit_history 13 169\n\ | |
582 @end example\n\ | |
583 \n\ | |
584 @noindent\n\ | |
585 only extracts commands 13 through 169. Specifying a larger number for\n\ | |
586 the first command than the last command reverses the list of commands\n\ | |
587 before placing them in the buffer to be edited. If both arguments are\n\ | |
588 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
|
589 @seealso{run_history}\n\ |
11547 | 590 @end deftypefn") |
529 | 591 { |
2086 | 592 octave_value_list retval; |
529 | 593 |
1755 | 594 int argc = args.length () + 1; |
595 | |
1968 | 596 string_vector argv = args.make_argv ("edit_history"); |
1755 | 597 |
598 if (error_state) | |
599 return retval; | |
529 | 600 |
601 do_edit_history (argc, argv); | |
602 | |
603 return retval; | |
604 } | |
605 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8286
diff
changeset
|
606 DEFUN (history, args, , |
3332 | 607 "-*- texinfo -*-\n\ |
11547 | 608 @deftypefn {Command} {} history options\n\ |
3332 | 609 If invoked with no arguments, @code{history} displays a list of commands\n\ |
610 that you have executed. Valid options are:\n\ | |
611 \n\ | |
612 @table @code\n\ | |
613 @item -w @var{file}\n\ | |
614 Write the current history to the file @var{file}. If the name is\n\ | |
615 omitted, use the default history file (normally @file{~/.octave_hist}).\n\ | |
529 | 616 \n\ |
3332 | 617 @item -r @var{file}\n\ |
11405
51b6193e90bb
Documentation fixes
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11368
diff
changeset
|
618 Read the file @var{file}, appending its contents to the current \n\ |
51b6193e90bb
Documentation fixes
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11368
diff
changeset
|
619 history list. If the name is omitted, use the default history file\n\ |
3332 | 620 (normally @file{~/.octave_hist}).\n\ |
621 \n\ | |
3499 | 622 @item @var{n}\n\ |
9035
57649dcecb55
Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
623 Display only the most recent @var{n} lines of history.\n\ |
3332 | 624 \n\ |
625 @item -q\n\ | |
626 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
|
627 and pasting commands using the X Window System.\n\ |
3332 | 628 @end table\n\ |
629 \n\ | |
630 For example, to display the five most recent commands that you have\n\ | |
631 typed without displaying line numbers, use the command\n\ | |
632 @kbd{history -q 5}.\n\ | |
11547 | 633 @end deftypefn") |
529 | 634 { |
2086 | 635 octave_value_list retval; |
529 | 636 |
1755 | 637 int argc = args.length () + 1; |
638 | |
1968 | 639 string_vector argv = args.make_argv ("history"); |
1755 | 640 |
641 if (error_state) | |
642 return retval; | |
529 | 643 |
644 do_history (argc, argv); | |
645 | |
646 return retval; | |
647 } | |
648 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8286
diff
changeset
|
649 DEFUN (run_history, args, , |
3332 | 650 "-*- texinfo -*-\n\ |
11547 | 651 @deftypefn {Command} {} run_history [@var{first}] [@var{last}]\n\ |
3332 | 652 Similar to @code{edit_history}, except that the editor is not invoked,\n\ |
653 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
|
654 @seealso{edit_history}\n\ |
11547 | 655 @end deftypefn") |
529 | 656 { |
2086 | 657 octave_value_list retval; |
529 | 658 |
1755 | 659 int argc = args.length () + 1; |
660 | |
1968 | 661 string_vector argv = args.make_argv ("run_history"); |
1755 | 662 |
663 if (error_state) | |
664 return retval; | |
529 | 665 |
666 do_run_history (argc, argv); | |
667 | |
668 return retval; | |
669 } | |
670 | |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
671 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
|
672 "-*- texinfo -*-\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
673 @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
|
674 @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
|
675 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
|
676 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
|
677 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
|
678 @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
|
679 \n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
680 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
|
681 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
|
682 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
|
683 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
|
684 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
|
685 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
|
686 @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
|
687 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
|
688 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
|
689 @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
|
690 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
|
691 @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
|
692 @end deftypefn") |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
693 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
694 std::string saved_history_control = Vhistory_control; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
695 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
696 octave_value retval = SET_INTERNAL_VARIABLE (history_control); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
697 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
698 if (Vhistory_control != saved_history_control) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
699 command_history::process_histcontrol (Vhistory_control); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
700 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
701 return retval; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
702 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
703 |
5794 | 704 DEFUN (history_size, args, nargout, |
705 "-*- texinfo -*-\n\ | |
10840 | 706 @deftypefn {Built-in Function} {@var{val} =} history_size ()\n\ |
5794 | 707 @deftypefnx {Built-in Function} {@var{old_val} =} history_size (@var{new_val})\n\ |
708 Query or set the internal variable that specifies how many entries\n\ | |
709 to store in the history file. The default value is @code{1024},\n\ | |
10840 | 710 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
|
711 @seealso{history_file, history_timestamp_format_string, saving_history}\n\ |
5794 | 712 @end deftypefn") |
3016 | 713 { |
5800 | 714 int saved_history_size = Vhistory_size; |
715 | |
716 octave_value retval | |
717 = SET_INTERNAL_VARIABLE_WITH_LIMITS (history_size, -1, INT_MAX); | |
718 | |
719 if (Vhistory_size != saved_history_size) | |
720 command_history::set_size (Vhistory_size); | |
721 | |
722 return retval; | |
3016 | 723 } |
724 | |
5794 | 725 DEFUN (history_file, args, nargout, |
726 "-*- texinfo -*-\n\ | |
10840 | 727 @deftypefn {Built-in Function} {@var{val} =} history_file ()\n\ |
5794 | 728 @deftypefnx {Built-in Function} {@var{old_val} =} history_file (@var{new_val})\n\ |
729 Query or set the internal variable that specifies the name of the\n\ | |
730 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
|
731 @file{~/.octave_hist}, but may be overridden by the environment\n\ |
10840 | 732 variable @w{@env{OCTAVE_HISTFILE}}.\n\ |
5794 | 733 @seealso{history_size, saving_history, history_timestamp_format_string}\n\ |
734 @end deftypefn") | |
5305 | 735 { |
5794 | 736 std::string saved_history_file = Vhistory_file; |
5305 | 737 |
5794 | 738 octave_value retval = SET_INTERNAL_VARIABLE (history_file); |
5305 | 739 |
5794 | 740 if (Vhistory_file != saved_history_file) |
5872 | 741 command_history::set_file (Vhistory_file); |
5305 | 742 |
5800 | 743 return retval; |
3016 | 744 } |
745 | |
5794 | 746 DEFUN (history_timestamp_format_string, args, nargout, |
747 "-*- texinfo -*-\n\ | |
10840 | 748 @deftypefn {Built-in Function} {@var{val} =} history_timestamp_format_string ()\n\ |
5794 | 749 @deftypefnx {Built-in Function} {@var{old_val} =} history_timestamp_format_string (@var{new_val})\n\ |
6653 | 750 Query or set the internal variable that specifies the format string\n\ |
5794 | 751 for the comment line that is written to the history file when Octave\n\ |
752 exits. The format string is passed to @code{strftime}. The default\n\ | |
753 value is\n\ | |
5305 | 754 \n\ |
755 @example\n\ | |
756 \"# Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>\"\n\ | |
757 @end example\n\ | |
5794 | 758 @seealso{strftime, history_file, history_size, saving_history}\n\ |
759 @end deftypefn") | |
760 { | |
761 return SET_INTERNAL_VARIABLE (history_timestamp_format_string); | |
762 } | |
5305 | 763 |
5794 | 764 DEFUN (saving_history, args, nargout, |
765 "-*- texinfo -*-\n\ | |
10840 | 766 @deftypefn {Built-in Function} {@var{val} =} saving_history ()\n\ |
5794 | 767 @deftypefnx {Built-in Function} {@var{old_val} =} saving_history (@var{new_val})\n\ |
768 Query or set the internal variable that controls whether commands entered\n\ | |
769 on the command line are saved in the history file.\n\ | |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
770 @seealso{history_control, history_file, history_size, history_timestamp_format_string}\n\ |
5794 | 771 @end deftypefn") |
772 { | |
773 octave_value retval = SET_INTERNAL_VARIABLE (saving_history); | |
774 | |
775 command_history::ignore_entries (! Vsaving_history); | |
776 | |
777 return retval; | |
3016 | 778 } |