annotate libinterp/corefcn/oct-hist.cc @ 25440:893344cee100

rename defaults source files to installation-data * installation-data.h, installation-data.cc: New files, adapted from defaults.h and defaults.cc. Include installation-data.h instead of defaults.h, but only in files that require it. * defaults.h: Preserve for backward compatibility. Define deprecated functions as inline. * libinterp/corefcn/module.mk: Update.
author John W. Eaton <jwe@octave.org>
date Fri, 08 Jun 2018 15:43:36 -0400
parents 6652d3823428
children f881d3e271d2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2
25054
6652d3823428 maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3 Copyright (C) 1993-2018 John W. Eaton
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
4
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23829
diff changeset
7 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
8 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23829
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
10 (at your option) any later version.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
15 GNU General Public License for more details.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6653
diff changeset
18 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23829
diff changeset
19 <https://www.gnu.org/licenses/>.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
20
2939
f2feebf0eb7d [project @ 1997-05-06 16:36:34 by jwe]
jwe
parents: 2936
diff changeset
21 */
f2feebf0eb7d [project @ 1997-05-06 16:36:34 by jwe]
jwe
parents: 2936
diff changeset
22
f2feebf0eb7d [project @ 1997-05-06 16:36:34 by jwe]
jwe
parents: 2936
diff changeset
23 /*
f2feebf0eb7d [project @ 1997-05-06 16:36:34 by jwe]
jwe
parents: 2936
diff changeset
24
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
25 The functions listed below were adapted from similar functions from
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
26 GNU Bash, the Bourne Again SHell, copyright (C) 1987, 1989, 1991 Free
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
27 Software Foundation, Inc.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
28
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
29 do_history edit_history_readline
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
30 do_edit_history edit_history_add_hist
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
31
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
32 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
36 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
37
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
38 #include <cstdlib>
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
39 #include <cstring>
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
40
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21748
diff changeset
41 #include <fstream>
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
42 #include <string>
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
43
1799
1881b2a7d1e2 [project @ 1996-01-29 05:10:48 by jwe]
jwe
parents: 1766
diff changeset
44 #include "cmd-hist.h"
1802
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1799
diff changeset
45 #include "file-ops.h"
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
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
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2897
diff changeset
48 #include "oct-env.h"
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
49 #include "oct-time.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
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
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
52
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
53 #include "defun.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
54 #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
55 #include "errwarn.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
56 #include "input.h"
1742
a02f140ed897 [project @ 1996-01-12 11:09:39 by jwe]
jwe
parents: 1690
diff changeset
57 #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
58 #include "ovl.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
59 #include "pager.h"
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
60 #include "parse.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
61 #include "sighandlers.h"
1690
a38bd8df9d33 [project @ 1996-01-05 21:36:24 by jwe]
jwe
parents: 1670
diff changeset
62 #include "sysdep.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 22051
diff changeset
63 #include "interpreter.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
64 #include "unwind-prot.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
65 #include "utils.h"
2205
bd389b53befa [project @ 1996-05-15 06:15:45 by jwe]
jwe
parents: 2095
diff changeset
66 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
67
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
68 // TRUE means input is coming from temporary history file.
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
69 bool input_from_tmp_history_file = false;
168
a500c60e8f23 [project @ 1993-10-19 05:24:44 by jwe]
jwe
parents: 64
diff changeset
70
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
71 static std::string
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
72 default_history_file (void)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
73 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
74 std::string file;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
75
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21730
diff changeset
76 std::string env_file = octave::sys::env::getenv ("OCTAVE_HISTFILE");
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
77
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2897
diff changeset
78 if (! env_file.empty ())
6141
f6c2d9276572 [project @ 2006-11-06 17:52:51 by jwe]
jwe
parents: 5872
diff changeset
79 file = env_file;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
80
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
81 if (file.empty ())
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
82 file = octave::sys::file_ops::concat (octave::sys::env::get_home_directory (),
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
83 ".octave_hist");
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
84
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
85 return file;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
86 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
87
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
88 static int
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
89 default_history_size (void)
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
90 {
16025
a78c1e445cfc Change default history size to 1000.
Rik <rik@octave.org>
parents: 16022
diff changeset
91 int size = 1000;
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
92
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21730
diff changeset
93 std::string env_size = octave::sys::env::getenv ("OCTAVE_HISTSIZE");
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
94
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
95 if (! env_size.empty ())
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
96 {
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
97 int val;
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
98
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
99 if (sscanf (env_size.c_str (), "%d", &val) == 1)
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23220
diff changeset
100 size = (val > 0 ? val : 0);
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
101 }
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
102
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
103 return size;
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
104 }
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
105
11486
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
106 static std::string
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
107 default_history_timestamp_format (void)
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
108 {
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
109 return
23829
01899bdd2a3a Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents: 23807
diff changeset
110 "# 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
111 + octave::sys::env::get_user_name ()
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
112 + '@'
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21730
diff changeset
113 + octave::sys::env::get_host_name ()
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
114 + '>';
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
115 }
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
116
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
117 // The format of the timestamp marker written to the history file when
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
118 // Octave exits.
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
119 static std::string Vhistory_timestamp_format_string
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
120 = default_history_timestamp_format ();
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
121
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
122 // Display, save, or load history. Stolen and modified from bash.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
123 //
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
124 // Arg of -w FILENAME means write file, arg of -r FILENAME
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
125 // 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
126 // means only display that many items.
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
127
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
128 static string_vector
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
129 do_history (const octave_value_list& args, int nargout)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
130 {
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
131 bool numbered_output = nargout == 0;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
132
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
133 octave::unwind_protect frame;
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
134
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
135 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
136
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
137 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
138 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
139
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
140 int nargin = args.length ();
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
141
16242
2a81ce01c383 Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents: 16196
diff changeset
142 // 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
143 int limit = -1;
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
144
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
145 for (octave_idx_type i = 0; i < nargin; i++)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
146 {
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
147 octave_value arg = args(i);
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
148
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
149 std::string option;
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
150
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
151 if (arg.is_string ())
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
152 option = arg.string_value ();
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23466
diff changeset
153 else if (arg.isnumeric ())
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
154 {
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
155 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
156 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
157 limit = -limit;
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
158 continue;
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
159 }
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
160 else
21129
228b65504557 maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
161 err_wrong_type_arg ("history", arg);
2435
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2434
diff changeset
162
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2434
diff changeset
163 if (option == "-r" || option == "-w" || option == "-a"
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
164 || option == "-n")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
165 {
16685
5c5c46a81ad5 Added default name usage for history -r,-w option (Bug #38986)
John Donoghue <john.donoghue@ieee.org>
parents: 16431
diff changeset
166 if (i < nargin - 1)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
167 {
20582
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
168 std::string fname
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20700
diff changeset
169 = 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
170 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
171
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
172 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
173 }
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
174 else
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
175 octave::command_history::set_file (default_history_file ());
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
176
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
177 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
178 // 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
179 octave::command_history::append ();
2435
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2434
diff changeset
180
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
181 else if (option == "-w")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
182 // Write entire history.
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
183 octave::command_history::write ();
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 641
diff changeset
184
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
185 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
186 {
5982d469f79b use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents: 16243
diff changeset
187 // Read entire file.
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
188 octave::command_history::read ();
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
189 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
190 }
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 641
diff changeset
191
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
192 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
193 {
5982d469f79b use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents: 16243
diff changeset
194 // 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
195 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
196 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
197 }
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 641
diff changeset
198
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
199 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
200 panic_impossible ();
2435
3be97fe02051 [project @ 1996-10-27 21:31:29 by jwe]
jwe
parents: 2434
diff changeset
201
15814
1eee8d8c59fd Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15467
diff changeset
202 return hlist;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
203 }
16431
5982d469f79b use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents: 16243
diff changeset
204 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
205 {
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
206 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
207 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
208 }
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
209 else if (option == "-q")
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
210 numbered_output = false;
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
211 else if (option == "--")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
212 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
213 i++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
214 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
215 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
216 else
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
217 {
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
218 // 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
219 // an integer will be used
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
220 int tmp;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
221
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
222 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
223 {
2a81ce01c383 Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents: 16196
diff changeset
224 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
225 limit = tmp;
2a81ce01c383 Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents: 16196
diff changeset
226 else
2a81ce01c383 Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents: 16196
diff changeset
227 limit = -tmp;
2a81ce01c383 Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents: 16196
diff changeset
228 }
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
229
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
230 else
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
231 {
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
232 if (option.length () > 0 && option[0] == '-')
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
233 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
234 else
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
235 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
236 }
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
237 }
15817
dbb7896f15c7 Fix argument passing to history() command
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15814
diff changeset
238 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
239
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
240 hlist = octave::command_history::list (limit, numbered_output);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
241
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20172
diff changeset
242 int len = hlist.numel ();
1799
1881b2a7d1e2 [project @ 1996-01-29 05:10:48 by jwe]
jwe
parents: 1766
diff changeset
243
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
244 if (nargout == 0)
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
245 {
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
246 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
247 octave_stdout << hlist[i] << "\n";
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
248 }
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
249
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 return hlist;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
251 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
252
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
253 // Read the edited history lines from STREAM and return them
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
254 // one at a time. This can read unlimited length lines. The
2434
ced642d8ba6a [project @ 1996-10-27 04:42:08 by jwe]
jwe
parents: 2205
diff changeset
255 // caller should free the storage.
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
256
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
257 static char *
3551
4833e231e05b [project @ 2000-02-03 02:30:44 by jwe]
jwe
parents: 3544
diff changeset
258 edit_history_readline (std::fstream& stream)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
259 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
260 char c;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
261 int line_len = 128;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
262 int lindex = 0;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
263 char *line = new char [line_len];
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
264 line[0] = '\0';
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
265
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
266 while (stream.get (c))
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
267 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
268 if (lindex + 2 >= line_len)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
269 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
270 char *tmp_line = new char [line_len += 128];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
271 strcpy (tmp_line, line);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
272 delete [] line;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
273 line = tmp_line;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
274 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
275
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
276 if (c == '\n')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
277 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
278 line[lindex++] = '\n';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
279 line[lindex++] = '\0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
280 return line;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
281 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
282 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
283 line[lindex++] = c;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
284 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
285
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
286 if (! lindex)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
287 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
288 delete [] line;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23723
diff changeset
289 return nullptr;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
290 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
291
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
292 if (lindex + 2 >= line_len)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
293 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
294 char *tmp_line = new char [lindex+3];
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
295 strcpy (tmp_line, line);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
296 delete [] line;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
297 line = tmp_line;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
298 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
299
1358
dc9c01f66a19 [project @ 1995-09-05 21:10:01 by jwe]
jwe
parents: 1352
diff changeset
300 // Finish with newline if none in file.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
301
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
302 line[lindex++] = '\n';
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
303 line[lindex++] = '\0';
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
304 return line;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
305 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
306
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
307 static void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
308 edit_history_add_hist (const std::string& line)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
309 {
1799
1881b2a7d1e2 [project @ 1996-01-29 05:10:48 by jwe]
jwe
parents: 1766
diff changeset
310 if (! line.empty ())
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
311 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
312 std::string tmp = line;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
313
1799
1881b2a7d1e2 [project @ 1996-01-29 05:10:48 by jwe]
jwe
parents: 1766
diff changeset
314 int len = tmp.length ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
315
1799
1881b2a7d1e2 [project @ 1996-01-29 05:10:48 by jwe]
jwe
parents: 1766
diff changeset
316 if (len > 0 && tmp[len-1] == '\n')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
317 tmp.resize (len - 1);
1799
1881b2a7d1e2 [project @ 1996-01-29 05:10:48 by jwe]
jwe
parents: 1766
diff changeset
318
1881b2a7d1e2 [project @ 1996-01-29 05:10:48 by jwe]
jwe
parents: 1766
diff changeset
319 if (! tmp.empty ())
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
320 if (octave::command_history::add (tmp))
17215
7c06875c2dcc Backed out changeset 3d1205d5771e
John W. Eaton <jwe@octave.org>
parents: 17214
diff changeset
321 octave_link::append_history (tmp);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
322 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
323 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
324
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
325 static bool
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
326 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
327 {
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
328 bool ok = true;
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
329
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
330 if (arg.is_string ())
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
331 {
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
332 std::string tmp = arg.string_value ();
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
333
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
334 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
335 }
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23466
diff changeset
336 else if (arg.isnumeric ())
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
337 val = arg.int_value ();
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
338 else
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
339 ok = false;
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
340
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
341 return ok;
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
342 }
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
343
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
344 static std::string
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
345 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
346 bool insert_curr, const char *warn_for)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
347 {
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
348 string_vector hlist = octave::command_history::list ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
349
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20172
diff changeset
350 int hist_count = hlist.numel () - 1; // switch to zero-based indexing
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
351
1358
dc9c01f66a19 [project @ 1995-09-05 21:10:01 by jwe]
jwe
parents: 1352
diff changeset
352 // 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
353 // 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
354 // 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
355 // but the actual commands performed will.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
356
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
357 if (! insert_curr)
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
358 octave::command_history::remove (hist_count);
1799
1881b2a7d1e2 [project @ 1996-01-29 05:10:48 by jwe]
jwe
parents: 1766
diff changeset
359
16022
d8f216d241cf Fix off-by-1 error in run_history when called with no arguments.
Rik <rik@octave.org>
parents: 16016
diff changeset
360 hist_count--; // skip last entry in history list
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
361
1358
dc9c01f66a19 [project @ 1995-09-05 21:10:01 by jwe]
jwe
parents: 1352
diff changeset
362 // If no numbers have been specified, the default is to edit the
dc9c01f66a19 [project @ 1995-09-05 21:10:01 by jwe]
jwe
parents: 1352
diff changeset
363 // last command in the history list.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
364
16022
d8f216d241cf Fix off-by-1 error in run_history when called with no arguments.
Rik <rik@octave.org>
parents: 16016
diff changeset
365 int hist_beg = hist_count;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
366 int hist_end = hist_count;
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
367
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
368 bool reverse = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
369
1358
dc9c01f66a19 [project @ 1995-09-05 21:10:01 by jwe]
jwe
parents: 1352
diff changeset
370 // Process options.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
371
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
372 int nargin = args.length ();
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
373
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
374 if (nargin == 2)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
375 {
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
376 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
377 || ! get_int_arg (args(1), hist_end))
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
378 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
379
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
380 if (hist_beg < 0)
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
381 hist_beg += (hist_count + 1);
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
382 else
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
383 hist_beg--;
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
384 if (hist_end < 0)
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
385 hist_end += (hist_count + 1);
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
386 else
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
387 hist_end--;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
388 }
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
389 else if (nargin == 1)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
390 {
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
391 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
392 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
393
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
394 if (hist_beg < 0)
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
395 hist_beg += (hist_count + 1);
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
396 else
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
397 hist_beg--;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
398
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
399 hist_end = hist_beg;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
400 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
401
16188
8366bc871d45 Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents: 16052
diff changeset
402 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
403 error ("%s: history specification out of range", warn_for);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
404
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
405 if (hist_end < hist_beg)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
406 {
16022
d8f216d241cf Fix off-by-1 error in run_history when called with no arguments.
Rik <rik@octave.org>
parents: 16016
diff changeset
407 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
408 reverse = true;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
409 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
410
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
411 std::string name = octave::sys::tempnam ("", "oct-");
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
412
3551
4833e231e05b [project @ 2000-02-03 02:30:44 by jwe]
jwe
parents: 3544
diff changeset
413 std::fstream file (name.c_str (), std::ios::out);
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
414
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
415 if (! file)
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
416 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
417 name.c_str ());
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
418
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
419 if (reverse)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
420 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
421 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
422 file << hlist[i] << "\n";
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
423 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
424 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
425 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
426 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
427 file << hlist[i] << "\n";
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
428 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
429
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
430 file.close ();
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
431
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
432 return name;
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
433 }
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
434
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
435 static void
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
436 unlink_cleanup (const char *file)
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
437 {
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21748
diff changeset
438 octave_unlink_wrapper (file);
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
439 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
440
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
441 static void
23719
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
442 do_edit_history (octave::interpreter& interp, const octave_value_list& args)
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
443 {
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
444 std::string name = mk_tmp_hist_file (args, false, "edit_history");
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
445
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
446 if (name.empty ())
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
447 return;
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
448
1358
dc9c01f66a19 [project @ 1995-09-05 21:10:01 by jwe]
jwe
parents: 1352
diff changeset
449 // Call up our favorite editor on the file of commands.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
450
23719
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
451 octave::environment& env = interp.get_environment ();
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
452 std::string cmd = env.editor ();
23803
90689bdbe048 Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents: 23795
diff changeset
453 cmd.append (R"( ")" + name + '"');
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
454
1358
dc9c01f66a19 [project @ 1995-09-05 21:10:01 by jwe]
jwe
parents: 1352
diff changeset
455 // Ignore interrupts while we are off editing commands. Should we
dc9c01f66a19 [project @ 1995-09-05 21:10:01 by jwe]
jwe
parents: 1352
diff changeset
456 // maybe avoid using system()?
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
457
22051
6db928d06b07 move signal functions into octave namespace
John W. Eaton <jwe@octave.org>
parents: 21966
diff changeset
458 volatile octave::interrupt_handler old_interrupt_handler
6db928d06b07 move signal functions into octave namespace
John W. Eaton <jwe@octave.org>
parents: 21966
diff changeset
459 = octave::ignore_interrupts ();
1443
cd6c9be7337c [project @ 1995-09-19 21:54:56 by jwe]
jwe
parents: 1363
diff changeset
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
cd6c9be7337c [project @ 1995-09-19 21:54:56 by jwe]
jwe
parents: 1363
diff changeset
462
22051
6db928d06b07 move signal functions into octave namespace
John W. Eaton <jwe@octave.org>
parents: 21966
diff changeset
463 octave::set_interrupt_handler (old_interrupt_handler);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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
dc9c01f66a19 [project @ 1995-09-05 21:10:01 by jwe]
jwe
parents: 1352
diff changeset
471 // disables command line history while it executes.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
472
3551
4833e231e05b [project @ 2000-02-03 02:30:44 by jwe]
jwe
parents: 3544
diff changeset
473 std::fstream file (name.c_str (), std::ios::in);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
474
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23723
diff changeset
477 while ((line = edit_history_readline (file)) != nullptr)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
478 {
1358
dc9c01f66a19 [project @ 1995-09-05 21:10:01 by jwe]
jwe
parents: 1352
diff changeset
479 // Skip blank lines.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
480
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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
9194bb707d63 Plug memory leak in edit_history.
Rik <rik@octave.org>
parents: 15990
diff changeset
488
9194bb707d63 Plug memory leak in edit_history.
Rik <rik@octave.org>
parents: 15990
diff changeset
489 delete [] line;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
490 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
491
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
492 file.close ();
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
493
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
494 octave::unwind_protect frame;
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
495
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
496 frame.add_fcn (unlink_cleanup, name.c_str ());
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
497 frame.protect_var (input_from_tmp_history_file);
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
498
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
499 input_from_tmp_history_file = true;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
500
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
501 // FIXME: instead of sourcing a file, we should just iterate through
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
502 // the list of commands, parsing and executing them one at a time as
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
503 // if they were entered interactively.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
504
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
505 octave::source_file (name);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
506 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
507
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
508 static void
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
509 do_run_history (const octave_value_list& args)
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
510 {
16243
428da5debfe4 maint: Remove commented out lines from history fix in changeset 2a81ce01c383.
Rik <rik@octave.org>
parents: 16242
diff changeset
511 std::string name = mk_tmp_hist_file (args, false, "run_history");
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
512
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
513 if (name.empty ())
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
514 return;
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
515
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
516 octave::unwind_protect frame;
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
517
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
518 frame.add_fcn (unlink_cleanup, name.c_str ());
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
519 frame.protect_var (input_from_tmp_history_file);
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
520
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
521 input_from_tmp_history_file = true;
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
522
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
523 // FIXME: instead of sourcing a file, we should just iterate through
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
524 // the list of commands, parsing and executing them one at a time as
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
525 // if they were entered interactively.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
526
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
527 octave::source_file (name);
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
528 }
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
529
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
530 void
8273
2c1ba965b486 skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents: 7715
diff changeset
531 initialize_history (bool read_history_file)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
532 {
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
533 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
534 default_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_size (),
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
536 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
537
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
538 octave_link::set_history (octave::command_history::list ());
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
539 }
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
540
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
541 void
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
542 octave_history_write_timestamp (void)
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
543 {
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
544 octave::sys::localtime now;
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
545
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
546 std::string timestamp = now.strftime (Vhistory_timestamp_format_string);
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
547
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
548 if (! timestamp.empty ())
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
549 if (octave::command_history::add (timestamp))
17215
7c06875c2dcc Backed out changeset 3d1205d5771e
John W. Eaton <jwe@octave.org>
parents: 17214
diff changeset
550 octave_link::append_history (timestamp);
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
551 }
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
552
23719
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
553 DEFMETHOD (edit_history, interp, args, ,
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
554 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
555 @deftypefn {} {} edit_history
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
556 @deftypefnx {} {} edit_history @var{cmd_number}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
557 @deftypefnx {} {} edit_history @var{first} @var{last}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
558 Edit the history list using the editor named by the variable @env{EDITOR}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
559
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
560 The commands to be edited are first copied to a temporary file. When you
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
561 exit the editor, Octave executes the commands that remain in the file. It
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
562 is often more convenient to use @code{edit_history} to define functions
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
563 rather than attempting to enter them directly on the command line.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
564 The block of commands is executed as soon as you exit the editor.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
565 To avoid executing any commands, simply delete all the lines from the buffer
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
566 before leaving the editor.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
567
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
568 When invoked with no arguments, edit the previously executed command;
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
569 With one argument, edit the specified command @var{cmd_number};
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
570 With two arguments, edit the list of commands between @var{first} and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
571 @var{last}. Command number specifiers may also be negative where -1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
572 refers to the most recently executed command.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
573 The following are equivalent and edit the most recently executed command.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
574
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
575 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
576 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
577 edit_history
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
578 edit_history -1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
579 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
580 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
581
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
582 When using ranges, specifying a larger number for the first command than the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
583 last command reverses the list of commands before they are placed in the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
584 buffer to be edited.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
585 @seealso{run_history, history}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
586 @end deftypefn */)
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
587 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
588 // FIXME: should this be limited to the top-level context?
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
589
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
590 if (args.length () > 2)
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
591 print_usage ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
592
23719
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
593 do_edit_history (interp, args);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
594
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
595 return ovl ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
596 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
597
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
598 DEFUN (history, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
599 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
600 @deftypefn {} {} history
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
601 @deftypefnx {} {} history @var{opt1} @dots{}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
602 @deftypefnx {} {@var{h} =} history ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
603 @deftypefnx {} {@var{h} =} history (@var{opt1}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
604 If invoked with no arguments, @code{history} displays a list of commands
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
605 that you have executed.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
606
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
607 Valid options are:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
608
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
609 @table @code
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
610 @item @var{n}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
611 @itemx -@var{n}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
612 Display only the most recent @var{n} lines of history.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
613
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
614 @item -c
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
615 Clear the history list.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
616
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
617 @item -q
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
618 Don't number the displayed lines of history. This is useful for cutting
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
619 and pasting commands using the X Window System.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
620
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
621 @item -r @var{file}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
622 Read the file @var{file}, appending its contents to the current
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
623 history list. If the name is omitted, use the default history file
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
624 (normally @file{~/.octave_hist}).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
625
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
626 @item -w @var{file}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
627 Write the current history to the file @var{file}. If the name is
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
628 omitted, use the default history file (normally @file{~/.octave_hist}).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
629 @end table
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
630
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
631 For example, to display the five most recent commands that you have
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
632 typed without displaying line numbers, use the command
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
633 @kbd{history -q 5}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
634
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
635 If invoked with a single output argument, the history will be saved to that
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
636 argument as a cell string and will not be output to screen.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
637 @seealso{edit_history, run_history}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
638 @end deftypefn */)
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
639 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
640 // FIXME: should this be limited to the top-level context?
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
641
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
642 // Call do_history even if nargout is zero to display history list.
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
643
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
644 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
645
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
646 return nargout > 0 ? ovl (Cell (hlist)) : ovl ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
647 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
648
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8286
diff changeset
649 DEFUN (run_history, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
650 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
651 @deftypefn {} {} run_history
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
652 @deftypefnx {} {} run_history @var{cmd_number}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
653 @deftypefnx {} {} run_history @var{first} @var{last}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
654 Run commands from the history list.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
655
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
656 When invoked with no arguments, run the previously executed command;
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
657
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
658 With one argument, run the specified command @var{cmd_number};
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
659
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
660 With two arguments, run the list of commands between @var{first} and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
661 @var{last}. Command number specifiers may also be negative where -1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
662 refers to the most recently executed command. For example, the command
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
663
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
664 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
665 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
666 run_history
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
667 OR
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
668 run_history -1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
669 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
670 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
671
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
672 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
673 executes the most recent command again.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
674 The command
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
675
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
676 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
677 run_history 13 169
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
678 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
679
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
680 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
681 executes commands 13 through 169.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
682
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
683 Specifying a larger number for the first command than the last command
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
684 reverses the list of commands before executing them.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
685 For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
686
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
687 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
688 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
689 disp (1)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
690 disp (2)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
691 run_history -1 -2
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
692 @result{}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
693 2
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
694 1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
695 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
696 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
697
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
698 @seealso{edit_history, history}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
699 @end deftypefn */)
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
700 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
701 // FIXME: should this be limited to the top-level context?
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
702
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
703 if (args.length () > 2)
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
704 print_usage ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
705
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
706 do_run_history (args);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
707
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
708 return ovl ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
709 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
710
11486
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
711 DEFUN (history_control, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
712 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
713 @deftypefn {} {@var{val} =} history_control ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
714 @deftypefnx {} {@var{old_val} =} history_control (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
715 Query or set the internal variable that specifies how commands are saved
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
716 to the history list.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
717
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
718 The default value is an empty character string, but may be overridden by the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
719 environment variable @w{@env{OCTAVE_HISTCONTROL}}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
720
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
721 The value of @code{history_control} is a colon-separated list of values
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
722 controlling how commands are saved on the history list. If the list
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
723 of values includes @code{ignorespace}, lines which begin with a space
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
724 character are not saved in the history list. A value of @code{ignoredups}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
725 causes lines matching the previous history entry to not be saved.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
726 A value of @code{ignoreboth} is shorthand for @code{ignorespace} and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
727 @code{ignoredups}. A value of @code{erasedups} causes all previous lines
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
728 matching the current line to be removed from the history list before that
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
729 line is saved. Any value not in the above list is ignored. If
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
730 @code{history_control} is the empty string, all commands are saved on
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
731 the history list, subject to the value of @code{history_save}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
732 @seealso{history_file, history_size, history_timestamp_format_string, history_save}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
733 @end deftypefn */)
11486
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
734 {
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
735 octave_value retval;
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
736
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
737 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
738
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
739 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
740
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
741 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
742
12989
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
743 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
744 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
745
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
746 return retval;
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
747 }
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
748
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
749 DEFUN (history_size, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
750 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
751 @deftypefn {} {@var{val} =} history_size ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
752 @deftypefnx {} {@var{old_val} =} history_size (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
753 Query or set the internal variable that specifies how many entries
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
754 to store in the history file.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
755
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
756 The default value is @code{1000}, but may be overridden by the environment
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
757 variable @w{@env{OCTAVE_HISTSIZE}}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
758 @seealso{history_file, history_timestamp_format_string, history_save}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
759 @end deftypefn */)
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
760 {
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
761 octave_value retval;
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
762
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
763 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
764
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
765 int tmp = old_history_size;
5800
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
766
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
767 retval = set_internal_variable (tmp, args, nargout,
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
768 "history_size", -1,
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
769 std::numeric_limits<int>::max ());
5800
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
770
12989
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
771 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
772 octave::command_history::set_size (tmp);
5800
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
773
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
774 return retval;
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
775 }
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
776
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
777 DEFUN (history_file, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
778 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
779 @deftypefn {} {@var{val} =} history_file ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
780 @deftypefnx {} {@var{old_val} =} history_file (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
781 Query or set the internal variable that specifies the name of the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
782 file used to store command history.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
783
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
784 The default value is @file{~/.octave_hist}, but may be overridden by the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
785 environment variable @w{@env{OCTAVE_HISTFILE}}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
786 @seealso{history_size, history_save, history_timestamp_format_string}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
787 @end deftypefn */)
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
788 {
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
789 octave_value retval;
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
790
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
791 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
792
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
793 std::string tmp = old_history_file;
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
794
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
795 retval = set_internal_variable (tmp, args, nargout, "history_file");
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
796
12989
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
797 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
798 octave::command_history::set_file (tmp);
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
799
5800
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
800 return retval;
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
801 }
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
802
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
803 DEFUN (history_timestamp_format_string, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
804 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
805 @deftypefn {} {@var{val} =} history_timestamp_format_string ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
806 @deftypefnx {} {@var{old_val} =} history_timestamp_format_string (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
807 @deftypefnx {} {} history_timestamp_format_string (@var{new_val}, "local")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
808 Query or set the internal variable that specifies the format string
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
809 for the comment line that is written to the history file when Octave
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
810 exits.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
811
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
812 The format string is passed to @code{strftime}. The default value is
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
813
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
814 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
815 "# Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>"
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
816 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
817
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
818 When called from inside a function with the @qcode{"local"} option, the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
819 variable is changed locally for the function and any subroutines it calls.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
820 The original variable value is restored when exiting the function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
821 @seealso{strftime, history_file, history_size, history_save}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
822 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
823 {
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
824 return SET_INTERNAL_VARIABLE (history_timestamp_format_string);
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
825 }
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
826
16876
9e0618443c2b Rename saving_history() to history_save().
Rik <rik@octave.org>
parents: 16687
diff changeset
827 DEFUN (history_save, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
828 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
829 @deftypefn {} {@var{val} =} history_save ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
830 @deftypefnx {} {@var{old_val} =} history_save (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
831 @deftypefnx {} {} history_save (@var{new_val}, "local")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
832 Query or set the internal variable that controls whether commands entered
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
833 on the command line are saved in the history file.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
834
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
835 When called from inside a function with the @qcode{"local"} option, the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
836 variable is changed locally for the function and any subroutines it calls.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
837 The original variable value is restored when exiting the function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
838 @seealso{history_control, history_file, history_size, history_timestamp_format_string}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
839 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
840 {
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
841 octave_value retval;
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
842
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
843 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
844
16876
9e0618443c2b Rename saving_history() to history_save().
Rik <rik@octave.org>
parents: 16687
diff changeset
845 bool tmp = old_history_save;
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
846
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
847 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
848
16876
9e0618443c2b Rename saving_history() to history_save().
Rik <rik@octave.org>
parents: 16687
diff changeset
849 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
850 octave::command_history::ignore_entries (! tmp);
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
851
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
852 return retval;
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
853 }