Mercurial > octave
annotate libinterp/corefcn/oct-hist.cc @ 21910:4d723ba06b4a
provide wrappers for some unistd.h functions
* liboctave/wrappers/unistd-wrappers.c,
liboctave/wrappers/unistd-wrappers.h: New files.
* liboctave/wrappers/module.mk: Update.
* gl2ps-print.cc, oct-hist.cc, oct-procbuf.cc, oct-tex-lexer.in.ll,
sysdep.cc, octave.cc, parse-tree/lex.ll, file-ops.cc, lo-sysdep.cc,
oct-env.cc, oct-syscalls.cc, cmd-edit.cc, kpse.cc:
Use wrappers instead of calling unistd.h functions directly.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 14 Jun 2016 18:10:04 -0400 |
parents | 176536b15d68 |
children | 112b20240c87 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3 Copyright (C) 1993-2015 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 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
34 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
35 # include "config.h" |
1 | 36 #endif |
37 | |
1343 | 38 #include <cstdlib> |
39 #include <cstring> | |
40 | |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21748
diff
changeset
|
41 #include <fstream> |
1750 | 42 #include <string> |
43 | |
1799 | 44 #include "cmd-hist.h" |
1802 | 45 #include "file-ops.h" |
3016 | 46 #include "lo-mappers.h" |
16431
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
47 #include "octave-link.h" |
2926 | 48 #include "oct-env.h" |
5305 | 49 #include "oct-time.h" |
1755 | 50 #include "str-vec.h" |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21748
diff
changeset
|
51 #include "unistd-wrappers.h" |
1755 | 52 |
2492 | 53 #include <defaults.h> |
1352 | 54 #include "defun.h" |
1 | 55 #include "error.h" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20983
diff
changeset
|
56 #include "errwarn.h" |
1 | 57 #include "input.h" |
1742 | 58 #include "oct-hist.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
59 #include "ovl.h" |
1352 | 60 #include "pager.h" |
3018 | 61 #include "parse.h" |
1352 | 62 #include "sighandlers.h" |
1690 | 63 #include "sysdep.h" |
1750 | 64 #include "toplev.h" |
1352 | 65 #include "unwind-prot.h" |
66 #include "utils.h" | |
2205 | 67 #include "variables.h" |
1 | 68 |
3018 | 69 // TRUE means input is coming from temporary history file. |
70 bool input_from_tmp_history_file = false; | |
168 | 71 |
5305 | 72 static std::string |
1 | 73 default_history_file (void) |
74 { | |
3523 | 75 std::string file; |
1 | 76 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
77 std::string env_file = octave::sys::env::getenv ("OCTAVE_HISTFILE"); |
1755 | 78 |
2926 | 79 if (! env_file.empty ()) |
6141 | 80 file = env_file; |
1 | 81 |
1755 | 82 if (file.empty ()) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
83 file = octave::sys::file_ops::concat (octave::sys::env::get_home_directory (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
84 ".octave_hist"); |
1 | 85 |
86 return file; | |
87 } | |
88 | |
5305 | 89 static int |
90 default_history_size (void) | |
91 { | |
16025
a78c1e445cfc
Change default history size to 1000.
Rik <rik@octave.org>
parents:
16022
diff
changeset
|
92 int size = 1000; |
5305 | 93 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
94 std::string env_size = octave::sys::env::getenv ("OCTAVE_HISTSIZE"); |
5305 | 95 |
96 if (! env_size.empty ()) | |
97 { | |
98 int val; | |
99 | |
100 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
|
101 size = val > 0 ? val : 0; |
5305 | 102 } |
103 | |
104 return size; | |
105 } | |
106 | |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
107 static std::string |
5305 | 108 default_history_timestamp_format (void) |
109 { | |
110 return | |
111 std::string ("# Octave " OCTAVE_VERSION ", %a %b %d %H:%M:%S %Y %Z <") | |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
112 + octave::sys::env::get_user_name () |
5305 | 113 + std::string ("@") |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
114 + octave::sys::env::get_host_name () |
5305 | 115 + std::string (">"); |
116 } | |
117 | |
5794 | 118 // The format of the timestamp marker written to the history file when |
119 // Octave exits. | |
120 static std::string Vhistory_timestamp_format_string | |
121 = default_history_timestamp_format (); | |
122 | |
581 | 123 // Display, save, or load history. Stolen and modified from bash. |
124 // | |
125 // Arg of -w FILENAME means write file, arg of -r FILENAME | |
126 // 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
|
127 // means only display that many items. |
581 | 128 |
15814
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
129 static string_vector |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
130 do_history (const octave_value_list& args, int nargout) |
1 | 131 { |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
132 bool numbered_output = nargout == 0; |
1 | 133 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
134 octave::unwind_protect frame; |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
135 |
15814
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
136 string_vector hlist; |
12990
07dc4839c05f
properly save and restore command history file name in history command (bug #32524)
John W. Eaton <jwe@octave.org>
parents:
12989
diff
changeset
|
137 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
138 frame.add_fcn (octave::command_history::set_file, |
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
139 octave::command_history::file ()); |
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
|
140 |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
141 int nargin = args.length (); |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
142 |
16242
2a81ce01c383
Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents:
16196
diff
changeset
|
143 // Number of history lines to show (-1 = all) |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
144 int limit = -1; |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
145 |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
146 for (octave_idx_type i = 0; i < nargin; i++) |
1 | 147 { |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
148 octave_value arg = args(i); |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
149 |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
150 std::string option; |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
151 |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
152 if (arg.is_string ()) |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
153 option = arg.string_value (); |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
154 else if (arg.is_numeric_type ()) |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
155 { |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
156 limit = arg.int_value (); |
16242
2a81ce01c383
Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents:
16196
diff
changeset
|
157 if (limit < 0) |
2a81ce01c383
Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents:
16196
diff
changeset
|
158 limit = -limit; |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
159 continue; |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
160 } |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
161 else |
21129
228b65504557
maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
162 err_wrong_type_arg ("history", arg); |
2435 | 163 |
164 if (option == "-r" || option == "-w" || option == "-a" | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
165 || option == "-n") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
166 { |
16685
5c5c46a81ad5
Added default name usage for history -r,-w option (Bug #38986)
John Donoghue <john.donoghue@ieee.org>
parents:
16431
diff
changeset
|
167 if (i < nargin - 1) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
168 { |
20582
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
169 std::string fname |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
170 = args(++i).xstring_value ("history: filename must be a string for %s option", |
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
171 option.c_str ()); |
20582
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
172 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
173 octave::command_history::set_file (fname); |
16685
5c5c46a81ad5
Added default name usage for history -r,-w option (Bug #38986)
John Donoghue <john.donoghue@ieee.org>
parents:
16431
diff
changeset
|
174 } |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
175 else |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
176 octave::command_history::set_file (default_history_file ()); |
1 | 177 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
178 if (option == "-a") |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
179 // Append 'new' lines to file. |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
180 octave::command_history::append (); |
2435 | 181 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
182 else if (option == "-w") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
183 // Write entire history. |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
184 octave::command_history::write (); |
777 | 185 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
186 else if (option == "-r") |
16431
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
187 { |
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
188 // Read entire file. |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
189 octave::command_history::read (); |
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
190 octave_link::set_history (octave::command_history::list ()); |
16431
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
191 } |
777 | 192 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
193 else if (option == "-n") |
16431
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
194 { |
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
195 // Read 'new' history from file. |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
196 octave::command_history::read_range (); |
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
197 octave_link::set_history (octave::command_history::list ()); |
16431
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
198 } |
777 | 199 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
200 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
201 panic_impossible (); |
2435 | 202 |
15814
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
203 return hlist; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
204 } |
16431
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
205 else if (option == "-c") |
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
206 { |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
207 octave::command_history::clear (); |
16431
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
208 octave_link::clear_history (); |
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
209 } |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
210 else if (option == "-q") |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
211 numbered_output = false; |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
212 else if (option == "--") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
213 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
214 i++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
215 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
216 } |
1 | 217 else |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
218 { |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
219 // The last argument found in the command list that looks like |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
220 // an integer will be used |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
221 int tmp; |
1 | 222 |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
223 if (sscanf (option.c_str (), "%d", &tmp) == 1) |
16242
2a81ce01c383
Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents:
16196
diff
changeset
|
224 { |
2a81ce01c383
Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents:
16196
diff
changeset
|
225 if (tmp > 0) |
2a81ce01c383
Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents:
16196
diff
changeset
|
226 limit = tmp; |
2a81ce01c383
Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents:
16196
diff
changeset
|
227 else |
2a81ce01c383
Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents:
16196
diff
changeset
|
228 limit = -tmp; |
2a81ce01c383
Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents:
16196
diff
changeset
|
229 } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
230 |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
231 else |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
232 { |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
233 if (option.length () > 0 && option[0] == '-') |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
234 error ("history: unrecognized option '%s'", option.c_str ()); |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
235 else |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
236 error ("history: bad non-numeric arg '%s'", option.c_str ()); |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
237 } |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
238 } |
15817
dbb7896f15c7
Fix argument passing to history() command
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15814
diff
changeset
|
239 } |
1 | 240 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
241 hlist = octave::command_history::list (limit, numbered_output); |
1 | 242 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20172
diff
changeset
|
243 int len = hlist.numel (); |
1799 | 244 |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
245 if (nargout == 0) |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
246 { |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
247 for (octave_idx_type i = 0; i < len; i++) |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
248 octave_stdout << hlist[i] << "\n"; |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
249 } |
15814
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
250 |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
251 return hlist; |
1 | 252 } |
253 | |
581 | 254 // Read the edited history lines from STREAM and return them |
255 // one at a time. This can read unlimited length lines. The | |
2434 | 256 // caller should free the storage. |
581 | 257 |
1 | 258 static char * |
3551 | 259 edit_history_readline (std::fstream& stream) |
1 | 260 { |
261 char c; | |
262 int line_len = 128; | |
263 int lindex = 0; | |
264 char *line = new char [line_len]; | |
265 line[0] = '\0'; | |
266 | |
267 while (stream.get (c)) | |
268 { | |
269 if (lindex + 2 >= line_len) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
270 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
271 char *tmp_line = new char [line_len += 128]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
272 strcpy (tmp_line, line); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
273 delete [] line; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
274 line = tmp_line; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
275 } |
1 | 276 |
277 if (c == '\n') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
278 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
279 line[lindex++] = '\n'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
280 line[lindex++] = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
281 return line; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
282 } |
1 | 283 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
284 line[lindex++] = c; |
1 | 285 } |
286 | |
287 if (! lindex) | |
288 { | |
289 delete [] line; | |
529 | 290 return 0; |
1 | 291 } |
292 | |
293 if (lindex + 2 >= line_len) | |
294 { | |
295 char *tmp_line = new char [lindex+3]; | |
296 strcpy (tmp_line, line); | |
297 delete [] line; | |
298 line = tmp_line; | |
299 } | |
300 | |
1358 | 301 // Finish with newline if none in file. |
1 | 302 |
303 line[lindex++] = '\n'; | |
304 line[lindex++] = '\0'; | |
305 return line; | |
306 } | |
307 | |
308 static void | |
3523 | 309 edit_history_add_hist (const std::string& line) |
1 | 310 { |
1799 | 311 if (! line.empty ()) |
1 | 312 { |
3523 | 313 std::string tmp = line; |
1 | 314 |
1799 | 315 int len = tmp.length (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
316 |
1799 | 317 if (len > 0 && tmp[len-1] == '\n') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
318 tmp.resize (len - 1); |
1799 | 319 |
320 if (! tmp.empty ()) | |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
321 if (octave::command_history::add (tmp)) |
17215
7c06875c2dcc
Backed out changeset 3d1205d5771e
John W. Eaton <jwe@octave.org>
parents:
17214
diff
changeset
|
322 octave_link::append_history (tmp); |
1 | 323 } |
324 } | |
325 | |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
326 static bool |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
327 get_int_arg (const octave_value& arg, int& val) |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
328 { |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
329 bool ok = true; |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
330 |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
331 if (arg.is_string ()) |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
332 { |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
333 std::string tmp = arg.string_value (); |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
334 |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
335 ok = sscanf (tmp.c_str (), "%d", &val) == 1; |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
336 } |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
337 else if (arg.is_numeric_type ()) |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
338 val = arg.int_value (); |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
339 else |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
340 ok = false; |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
341 |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
342 return ok; |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
343 } |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
344 |
3536 | 345 static std::string |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
346 mk_tmp_hist_file (const octave_value_list& args, |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
347 bool insert_curr, const char *warn_for) |
1 | 348 { |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
349 string_vector hlist = octave::command_history::list (); |
1 | 350 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20172
diff
changeset
|
351 int hist_count = hlist.numel () - 1; // switch to zero-based indexing |
1 | 352 |
1358 | 353 // The current command line is already part of the history list by |
16051
3a06aa956d96
Fix off-by-1 error in history list when running 'edit_history'.
Rik <rik@octave.org>
parents:
16025
diff
changeset
|
354 // the time we get to this point. Delete the cmd from the list when |
3a06aa956d96
Fix off-by-1 error in history list when running 'edit_history'.
Rik <rik@octave.org>
parents:
16025
diff
changeset
|
355 // executing 'edit_history' so that it doesn't show up in the history |
3a06aa956d96
Fix off-by-1 error in history list when running 'edit_history'.
Rik <rik@octave.org>
parents:
16025
diff
changeset
|
356 // but the actual commands performed will. |
1 | 357 |
64 | 358 if (! insert_curr) |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
359 octave::command_history::remove (hist_count); |
1799 | 360 |
16022
d8f216d241cf
Fix off-by-1 error in run_history when called with no arguments.
Rik <rik@octave.org>
parents:
16016
diff
changeset
|
361 hist_count--; // skip last entry in history list |
1 | 362 |
1358 | 363 // If no numbers have been specified, the default is to edit the |
364 // last command in the history list. | |
1 | 365 |
16022
d8f216d241cf
Fix off-by-1 error in run_history when called with no arguments.
Rik <rik@octave.org>
parents:
16016
diff
changeset
|
366 int hist_beg = hist_count; |
1 | 367 int hist_end = hist_count; |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
368 |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
369 bool reverse = false; |
1 | 370 |
1358 | 371 // Process options. |
1 | 372 |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
373 int nargin = args.length (); |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
374 |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
375 if (nargin == 2) |
1 | 376 { |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
377 if (! get_int_arg (args(0), hist_beg) |
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
378 || ! get_int_arg (args(1), hist_end)) |
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
379 error ("%s: arguments must be integers", warn_for); |
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
380 |
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
381 if (hist_beg < 0) |
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
382 hist_beg += (hist_count + 1); |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
383 else |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
384 hist_beg--; |
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
385 if (hist_end < 0) |
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
386 hist_end += (hist_count + 1); |
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
387 else |
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
388 hist_end--; |
1 | 389 } |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
390 else if (nargin == 1) |
1 | 391 { |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
392 if (! get_int_arg (args(0), hist_beg)) |
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
393 error ("%s: argument must be an integer", warn_for); |
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
394 |
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
395 if (hist_beg < 0) |
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
396 hist_beg += (hist_count + 1); |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
397 else |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
398 hist_beg--; |
1 | 399 |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
400 hist_end = hist_beg; |
1 | 401 } |
402 | |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
403 if (hist_beg > hist_count || hist_end > hist_count) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
404 error ("%s: history specification out of range", warn_for); |
1 | 405 |
406 if (hist_end < hist_beg) | |
407 { | |
16022
d8f216d241cf
Fix off-by-1 error in run_history when called with no arguments.
Rik <rik@octave.org>
parents:
16016
diff
changeset
|
408 std::swap (hist_end, hist_beg); |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
409 reverse = true; |
1 | 410 } |
411 | |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
412 std::string name = octave::sys::tempnam ("", "oct-"); |
1 | 413 |
3551 | 414 std::fstream file (name.c_str (), std::ios::out); |
64 | 415 |
1 | 416 if (! file) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
417 error ("%s: couldn't open temporary file '%s'", warn_for, |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
418 name.c_str ()); |
1 | 419 |
420 if (reverse) | |
421 { | |
422 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
|
423 file << hlist[i] << "\n"; |
1 | 424 } |
425 else | |
426 { | |
427 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
|
428 file << hlist[i] << "\n"; |
1 | 429 } |
430 | |
431 file.close (); | |
432 | |
1755 | 433 return name; |
64 | 434 } |
435 | |
10411 | 436 static void |
437 unlink_cleanup (const char *file) | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
438 { |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21748
diff
changeset
|
439 octave_unlink_wrapper (file); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
440 } |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
441 |
1755 | 442 static void |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
443 do_edit_history (const octave_value_list& args) |
64 | 444 { |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
445 std::string name = mk_tmp_hist_file (args, false, "edit_history"); |
64 | 446 |
1755 | 447 if (name.empty ()) |
64 | 448 return; |
449 | |
1358 | 450 // Call up our favorite editor on the file of commands. |
1 | 451 |
5794 | 452 std::string cmd = VEDITOR; |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
453 cmd.append (" \"" + name + "\""); |
1 | 454 |
1358 | 455 // Ignore interrupts while we are off editing commands. Should we |
456 // maybe avoid using system()? | |
1 | 457 |
2705 | 458 volatile octave_interrupt_handler old_interrupt_handler |
2554 | 459 = octave_ignore_interrupts (); |
1443 | 460 |
15990
696e82182eba
Check if history edition was successful, abort operation on failure.
Júlio Hoffimann <julio.hoffimann@gmail.com>
parents:
15823
diff
changeset
|
461 int status = system (cmd.c_str ()); |
1443 | 462 |
2554 | 463 octave_set_interrupt_handler (old_interrupt_handler); |
1 | 464 |
15990
696e82182eba
Check if history edition was successful, abort operation on failure.
Júlio Hoffimann <julio.hoffimann@gmail.com>
parents:
15823
diff
changeset
|
465 // Check if text edition was successfull. Abort the operation |
696e82182eba
Check if history edition was successful, abort operation on failure.
Júlio Hoffimann <julio.hoffimann@gmail.com>
parents:
15823
diff
changeset
|
466 // in case of failure. |
696e82182eba
Check if history edition was successful, abort operation on failure.
Júlio Hoffimann <julio.hoffimann@gmail.com>
parents:
15823
diff
changeset
|
467 if (status != EXIT_SUCCESS) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
468 error ("edit_history: text editor command failed"); |
15990
696e82182eba
Check if history edition was successful, abort operation on failure.
Júlio Hoffimann <julio.hoffimann@gmail.com>
parents:
15823
diff
changeset
|
469 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
470 // Write the commands to the history file since source_file |
1358 | 471 // disables command line history while it executes. |
1 | 472 |
3551 | 473 std::fstream file (name.c_str (), std::ios::in); |
1 | 474 |
475 char *line; | |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
476 //int first = 1; |
529 | 477 while ((line = edit_history_readline (file)) != 0) |
1 | 478 { |
1358 | 479 // Skip blank lines. |
1 | 480 |
481 if (line[0] == '\n') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
482 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
483 delete [] line; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
484 continue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
485 } |
1 | 486 |
16051
3a06aa956d96
Fix off-by-1 error in history list when running 'edit_history'.
Rik <rik@octave.org>
parents:
16025
diff
changeset
|
487 edit_history_add_hist (line); |
16016 | 488 |
489 delete [] line; | |
1 | 490 } |
491 | |
492 file.close (); | |
493 | |
1358 | 494 // Turn on command echo, so the output from this will make better |
495 // sense. | |
1 | 496 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
497 octave::unwind_protect frame; |
3018 | 498 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
499 frame.add_fcn (unlink_cleanup, name.c_str ()); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
500 frame.protect_var (Vecho_executing_commands); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
501 frame.protect_var (input_from_tmp_history_file); |
3018 | 502 |
2205 | 503 Vecho_executing_commands = ECHO_CMD_LINE; |
3018 | 504 input_from_tmp_history_file = true; |
1 | 505 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
506 source_file (name); |
1 | 507 } |
508 | |
1755 | 509 static void |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
510 do_run_history (const octave_value_list& args) |
64 | 511 { |
16243
428da5debfe4
maint: Remove commented out lines from history fix in changeset 2a81ce01c383.
Rik <rik@octave.org>
parents:
16242
diff
changeset
|
512 std::string name = mk_tmp_hist_file (args, false, "run_history"); |
64 | 513 |
1755 | 514 if (name.empty ()) |
64 | 515 return; |
516 | |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
517 // Turn on command echo so the output from this will make better sense. |
64 | 518 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
519 octave::unwind_protect frame; |
3018 | 520 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
521 frame.add_fcn (unlink_cleanup, name.c_str ()); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
522 frame.protect_var (Vecho_executing_commands); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
523 frame.protect_var (input_from_tmp_history_file); |
3018 | 524 |
2205 | 525 Vecho_executing_commands = ECHO_CMD_LINE; |
3018 | 526 input_from_tmp_history_file = true; |
64 | 527 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
528 source_file (name); |
64 | 529 } |
530 | |
5305 | 531 void |
8273
2c1ba965b486
skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
532 initialize_history (bool read_history_file) |
5794 | 533 { |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
534 octave::command_history::initialize (read_history_file, |
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
535 default_history_file (), |
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
536 default_history_size (), |
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
537 octave::sys::env::getenv ("OCTAVE_HISTCONTROL")); |
16431
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
538 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
539 octave_link::set_history (octave::command_history::list ()); |
5794 | 540 } |
541 | |
542 void | |
5305 | 543 octave_history_write_timestamp (void) |
544 { | |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
545 octave::sys::localtime now; |
5305 | 546 |
547 std::string timestamp = now.strftime (Vhistory_timestamp_format_string); | |
548 | |
549 if (! timestamp.empty ()) | |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
550 if (octave::command_history::add (timestamp)) |
17215
7c06875c2dcc
Backed out changeset 3d1205d5771e
John W. Eaton <jwe@octave.org>
parents:
17214
diff
changeset
|
551 octave_link::append_history (timestamp); |
5305 | 552 } |
553 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8286
diff
changeset
|
554 DEFUN (edit_history, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
555 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
556 @deftypefn {} {} edit_history\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
557 @deftypefnx {} {} edit_history @var{cmd_number}\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
558 @deftypefnx {} {} edit_history @var{first} @var{last}\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
559 Edit the history list using the editor named by the variable @env{EDITOR}.\n\ |
3332 | 560 \n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
561 The commands to be edited are first copied to a temporary file. When you\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
562 exit the editor, Octave executes the commands that remain in the file. It\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
563 is often more convenient to use @code{edit_history} to define functions\n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
564 rather than attempting to enter them directly on the command line.\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
565 The block of commands is executed as soon as you exit the editor.\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
566 To avoid executing any commands, simply delete all the lines from the buffer\n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
567 before leaving the editor.\n\ |
3332 | 568 \n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
569 When invoked with no arguments, edit the previously executed command;\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
570 With one argument, edit the specified command @var{cmd_number};\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
571 With two arguments, edit the list of commands between @var{first} and\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
572 @var{last}. Command number specifiers may also be negative where -1\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
573 refers to the most recently executed command.\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
574 The following are equivalent and edit the most recently executed command.\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
575 \n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
576 @example\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
577 @group\n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
578 edit_history\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
579 edit_history -1\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
580 @end group\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
581 @end example\n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
582 \n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
583 When using ranges, specifying a larger number for the first command than the\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
584 last command reverses the list of commands before they are placed in the\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
585 buffer to be edited.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
586 @seealso{run_history, history}\n\ |
11547 | 587 @end deftypefn") |
529 | 588 { |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
589 if (args.length () > 2) |
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
590 print_usage (); |
529 | 591 |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
592 do_edit_history (args); |
529 | 593 |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
594 return ovl (); |
529 | 595 } |
596 | |
15814
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
597 DEFUN (history, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
598 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
599 @deftypefn {} {} history\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
600 @deftypefnx {} {} history @var{opt1} @dots{}\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
601 @deftypefnx {} {@var{h} =} history ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
602 @deftypefnx {} {@var{h} =} history (@var{opt1}, @dots{})\n\ |
3332 | 603 If invoked with no arguments, @code{history} displays a list of commands\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
604 that you have executed.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
605 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
606 Valid options are:\n\ |
3332 | 607 \n\ |
608 @table @code\n\ | |
16052 | 609 @item @var{n}\n\ |
610 @itemx -@var{n}\n\ | |
611 Display only the most recent @var{n} lines of history.\n\ | |
612 \n\ | |
16431
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
613 @item -c\n\ |
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
614 Clear the history list.\n\ |
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
615 \n\ |
16052 | 616 @item -q\n\ |
617 Don't number the displayed lines of history. This is useful for cutting\n\ | |
618 and pasting commands using the X Window System.\n\ | |
529 | 619 \n\ |
3332 | 620 @item -r @var{file}\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
621 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
|
622 history list. If the name is omitted, use the default history file\n\ |
3332 | 623 (normally @file{~/.octave_hist}).\n\ |
624 \n\ | |
16052 | 625 @item -w @var{file}\n\ |
626 Write the current history to the file @var{file}. If the name is\n\ | |
627 omitted, use the default history file (normally @file{~/.octave_hist}).\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\ | |
15814
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
633 \n\ |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
634 If invoked with a single output argument, the history will be saved to that\n\ |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
635 argument as a cell string and will not be output to screen.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
636 @seealso{edit_history, run_history}\n\ |
11547 | 637 @end deftypefn") |
529 | 638 { |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
639 // Call do_history even if nargout is zero to display history list. |
529 | 640 |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
641 string_vector hlist = do_history (args, nargout); |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
642 |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
643 return nargout > 0 ? ovl (Cell (hlist)) : ovl (); |
529 | 644 } |
645 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8286
diff
changeset
|
646 DEFUN (run_history, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
647 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
648 @deftypefn {} {} run_history\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
649 @deftypefnx {} {} run_history @var{cmd_number}\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
650 @deftypefnx {} {} run_history @var{first} @var{last}\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
651 Run commands from the history list.\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
652 \n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
653 When invoked with no arguments, run the previously executed command;\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
654 \n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
655 With one argument, run the specified command @var{cmd_number};\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
656 \n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
657 With two arguments, run the list of commands between @var{first} and\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
658 @var{last}. Command number specifiers may also be negative where -1\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
659 refers to the most recently executed command. For example, the command\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
660 \n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
661 @example\n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
662 @group\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
663 run_history\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
664 OR\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
665 run_history -1\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
666 @end group\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
667 @end example\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
668 \n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
669 @noindent\n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
670 executes the most recent command again.\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
671 The command\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
672 \n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
673 @example\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
674 run_history 13 169\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
675 @end example\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
676 \n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
677 @noindent\n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
678 executes commands 13 through 169.\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
679 \n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
680 Specifying a larger number for the first command than the last command\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
681 reverses the list of commands before executing them.\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
682 For example:\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
683 \n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
684 @example\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
685 @group\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
686 disp (1)\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
687 disp (2)\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
688 run_history -1 -2\n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
689 @result{}\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
690 2\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
691 1\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
692 @end group\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
693 @end example\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
694 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
695 @seealso{edit_history, history}\n\ |
11547 | 696 @end deftypefn") |
529 | 697 { |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
698 if (args.length () > 2) |
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
699 print_usage (); |
529 | 700 |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
701 do_run_history (args); |
529 | 702 |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
703 return ovl (); |
529 | 704 } |
705 | |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
706 DEFUN (history_control, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
707 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
708 @deftypefn {} {@var{val} =} history_control ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
709 @deftypefnx {} {@var{old_val} =} history_control (@var{new_val})\n\ |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
710 Query or set the internal variable that specifies how commands are saved\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
711 to the history list.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
712 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
713 The default value is an empty character string, but may be overridden by the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
714 environment variable @w{@env{OCTAVE_HISTCONTROL}}.\n\ |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
715 \n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
716 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
|
717 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
|
718 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
|
719 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
|
720 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
|
721 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
|
722 @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
|
723 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
|
724 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
|
725 @code{history_control} is the empty string, all commands are saved on\n\ |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
726 the history list, subject to the value of @code{history_save}.\n\ |
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
727 @seealso{history_file, history_size, history_timestamp_format_string, history_save}\n\ |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
728 @end deftypefn") |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
729 { |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
730 octave_value retval; |
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
731 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
732 std::string old_history_control = octave::command_history::histcontrol (); |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
733 |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
734 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
|
735 |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
736 retval = set_internal_variable (tmp, args, nargout, "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
|
737 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
738 if (tmp != old_history_control) |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
739 octave::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
|
740 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
741 return retval; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
742 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
743 |
5794 | 744 DEFUN (history_size, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
745 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
746 @deftypefn {} {@var{val} =} history_size ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
747 @deftypefnx {} {@var{old_val} =} history_size (@var{new_val})\n\ |
5794 | 748 Query or set the internal variable that specifies how many entries\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
749 to store in the history file.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
750 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
751 The default value is @code{1000}, but may be overridden by the environment\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
752 variable @w{@env{OCTAVE_HISTSIZE}}.\n\ |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
753 @seealso{history_file, history_timestamp_format_string, history_save}\n\ |
5794 | 754 @end deftypefn") |
3016 | 755 { |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
756 octave_value retval; |
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
757 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
758 int old_history_size = octave::command_history::size (); |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
759 |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
760 int tmp = old_history_size; |
5800 | 761 |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
762 retval = set_internal_variable (tmp, args, nargout, |
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
763 "history_size", -1, |
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
764 std::numeric_limits<int>::max ()); |
5800 | 765 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
766 if (tmp != old_history_size) |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
767 octave::command_history::set_size (tmp); |
5800 | 768 |
769 return retval; | |
3016 | 770 } |
771 | |
5794 | 772 DEFUN (history_file, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
773 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
774 @deftypefn {} {@var{val} =} history_file ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
775 @deftypefnx {} {@var{old_val} =} history_file (@var{new_val})\n\ |
5794 | 776 Query or set the internal variable that specifies the name of the\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
777 file used to store command history.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
778 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
779 The default value is @file{~/.octave_hist}, but may be overridden by the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
780 environment variable @w{@env{OCTAVE_HISTFILE}}.\n\ |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
781 @seealso{history_size, history_save, history_timestamp_format_string}\n\ |
5794 | 782 @end deftypefn") |
5305 | 783 { |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
784 octave_value retval; |
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
785 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
786 std::string old_history_file = octave::command_history::file (); |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
787 |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
788 std::string tmp = old_history_file; |
5305 | 789 |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
790 retval = set_internal_variable (tmp, args, nargout, "history_file"); |
5305 | 791 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
792 if (tmp != old_history_file) |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
793 octave::command_history::set_file (tmp); |
5305 | 794 |
5800 | 795 return retval; |
3016 | 796 } |
797 | |
5794 | 798 DEFUN (history_timestamp_format_string, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
799 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
800 @deftypefn {} {@var{val} =} history_timestamp_format_string ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
801 @deftypefnx {} {@var{old_val} =} history_timestamp_format_string (@var{new_val})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
802 @deftypefnx {} {} history_timestamp_format_string (@var{new_val}, \"local\")\n\ |
6653 | 803 Query or set the internal variable that specifies the format string\n\ |
5794 | 804 for the comment line that is written to the history file when Octave\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
805 exits.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
806 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
807 The format string is passed to @code{strftime}. The default value is\n\ |
5305 | 808 \n\ |
809 @example\n\ | |
810 \"# Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>\"\n\ | |
811 @end example\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12990
diff
changeset
|
812 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17219
diff
changeset
|
813 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
814 variable is changed locally for the function and any subroutines it calls.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17219
diff
changeset
|
815 The original variable value is restored when exiting the function.\n\ |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
816 @seealso{strftime, history_file, history_size, history_save}\n\ |
5794 | 817 @end deftypefn") |
818 { | |
819 return SET_INTERNAL_VARIABLE (history_timestamp_format_string); | |
820 } | |
5305 | 821 |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
822 DEFUN (history_save, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
823 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
824 @deftypefn {} {@var{val} =} history_save ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
825 @deftypefnx {} {@var{old_val} =} history_save (@var{new_val})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
826 @deftypefnx {} {} history_save (@var{new_val}, \"local\")\n\ |
5794 | 827 Query or set the internal variable that controls whether commands entered\n\ |
828 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
|
829 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17219
diff
changeset
|
830 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
831 variable is changed locally for the function and any subroutines it calls.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17219
diff
changeset
|
832 The original 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
|
833 @seealso{history_control, history_file, history_size, history_timestamp_format_string}\n\ |
5794 | 834 @end deftypefn") |
835 { | |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
836 octave_value retval; |
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
837 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
838 bool old_history_save = ! octave::command_history::ignoring_entries (); |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
839 |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
840 bool tmp = old_history_save; |
5794 | 841 |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
842 retval = set_internal_variable (tmp, args, nargout, "history_save"); |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
843 |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
844 if (tmp != old_history_save) |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
845 octave::command_history::ignore_entries (! tmp); |
5794 | 846 |
847 return retval; | |
3016 | 848 } |