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