Mercurial > octave-nkf
annotate libinterp/corefcn/oct-hist.cc @ 17281:bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Macro handles options ("on") or properties ("position") more elegantly
than @code{"text"}.
* doc/interpreter/macros.texi: Add new @qcode macro.
* doc/interpreter/tips.txi: Add documentation about @qcode macro.
* doc/interpreter/basics.txi, doc/interpreter/container.txi,
doc/interpreter/emacs.txi, doc/interpreter/errors.txi,
doc/interpreter/eval.txi, doc/interpreter/expr.txi,
doc/interpreter/external.txi, doc/interpreter/func.txi,
doc/interpreter/grammar.txi, doc/interpreter/image.txi,
doc/interpreter/install.txi, doc/interpreter/interp.txi,
doc/interpreter/io.txi, doc/interpreter/matrix.txi,
doc/interpreter/numbers.txi, doc/interpreter/oop.txi,
doc/interpreter/package.txi, doc/interpreter/plot.txi,
doc/interpreter/quad.txi, doc/interpreter/sparse.txi,
doc/interpreter/strings.txi, doc/interpreter/system.txi,
doc/interpreter/vectorize.txi, libinterp/corefcn/balance.cc,
libinterp/corefcn/bitfcns.cc, libinterp/corefcn/cellfun.cc,
libinterp/corefcn/conv2.cc, libinterp/corefcn/data.cc,
libinterp/corefcn/debug.cc, libinterp/corefcn/defaults.cc,
libinterp/corefcn/dirfns.cc, libinterp/corefcn/dlmread.cc,
libinterp/corefcn/error.cc, libinterp/corefcn/file-io.cc,
libinterp/corefcn/find.cc, libinterp/corefcn/gammainc.cc,
libinterp/corefcn/graphics.cc, libinterp/corefcn/help.cc,
libinterp/corefcn/hex2num.cc, libinterp/corefcn/input.cc,
libinterp/corefcn/load-path.cc, libinterp/corefcn/load-save.cc,
libinterp/corefcn/ls-oct-ascii.cc, libinterp/corefcn/lu.cc,
libinterp/corefcn/luinc.cc, libinterp/corefcn/matrix_type.cc,
libinterp/corefcn/oct-hist.cc, libinterp/corefcn/pager.cc,
libinterp/corefcn/pr-output.cc, libinterp/corefcn/pt-jit.cc,
libinterp/corefcn/qz.cc, libinterp/corefcn/rand.cc,
libinterp/corefcn/regexp.cc, libinterp/corefcn/schur.cc,
libinterp/corefcn/sighandlers.cc, libinterp/corefcn/sparse.cc,
libinterp/corefcn/spparms.cc, libinterp/corefcn/str2double.cc,
libinterp/corefcn/svd.cc, libinterp/corefcn/symtab.cc,
libinterp/corefcn/syscalls.cc, libinterp/corefcn/toplev.cc,
libinterp/corefcn/tril.cc, libinterp/corefcn/typecast.cc,
libinterp/corefcn/utils.cc, libinterp/corefcn/variables.cc,
libinterp/dldfcn/__init_fltk__.cc, libinterp/dldfcn/chol.cc,
libinterp/dldfcn/colamd.cc, libinterp/dldfcn/fftw.cc, libinterp/dldfcn/qr.cc,
libinterp/dldfcn/symbfact.cc, libinterp/octave-value/ov-base.cc,
libinterp/octave-value/ov-fcn-handle.cc,
libinterp/octave-value/ov-fcn-inline.cc, libinterp/octave-value/ov-java.cc,
libinterp/octave-value/ov-range.cc, libinterp/octave-value/ov-struct.cc,
libinterp/octave-value/ov-usr-fcn.cc, libinterp/parse-tree/oct-parse.in.yy,
libinterp/parse-tree/pt-binop.cc, libinterp/parse-tree/pt-eval.cc,
libinterp/parse-tree/pt-mat.cc, scripts/@ftp/ftp.m,
scripts/deprecated/java_convert_matrix.m, scripts/deprecated/java_debug.m,
scripts/deprecated/java_unsigned_conversion.m, scripts/deprecated/shell_cmd.m,
scripts/general/dblquad.m, scripts/general/display.m,
scripts/general/genvarname.m, scripts/general/idivide.m,
scripts/general/interp1.m, scripts/general/interp2.m,
scripts/general/interp3.m, scripts/general/interpn.m, scripts/general/isa.m,
scripts/general/profexplore.m, scripts/general/profile.m,
scripts/general/quadgk.m, scripts/general/randi.m, scripts/general/structfun.m,
scripts/general/subsindex.m, scripts/general/triplequad.m,
scripts/geometry/griddata.m, scripts/geometry/griddata3.m,
scripts/geometry/griddatan.m, scripts/geometry/voronoi.m, scripts/help/help.m,
scripts/help/lookfor.m, scripts/image/cmpermute.m, scripts/image/colormap.m,
scripts/image/image.m, scripts/image/imagesc.m, scripts/image/imfinfo.m,
scripts/image/imformats.m, scripts/image/imread.m, scripts/image/imshow.m,
scripts/image/imwrite.m, scripts/image/ind2gray.m, scripts/image/lines.m,
scripts/image/rgb2ind.m, scripts/image/spinmap.m, scripts/io/dlmwrite.m,
scripts/io/strread.m, scripts/io/textread.m, scripts/io/textscan.m,
scripts/java/javaclasspath.m, scripts/java/usejava.m,
scripts/miscellaneous/bzip2.m, scripts/miscellaneous/computer.m,
scripts/miscellaneous/copyfile.m, scripts/miscellaneous/debug.m,
scripts/miscellaneous/dos.m, scripts/miscellaneous/edit.m,
scripts/miscellaneous/gzip.m, scripts/miscellaneous/license.m,
scripts/miscellaneous/mkoctfile.m, scripts/miscellaneous/movefile.m,
scripts/miscellaneous/parseparams.m, scripts/miscellaneous/unix.m,
scripts/optimization/fminbnd.m, scripts/optimization/fminsearch.m,
scripts/optimization/fminunc.m, scripts/optimization/fsolve.m,
scripts/optimization/fzero.m, scripts/optimization/glpk.m,
scripts/optimization/lsqnonneg.m, scripts/optimization/optimset.m,
scripts/optimization/pqpnonneg.m, scripts/pkg/pkg.m, scripts/plot/allchild.m,
scripts/plot/ancestor.m, scripts/plot/area.m, scripts/plot/axis.m,
scripts/plot/bar.m, scripts/plot/barh.m, scripts/plot/box.m,
scripts/plot/caxis.m, scripts/plot/cla.m, scripts/plot/clabel.m,
scripts/plot/clf.m, scripts/plot/close.m, scripts/plot/colorbar.m,
scripts/plot/daspect.m, scripts/plot/ezmesh.m, scripts/plot/ezmeshc.m,
scripts/plot/ezsurf.m, scripts/plot/ezsurfc.m, scripts/plot/findall.m,
scripts/plot/findobj.m, scripts/plot/gcbo.m, scripts/plot/gcf.m,
scripts/plot/gco.m, scripts/plot/grid.m, scripts/plot/guihandles.m,
scripts/plot/hdl2struct.m, scripts/plot/hidden.m, scripts/plot/hold.m,
scripts/plot/isonormals.m, scripts/plot/isosurface.m, scripts/plot/legend.m,
scripts/plot/mesh.m, scripts/plot/meshc.m, scripts/plot/meshz.m,
scripts/plot/newplot.m, scripts/plot/orient.m, scripts/plot/pareto.m,
scripts/plot/patch.m, scripts/plot/pbaspect.m, scripts/plot/pcolor.m,
scripts/plot/plot.m, scripts/plot/print.m,
scripts/plot/private/__add_default_menu__.m, scripts/plot/quiver.m,
scripts/plot/quiver3.m, scripts/plot/refreshdata.m, scripts/plot/saveas.m,
scripts/plot/scatter.m, scripts/plot/scatter3.m, scripts/plot/shading.m,
scripts/plot/shrinkfaces.m, scripts/plot/slice.m, scripts/plot/stem.m,
scripts/plot/stem3.m, scripts/plot/struct2hdl.m, scripts/plot/subplot.m,
scripts/plot/surf.m, scripts/plot/surfc.m, scripts/plot/surfl.m,
scripts/plot/tetramesh.m, scripts/plot/uigetfile.m, scripts/plot/uimenu.m,
scripts/plot/uiputfile.m, scripts/plot/waterfall.m, scripts/plot/whitebg.m,
scripts/plot/xlim.m, scripts/plot/ylim.m, scripts/plot/zlim.m,
scripts/polynomial/conv.m, scripts/polynomial/polyout.m,
scripts/polynomial/splinefit.m, scripts/set/ismember.m, scripts/set/powerset.m,
scripts/set/setdiff.m, scripts/set/union.m, scripts/set/unique.m,
scripts/signal/detrend.m, scripts/signal/filter2.m, scripts/signal/freqz.m,
scripts/signal/periodogram.m, scripts/signal/spectral_adf.m,
scripts/signal/spectral_xdf.m, scripts/sparse/eigs.m, scripts/sparse/svds.m,
scripts/specfun/legendre.m, scripts/special-matrix/gallery.m,
scripts/statistics/base/mean.m, scripts/statistics/base/moment.m,
scripts/statistics/tests/cor_test.m,
scripts/statistics/tests/kolmogorov_smirnov_test.m,
scripts/statistics/tests/kolmogorov_smirnov_test_2.m,
scripts/statistics/tests/kruskal_wallis_test.m,
scripts/statistics/tests/prop_test_2.m, scripts/statistics/tests/sign_test.m,
scripts/statistics/tests/t_test.m, scripts/statistics/tests/t_test_2.m,
scripts/statistics/tests/t_test_regression.m,
scripts/statistics/tests/u_test.m, scripts/statistics/tests/var_test.m,
scripts/statistics/tests/welch_test.m,
scripts/statistics/tests/wilcoxon_test.m, scripts/statistics/tests/z_test.m,
scripts/statistics/tests/z_test_2.m, scripts/strings/base2dec.m,
scripts/strings/index.m, scripts/strings/isstrprop.m,
scripts/strings/mat2str.m, scripts/strings/regexptranslate.m,
scripts/strings/rindex.m, scripts/strings/str2num.m, scripts/strings/strcat.m,
scripts/strings/strjust.m, scripts/strings/strmatch.m,
scripts/strings/validatestring.m, scripts/testfun/demo.m,
scripts/testfun/example.m, scripts/testfun/test.m, scripts/time/addtodate.m,
scripts/time/asctime.m, scripts/time/datestr.m, scripts/time/datetick.m,
scripts/time/weekday.m, scripts/ui/errordlg.m, scripts/ui/helpdlg.m,
scripts/ui/inputdlg.m, scripts/ui/listdlg.m, scripts/ui/msgbox.m,
scripts/ui/questdlg.m, scripts/ui/warndlg.m: Use new @qcode macro.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 19 Aug 2013 20:46:38 -0700 |
parents | 33ce8c381f2c |
children | 91691d74845d |
rev | line source |
---|---|
1 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
3 Copyright (C) 1993-2012 John W. Eaton |
1 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1 | 20 |
2939 | 21 */ |
22 | |
23 /* | |
24 | |
1 | 25 The functions listed below were adapted from similar functions from |
26 GNU Bash, the Bourne Again SHell, copyright (C) 1987, 1989, 1991 Free | |
27 Software Foundation, Inc. | |
28 | |
29 do_history edit_history_readline | |
30 do_edit_history edit_history_add_hist | |
31 | |
32 */ | |
33 | |
240 | 34 #ifdef HAVE_CONFIG_H |
1192 | 35 #include <config.h> |
1 | 36 #endif |
37 | |
1343 | 38 #include <cstdlib> |
39 #include <cstring> | |
40 | |
1750 | 41 #include <string> |
42 | |
3503 | 43 #include <fstream> |
1350 | 44 |
1 | 45 #include <sys/types.h> |
46 #include <unistd.h> | |
1350 | 47 |
1799 | 48 #include "cmd-hist.h" |
1802 | 49 #include "file-ops.h" |
3016 | 50 #include "lo-mappers.h" |
16431
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
51 #include "octave-link.h" |
2926 | 52 #include "oct-env.h" |
5305 | 53 #include "oct-time.h" |
1755 | 54 #include "str-vec.h" |
55 | |
2492 | 56 #include <defaults.h> |
1352 | 57 #include "defun.h" |
1 | 58 #include "error.h" |
3016 | 59 #include "gripes.h" |
1 | 60 #include "input.h" |
1742 | 61 #include "oct-hist.h" |
1750 | 62 #include "oct-obj.h" |
1352 | 63 #include "pager.h" |
3018 | 64 #include "parse.h" |
1352 | 65 #include "sighandlers.h" |
1690 | 66 #include "sysdep.h" |
1750 | 67 #include "toplev.h" |
1352 | 68 #include "unwind-prot.h" |
69 #include "utils.h" | |
2205 | 70 #include "variables.h" |
1 | 71 |
3018 | 72 // TRUE means input is coming from temporary history file. |
73 bool input_from_tmp_history_file = false; | |
168 | 74 |
5305 | 75 static std::string |
1 | 76 default_history_file (void) |
77 { | |
3523 | 78 std::string file; |
1 | 79 |
3523 | 80 std::string env_file = octave_env::getenv ("OCTAVE_HISTFILE"); |
1755 | 81 |
2926 | 82 if (! env_file.empty ()) |
6141 | 83 file = env_file; |
1 | 84 |
1755 | 85 if (file.empty ()) |
7272 | 86 file = file_ops::concat (octave_env::get_home_directory (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
87 ".octave_hist"); |
1 | 88 |
89 return file; | |
90 } | |
91 | |
5305 | 92 static int |
93 default_history_size (void) | |
94 { | |
16025
a78c1e445cfc
Change default history size to 1000.
Rik <rik@octave.org>
parents:
16022
diff
changeset
|
95 int size = 1000; |
5305 | 96 |
97 std::string env_size = octave_env::getenv ("OCTAVE_HISTSIZE"); | |
98 | |
99 if (! env_size.empty ()) | |
100 { | |
101 int val; | |
102 | |
103 if (sscanf (env_size.c_str (), "%d", &val) == 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
104 size = val > 0 ? val : 0; |
5305 | 105 } |
106 | |
107 return size; | |
108 } | |
109 | |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
110 static std::string |
5305 | 111 default_history_timestamp_format (void) |
112 { | |
113 return | |
114 std::string ("# Octave " OCTAVE_VERSION ", %a %b %d %H:%M:%S %Y %Z <") | |
115 + octave_env::get_user_name () | |
116 + std::string ("@") | |
117 + octave_env::get_host_name () | |
118 + std::string (">"); | |
119 } | |
120 | |
5794 | 121 // The format of the timestamp marker written to the history file when |
122 // Octave exits. | |
123 static std::string Vhistory_timestamp_format_string | |
124 = default_history_timestamp_format (); | |
125 | |
581 | 126 // Display, save, or load history. Stolen and modified from bash. |
127 // | |
128 // Arg of -w FILENAME means write file, arg of -r FILENAME | |
129 // 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
|
130 // means only display that many items. |
581 | 131 |
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
|
132 static string_vector |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
133 do_history (const octave_value_list& args, int nargout) |
1 | 134 { |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
135 bool numbered_output = nargout == 0; |
1 | 136 |
12990
07dc4839c05f
properly save and restore command history file name in history command (bug #32524)
John W. Eaton <jwe@octave.org>
parents:
12989
diff
changeset
|
137 unwind_protect frame; |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
138 |
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
|
139 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
|
140 |
07dc4839c05f
properly save and restore command history file name in history command (bug #32524)
John W. Eaton <jwe@octave.org>
parents:
12989
diff
changeset
|
141 frame.add_fcn (command_history::set_file, command_history::file ()); |
07dc4839c05f
properly save and restore command history file name in history command (bug #32524)
John W. Eaton <jwe@octave.org>
parents:
12989
diff
changeset
|
142 |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
143 int nargin = args.length (); |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
144 |
16242
2a81ce01c383
Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents:
16196
diff
changeset
|
145 // 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
|
146 int limit = -1; |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
147 |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
148 for (octave_idx_type i = 0; i < nargin; i++) |
1 | 149 { |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
150 octave_value arg = args(i); |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
151 |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
152 std::string option; |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
153 |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
154 if (arg.is_string ()) |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
155 option = arg.string_value (); |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
156 else if (arg.is_numeric_type ()) |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
157 { |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
158 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
|
159 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
|
160 limit = -limit; |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
161 continue; |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
162 } |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
163 else |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
164 { |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
165 gripe_wrong_type_arg ("history", arg); |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
166 return hlist; |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
167 } |
2435 | 168 |
169 if (option == "-r" || option == "-w" || option == "-a" | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
170 || option == "-n") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
171 { |
16685
5c5c46a81ad5
Added default name usage for history -r,-w option (Bug #38986)
John Donoghue <john.donoghue@ieee.org>
parents:
16431
diff
changeset
|
172 if (i < nargin - 1) |
5c5c46a81ad5
Added default name usage for history -r,-w option (Bug #38986)
John Donoghue <john.donoghue@ieee.org>
parents:
16431
diff
changeset
|
173 { |
5c5c46a81ad5
Added default name usage for history -r,-w option (Bug #38986)
John Donoghue <john.donoghue@ieee.org>
parents:
16431
diff
changeset
|
174 if (args(i+1).is_string ()) |
5c5c46a81ad5
Added default name usage for history -r,-w option (Bug #38986)
John Donoghue <john.donoghue@ieee.org>
parents:
16431
diff
changeset
|
175 command_history::set_file (args(++i).string_value ()); |
5c5c46a81ad5
Added default name usage for history -r,-w option (Bug #38986)
John Donoghue <john.donoghue@ieee.org>
parents:
16431
diff
changeset
|
176 else |
16687
f4d18d3f7fd7
* oct-hist.cc: Style fixes. Remove unused code.
John W. Eaton <jwe@octave.org>
parents:
16685
diff
changeset
|
177 { |
f4d18d3f7fd7
* oct-hist.cc: Style fixes. Remove unused code.
John W. Eaton <jwe@octave.org>
parents:
16685
diff
changeset
|
178 error ("history: expecting file name for %s option", |
f4d18d3f7fd7
* oct-hist.cc: Style fixes. Remove unused code.
John W. Eaton <jwe@octave.org>
parents:
16685
diff
changeset
|
179 option.c_str ()); |
f4d18d3f7fd7
* oct-hist.cc: Style fixes. Remove unused code.
John W. Eaton <jwe@octave.org>
parents:
16685
diff
changeset
|
180 return hlist; |
f4d18d3f7fd7
* oct-hist.cc: Style fixes. Remove unused code.
John W. Eaton <jwe@octave.org>
parents:
16685
diff
changeset
|
181 } |
16685
5c5c46a81ad5
Added default name usage for history -r,-w option (Bug #38986)
John Donoghue <john.donoghue@ieee.org>
parents:
16431
diff
changeset
|
182 } |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
183 else |
16687
f4d18d3f7fd7
* oct-hist.cc: Style fixes. Remove unused code.
John W. Eaton <jwe@octave.org>
parents:
16685
diff
changeset
|
184 command_history::set_file (default_history_file ()); |
1 | 185 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
186 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
|
187 // Append 'new' lines to file. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
188 command_history::append (); |
2435 | 189 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
190 else if (option == "-w") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
191 // Write entire history. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
192 command_history::write (); |
777 | 193 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
194 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
|
195 { |
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
196 // Read entire file. |
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
197 command_history::read (); |
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
198 octave_link::set_history (command_history::list ()); |
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
199 } |
777 | 200 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
201 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
|
202 { |
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
203 // Read 'new' history from file. |
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
204 command_history::read_range (); |
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
205 octave_link::set_history (command_history::list ()); |
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
206 } |
777 | 207 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
208 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
209 panic_impossible (); |
2435 | 210 |
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
|
211 return hlist; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
212 } |
16431
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
213 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
|
214 { |
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
215 command_history::clear (); |
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
216 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
|
217 } |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
218 else if (option == "-q") |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
219 numbered_output = false; |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
220 else if (option == "--") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
221 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
222 i++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
223 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
224 } |
1 | 225 else |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
226 { |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
227 // 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
|
228 // an integer will be used |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
229 int tmp; |
1 | 230 |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
231 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
|
232 { |
2a81ce01c383
Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents:
16196
diff
changeset
|
233 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
|
234 limit = tmp; |
2a81ce01c383
Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents:
16196
diff
changeset
|
235 else |
2a81ce01c383
Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents:
16196
diff
changeset
|
236 limit = -tmp; |
2a81ce01c383
Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents:
16196
diff
changeset
|
237 } |
2a81ce01c383
Fix history() so that it shows all commands when called with no arguments.
Rik <rik@octave.org>
parents:
16196
diff
changeset
|
238 |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
239 else |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
240 { |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
241 if (option.length () > 0 && option[0] == '-') |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
242 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
|
243 else |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
244 error ("history: bad non-numeric arg '%s'", option.c_str ()); |
1799 | 245 |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
246 return hlist; |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
247 } |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
248 } |
15817
dbb7896f15c7
Fix argument passing to history() command
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15814
diff
changeset
|
249 } |
1 | 250 |
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
|
251 hlist = command_history::list (limit, numbered_output); |
1 | 252 |
1799 | 253 int len = hlist.length (); |
254 | |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
255 if (nargout == 0) |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
256 { |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
257 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
|
258 octave_stdout << hlist[i] << "\n"; |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
259 } |
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
|
260 |
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
|
261 return hlist; |
1 | 262 } |
263 | |
581 | 264 // Read the edited history lines from STREAM and return them |
265 // one at a time. This can read unlimited length lines. The | |
2434 | 266 // caller should free the storage. |
581 | 267 |
1 | 268 static char * |
3551 | 269 edit_history_readline (std::fstream& stream) |
1 | 270 { |
271 char c; | |
272 int line_len = 128; | |
273 int lindex = 0; | |
274 char *line = new char [line_len]; | |
275 line[0] = '\0'; | |
276 | |
277 while (stream.get (c)) | |
278 { | |
279 if (lindex + 2 >= line_len) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
280 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
281 char *tmp_line = new char [line_len += 128]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
282 strcpy (tmp_line, line); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
283 delete [] line; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
284 line = tmp_line; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
285 } |
1 | 286 |
287 if (c == '\n') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
288 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
289 line[lindex++] = '\n'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
290 line[lindex++] = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
291 return line; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
292 } |
1 | 293 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
294 line[lindex++] = c; |
1 | 295 } |
296 | |
297 if (! lindex) | |
298 { | |
299 delete [] line; | |
529 | 300 return 0; |
1 | 301 } |
302 | |
303 if (lindex + 2 >= line_len) | |
304 { | |
305 char *tmp_line = new char [lindex+3]; | |
306 strcpy (tmp_line, line); | |
307 delete [] line; | |
308 line = tmp_line; | |
309 } | |
310 | |
1358 | 311 // Finish with newline if none in file. |
1 | 312 |
313 line[lindex++] = '\n'; | |
314 line[lindex++] = '\0'; | |
315 return line; | |
316 } | |
317 | |
318 static void | |
3523 | 319 edit_history_add_hist (const std::string& line) |
1 | 320 { |
1799 | 321 if (! line.empty ()) |
1 | 322 { |
3523 | 323 std::string tmp = line; |
1 | 324 |
1799 | 325 int len = tmp.length (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
326 |
1799 | 327 if (len > 0 && tmp[len-1] == '\n') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
328 tmp.resize (len - 1); |
1799 | 329 |
330 if (! tmp.empty ()) | |
17219
33ce8c381f2c
make history widget respect history_control settings (bug #39728)
Torsten <ttl@justmail.de>
parents:
17215
diff
changeset
|
331 if (command_history::add (tmp)) |
17215
7c06875c2dcc
Backed out changeset 3d1205d5771e
John W. Eaton <jwe@octave.org>
parents:
17214
diff
changeset
|
332 octave_link::append_history (tmp); |
1 | 333 } |
334 } | |
335 | |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
336 static bool |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
337 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
|
338 { |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
339 bool ok = true; |
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 if (arg.is_string ()) |
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 std::string tmp = arg.string_value (); |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
344 |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
345 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
|
346 } |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
347 else if (arg.is_numeric_type ()) |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
348 val = arg.int_value (); |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
349 else |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
350 ok = false; |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
351 |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
352 return ok; |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
353 } |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
354 |
3536 | 355 static std::string |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
356 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
|
357 bool insert_curr, const char *warn_for) |
1 | 358 { |
3523 | 359 std::string retval; |
1 | 360 |
2926 | 361 string_vector hlist = command_history::list (); |
1 | 362 |
16022
d8f216d241cf
Fix off-by-1 error in run_history when called with no arguments.
Rik <rik@octave.org>
parents:
16016
diff
changeset
|
363 int hist_count = hlist.length () - 1; // switch to zero-based indexing |
1 | 364 |
1358 | 365 // 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
|
366 // 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
|
367 // 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
|
368 // but the actual commands performed will. |
1 | 369 |
64 | 370 if (! insert_curr) |
2926 | 371 command_history::remove (hist_count); |
1799 | 372 |
16022
d8f216d241cf
Fix off-by-1 error in run_history when called with no arguments.
Rik <rik@octave.org>
parents:
16016
diff
changeset
|
373 hist_count--; // skip last entry in history list |
1 | 374 |
1358 | 375 // If no numbers have been specified, the default is to edit the |
376 // last command in the history list. | |
1 | 377 |
16022
d8f216d241cf
Fix off-by-1 error in run_history when called with no arguments.
Rik <rik@octave.org>
parents:
16016
diff
changeset
|
378 int hist_beg = hist_count; |
1 | 379 int hist_end = hist_count; |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
380 |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
381 bool reverse = false; |
1 | 382 |
1358 | 383 // Process options. |
1 | 384 |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
385 int nargin = args.length (); |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
386 |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
387 bool usage_error = false; |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
388 if (nargin == 2) |
1 | 389 { |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
390 if (get_int_arg (args(0), hist_beg) |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
391 && get_int_arg (args(1), hist_end)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
392 { |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
393 if (hist_beg < 0) |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
394 hist_beg += (hist_count + 1); |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
395 else |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
396 hist_beg--; |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
397 if (hist_end < 0) |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
398 hist_end += (hist_count + 1); |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
399 else |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
400 hist_end--; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
401 } |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
402 else |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
403 usage_error = true; |
1 | 404 } |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
405 else if (nargin == 1) |
1 | 406 { |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
407 if (get_int_arg (args(0), hist_beg)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
408 { |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
409 if (hist_beg < 0) |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
410 hist_beg += (hist_count + 1); |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
411 else |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
412 hist_beg--; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
413 hist_end = hist_beg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
414 } |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
415 else |
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
416 usage_error = true; |
1 | 417 } |
418 | |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
419 if (usage_error) |
1 | 420 { |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
421 usage ("%s [first] [last]", warn_for); |
1799 | 422 return retval; |
1 | 423 } |
424 | |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
425 if (hist_beg > hist_count || hist_end > hist_count) |
1 | 426 { |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
427 error ("%s: history specification out of range", warn_for); |
1799 | 428 return retval; |
1 | 429 } |
430 | |
431 if (hist_end < hist_beg) | |
432 { | |
16022
d8f216d241cf
Fix off-by-1 error in run_history when called with no arguments.
Rik <rik@octave.org>
parents:
16016
diff
changeset
|
433 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
|
434 reverse = true; |
1 | 435 } |
436 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
437 std::string name = octave_tempnam ("", "oct-"); |
1 | 438 |
3551 | 439 std::fstream file (name.c_str (), std::ios::out); |
64 | 440 |
1 | 441 if (! file) |
442 { | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
443 error ("%s: couldn't open temporary file '%s'", warn_for, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
444 name.c_str ()); |
1799 | 445 return retval; |
1 | 446 } |
447 | |
448 if (reverse) | |
449 { | |
450 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
|
451 file << hlist[i] << "\n"; |
1 | 452 } |
453 else | |
454 { | |
455 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
|
456 file << hlist[i] << "\n"; |
1 | 457 } |
458 | |
459 file.close (); | |
460 | |
1755 | 461 return name; |
64 | 462 } |
463 | |
10411 | 464 static void |
465 unlink_cleanup (const char *file) | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
466 { |
10411 | 467 gnulib::unlink (file); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
468 } |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
469 |
1755 | 470 static void |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
471 do_edit_history (const octave_value_list& args) |
64 | 472 { |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
473 std::string name = mk_tmp_hist_file (args, false, "edit_history"); |
64 | 474 |
1755 | 475 if (name.empty ()) |
64 | 476 return; |
477 | |
1358 | 478 // Call up our favorite editor on the file of commands. |
1 | 479 |
5794 | 480 std::string cmd = VEDITOR; |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
481 cmd.append (" \"" + name + "\""); |
1 | 482 |
1358 | 483 // Ignore interrupts while we are off editing commands. Should we |
484 // maybe avoid using system()? | |
1 | 485 |
2705 | 486 volatile octave_interrupt_handler old_interrupt_handler |
2554 | 487 = octave_ignore_interrupts (); |
1443 | 488 |
15990
696e82182eba
Check if history edition was successful, abort operation on failure.
Júlio Hoffimann <julio.hoffimann@gmail.com>
parents:
15823
diff
changeset
|
489 int status = system (cmd.c_str ()); |
1443 | 490 |
2554 | 491 octave_set_interrupt_handler (old_interrupt_handler); |
1 | 492 |
15990
696e82182eba
Check if history edition was successful, abort operation on failure.
Júlio Hoffimann <julio.hoffimann@gmail.com>
parents:
15823
diff
changeset
|
493 // 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
|
494 // 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
|
495 if (status != EXIT_SUCCESS) |
696e82182eba
Check if history edition was successful, abort operation on failure.
Júlio Hoffimann <julio.hoffimann@gmail.com>
parents:
15823
diff
changeset
|
496 { |
696e82182eba
Check if history edition was successful, abort operation on failure.
Júlio Hoffimann <julio.hoffimann@gmail.com>
parents:
15823
diff
changeset
|
497 error ("edit_history: text editor command failed"); |
696e82182eba
Check if history edition was successful, abort operation on failure.
Júlio Hoffimann <julio.hoffimann@gmail.com>
parents:
15823
diff
changeset
|
498 return; |
696e82182eba
Check if history edition was successful, abort operation on failure.
Júlio Hoffimann <julio.hoffimann@gmail.com>
parents:
15823
diff
changeset
|
499 } |
696e82182eba
Check if history edition was successful, abort operation on failure.
Júlio Hoffimann <julio.hoffimann@gmail.com>
parents:
15823
diff
changeset
|
500 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
501 // Write the commands to the history file since source_file |
1358 | 502 // disables command line history while it executes. |
1 | 503 |
3551 | 504 std::fstream file (name.c_str (), std::ios::in); |
1 | 505 |
506 char *line; | |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
507 //int first = 1; |
529 | 508 while ((line = edit_history_readline (file)) != 0) |
1 | 509 { |
1358 | 510 // Skip blank lines. |
1 | 511 |
512 if (line[0] == '\n') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
513 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
514 delete [] line; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
515 continue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
516 } |
1 | 517 |
16051
3a06aa956d96
Fix off-by-1 error in history list when running 'edit_history'.
Rik <rik@octave.org>
parents:
16025
diff
changeset
|
518 edit_history_add_hist (line); |
16016 | 519 |
520 delete [] line; | |
1 | 521 } |
522 | |
523 file.close (); | |
524 | |
1358 | 525 // Turn on command echo, so the output from this will make better |
526 // sense. | |
1 | 527 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
528 unwind_protect frame; |
3018 | 529 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
530 frame.add_fcn (unlink_cleanup, name.c_str ()); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
531 frame.protect_var (Vecho_executing_commands); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
532 frame.protect_var (input_from_tmp_history_file); |
3018 | 533 |
2205 | 534 Vecho_executing_commands = ECHO_CMD_LINE; |
3018 | 535 input_from_tmp_history_file = true; |
1 | 536 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
537 source_file (name); |
1 | 538 } |
539 | |
1755 | 540 static void |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
541 do_run_history (const octave_value_list& args) |
64 | 542 { |
16243
428da5debfe4
maint: Remove commented out lines from history fix in changeset 2a81ce01c383.
Rik <rik@octave.org>
parents:
16242
diff
changeset
|
543 std::string name = mk_tmp_hist_file (args, false, "run_history"); |
64 | 544 |
1755 | 545 if (name.empty ()) |
64 | 546 return; |
547 | |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
548 // Turn on command echo so the output from this will make better sense. |
64 | 549 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
550 unwind_protect frame; |
3018 | 551 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
552 frame.add_fcn (unlink_cleanup, name.c_str ()); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
553 frame.protect_var (Vecho_executing_commands); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
554 frame.protect_var (input_from_tmp_history_file); |
3018 | 555 |
2205 | 556 Vecho_executing_commands = ECHO_CMD_LINE; |
3018 | 557 input_from_tmp_history_file = true; |
64 | 558 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
559 source_file (name); |
64 | 560 } |
561 | |
5305 | 562 void |
8273
2c1ba965b486
skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
563 initialize_history (bool read_history_file) |
5794 | 564 { |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
565 command_history::initialize (read_history_file, |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
566 default_history_file (), |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
567 default_history_size (), |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
568 octave_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
|
569 |
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
570 octave_link::set_history (command_history::list ()); |
5794 | 571 } |
572 | |
573 void | |
5305 | 574 octave_history_write_timestamp (void) |
575 { | |
576 octave_localtime now; | |
577 | |
578 std::string timestamp = now.strftime (Vhistory_timestamp_format_string); | |
579 | |
580 if (! timestamp.empty ()) | |
17219
33ce8c381f2c
make history widget respect history_control settings (bug #39728)
Torsten <ttl@justmail.de>
parents:
17215
diff
changeset
|
581 if (command_history::add (timestamp)) |
17215
7c06875c2dcc
Backed out changeset 3d1205d5771e
John W. Eaton <jwe@octave.org>
parents:
17214
diff
changeset
|
582 octave_link::append_history (timestamp); |
5305 | 583 } |
584 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8286
diff
changeset
|
585 DEFUN (edit_history, args, , |
3332 | 586 "-*- texinfo -*-\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
587 @deftypefn {Command} {} edit_history\n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
588 @deftypefnx {Command} {} edit_history @var{cmd_number}\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
589 @deftypefnx {Command} {} edit_history @var{first} @var{last}\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
590 Edit the history list using the editor named by the variable\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
591 @w{@env{EDITOR}}.\n\ |
3332 | 592 \n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
593 The commands to be edited are first copied to a temporary file. When you\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
594 exit the editor, Octave executes the commands that remain in the file. It\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
595 is often more convenient to use @code{edit_history} to define functions\n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
596 rather than attempting to enter them directly on the command line.\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
597 The block of commands is executed as soon as you exit the editor.\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
598 To avoid executing any commands, simply delete all the lines from the buffer\n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
599 before leaving the editor.\n\ |
3332 | 600 \n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
601 When invoked with no arguments, edit the previously executed command;\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
602 With one argument, edit the specified command @var{cmd_number};\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
603 With two arguments, edit the list of commands between @var{first} and\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
604 @var{last}. Command number specifiers may also be negative where -1\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
605 refers to the most recently executed command.\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
606 The following are equivalent and edit the most recently executed command.\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
607 \n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
608 @example\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
609 @group\n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
610 edit_history\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
611 edit_history -1\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
612 @end group\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
613 @end example\n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
614 \n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
615 When using ranges, specifying a larger number for the first command than the\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
616 last command reverses the list of commands before they are placed in the\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
617 buffer to be edited.\n\ |
9035
57649dcecb55
Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
618 @seealso{run_history}\n\ |
11547 | 619 @end deftypefn") |
529 | 620 { |
2086 | 621 octave_value_list retval; |
529 | 622 |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
623 do_edit_history (args); |
529 | 624 |
625 return retval; | |
626 } | |
627 | |
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
|
628 DEFUN (history, args, nargout, |
3332 | 629 "-*- texinfo -*-\n\ |
16052 | 630 @deftypefn {Command} {} history\n\ |
631 @deftypefnx {Command} {} history @var{opt1} @dots{}\n\ | |
632 @deftypefnx {Built-in Function} {@var{h} =} history ()\n\ | |
633 @deftypefnx {Built-in Function} {@var{h} =} history (@var{opt1}, @dots{})\n\ | |
3332 | 634 If invoked with no arguments, @code{history} displays a list of commands\n\ |
635 that you have executed. Valid options are:\n\ | |
636 \n\ | |
637 @table @code\n\ | |
16052 | 638 @item @var{n}\n\ |
639 @itemx -@var{n}\n\ | |
640 Display only the most recent @var{n} lines of history.\n\ | |
641 \n\ | |
16431
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
642 @item -c\n\ |
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
643 Clear the history list.\n\ |
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
644 \n\ |
16052 | 645 @item -q\n\ |
646 Don't number the displayed lines of history. This is useful for cutting\n\ | |
647 and pasting commands using the X Window System.\n\ | |
529 | 648 \n\ |
3332 | 649 @item -r @var{file}\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
650 Read the file @var{file}, appending its contents to the current\n\ |
11405
51b6193e90bb
Documentation fixes
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11368
diff
changeset
|
651 history list. If the name is omitted, use the default history file\n\ |
3332 | 652 (normally @file{~/.octave_hist}).\n\ |
653 \n\ | |
16052 | 654 @item -w @var{file}\n\ |
655 Write the current history to the file @var{file}. If the name is\n\ | |
656 omitted, use the default history file (normally @file{~/.octave_hist}).\n\ | |
3332 | 657 @end table\n\ |
658 \n\ | |
659 For example, to display the five most recent commands that you have\n\ | |
660 typed without displaying line numbers, use the command\n\ | |
661 @kbd{history -q 5}.\n\ | |
15814
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
662 \n\ |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
663 If invoked with a single output argument, the history will be saved to that\n\ |
1eee8d8c59fd
Return history as a cell string when called with an output argument (bug #37947)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15467
diff
changeset
|
664 argument as a cell string and will not be output to screen.\n\ |
11547 | 665 @end deftypefn") |
529 | 666 { |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
667 octave_value retval; |
529 | 668 |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
669 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
|
670 |
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
|
671 if (nargout > 0) |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
672 retval = Cell (hlist); |
529 | 673 |
674 return retval; | |
675 } | |
676 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8286
diff
changeset
|
677 DEFUN (run_history, args, , |
3332 | 678 "-*- texinfo -*-\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
679 @deftypefn {Command} {} run_history\n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
680 @deftypefnx {Command} {} run_history @var{cmd_number}\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
681 @deftypefnx {Command} {} run_history @var{first} @var{last}\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
682 Run commands from the history list.\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
683 \n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
684 When invoked with no arguments, run the previously executed command;\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
685 With one argument, run the specified command @var{cmd_number};\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
686 With two arguments, run the list of commands between @var{first} and\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
687 @var{last}. Command number specifiers may also be negative where -1\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
688 refers to the most recently executed command.\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
689 For example, the command\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
690 \n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
691 @example\n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
692 @group\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
693 run_history\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
694 OR\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
695 run_history -1\n\ |
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
696 @end group\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
697 @end example\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
698 \n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
699 @noindent\n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
700 executes the most recent command again.\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
701 The command\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
702 \n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
703 @example\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
704 run_history 13 169\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
705 @end example\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
706 \n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
707 @noindent\n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
708 executes commands 13 through 169.\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
709 \n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
710 Specifying a larger number for the first command than the last command\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
711 reverses the list of commands before executing them.\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
712 For example:\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
713 \n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
714 @example\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
715 @group\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
716 disp (1)\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
717 disp (2)\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
718 run_history -1 -2\n\ |
16189
2825897a0c27
doc: Fix docstrings for edit_history, run_history to match true behavior.
Rik <rik@octave.org>
parents:
16188
diff
changeset
|
719 @result{}\n\ |
16188
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
720 2\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
721 1\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
722 @end group\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
723 @end example\n\ |
8366bc871d45
Allow negative numbers to be used in specifying edit_history commands.
Rik <rik@octave.org>
parents:
16052
diff
changeset
|
724 \n\ |
9035
57649dcecb55
Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
725 @seealso{edit_history}\n\ |
11547 | 726 @end deftypefn") |
529 | 727 { |
2086 | 728 octave_value_list retval; |
529 | 729 |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
730 do_run_history (args); |
529 | 731 |
732 return retval; | |
733 } | |
734 | |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
735 DEFUN (history_control, args, nargout, |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
736 "-*- texinfo -*-\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
737 @deftypefn {Built-in Function} {@var{val} =} history_control ()\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
738 @deftypefnx {Built-in Function} {@var{old_val} =} history_control (@var{new_val})\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
739 Query or set the internal variable that specifies how commands are saved\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
740 to the history list. The default value is an empty character string,\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
741 but may be overridden by the environment variable\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
742 @w{@env{OCTAVE_HISTCONTROL}}.\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
743 \n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
744 The value of @code{history_control} is a colon-separated list of values\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11547
diff
changeset
|
745 controlling how commands are saved on the history list. If the list\n\ |
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11547
diff
changeset
|
746 of values includes @code{ignorespace}, lines which begin with a space\n\ |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
747 character are not saved in the history list. A value of @code{ignoredups}\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
748 causes lines matching the previous history entry to not be saved.\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
749 A value of @code{ignoreboth} is shorthand for @code{ignorespace} and\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
750 @code{ignoredups}. A value of @code{erasedups} causes all previous lines\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
751 matching the current line to be removed from the history list before that\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
752 line is saved. Any value not in the above list is ignored. If\n\ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
753 @code{history_control} is the empty string, all commands are saved on\n\ |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
754 the history list, subject to the value of @code{history_save}.\n\ |
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
755 @seealso{history_file, history_size, history_timestamp_format_string, history_save}\n\ |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
756 @end deftypefn") |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
757 { |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
758 std::string old_history_control = command_history::histcontrol (); |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
759 |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
760 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
|
761 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
762 octave_value retval = set_internal_variable (tmp, args, nargout, |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
763 "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
|
764 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
765 if (tmp != old_history_control) |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
766 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
|
767 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
768 return retval; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
769 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
770 |
5794 | 771 DEFUN (history_size, args, nargout, |
772 "-*- texinfo -*-\n\ | |
10840 | 773 @deftypefn {Built-in Function} {@var{val} =} history_size ()\n\ |
5794 | 774 @deftypefnx {Built-in Function} {@var{old_val} =} history_size (@var{new_val})\n\ |
775 Query or set the internal variable that specifies how many entries\n\ | |
16025
a78c1e445cfc
Change default history size to 1000.
Rik <rik@octave.org>
parents:
16022
diff
changeset
|
776 to store in the history file. The default value is @code{1000},\n\ |
10840 | 777 but may be overridden by the environment variable @w{@env{OCTAVE_HISTSIZE}}.\n\ |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
778 @seealso{history_file, history_timestamp_format_string, history_save}\n\ |
5794 | 779 @end deftypefn") |
3016 | 780 { |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
781 int old_history_size = command_history::size (); |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
782 |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
783 int tmp = old_history_size; |
5800 | 784 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
785 octave_value retval = set_internal_variable (tmp, args, nargout, |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
786 "history_size", -1, |
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
787 std::numeric_limits<int>::max ()); |
5800 | 788 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
789 if (tmp != old_history_size) |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
790 command_history::set_size (tmp); |
5800 | 791 |
792 return retval; | |
3016 | 793 } |
794 | |
5794 | 795 DEFUN (history_file, args, nargout, |
796 "-*- texinfo -*-\n\ | |
10840 | 797 @deftypefn {Built-in Function} {@var{val} =} history_file ()\n\ |
5794 | 798 @deftypefnx {Built-in Function} {@var{old_val} =} history_file (@var{new_val})\n\ |
799 Query or set the internal variable that specifies the name of the\n\ | |
800 file used to store command history. The default value is\n\ | |
9134
a3739e27b017
Update section 2.4 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9035
diff
changeset
|
801 @file{~/.octave_hist}, but may be overridden by the environment\n\ |
10840 | 802 variable @w{@env{OCTAVE_HISTFILE}}.\n\ |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
803 @seealso{history_size, history_save, history_timestamp_format_string}\n\ |
5794 | 804 @end deftypefn") |
5305 | 805 { |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
806 std::string old_history_file = command_history::file (); |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
807 |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
808 std::string tmp = old_history_file; |
5305 | 809 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
810 octave_value retval = set_internal_variable (tmp, args, nargout, |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
811 "history_file"); |
5305 | 812 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
813 if (tmp != old_history_file) |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
814 command_history::set_file (tmp); |
5305 | 815 |
5800 | 816 return retval; |
3016 | 817 } |
818 | |
5794 | 819 DEFUN (history_timestamp_format_string, args, nargout, |
820 "-*- texinfo -*-\n\ | |
10840 | 821 @deftypefn {Built-in Function} {@var{val} =} history_timestamp_format_string ()\n\ |
5794 | 822 @deftypefnx {Built-in Function} {@var{old_val} =} history_timestamp_format_string (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12990
diff
changeset
|
823 @deftypefnx {Built-in Function} {} history_timestamp_format_string (@var{new_val}, \"local\")\n\ |
6653 | 824 Query or set the internal variable that specifies the format string\n\ |
5794 | 825 for the comment line that is written to the history file when Octave\n\ |
826 exits. The format string is passed to @code{strftime}. The default\n\ | |
827 value is\n\ | |
5305 | 828 \n\ |
829 @example\n\ | |
830 \"# Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>\"\n\ | |
831 @end example\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12990
diff
changeset
|
832 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17219
diff
changeset
|
833 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17219
diff
changeset
|
834 variable is changed locally for the function and any subroutines it calls. \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17219
diff
changeset
|
835 The original variable value is restored when exiting the function.\n\ |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
836 @seealso{strftime, history_file, history_size, history_save}\n\ |
5794 | 837 @end deftypefn") |
838 { | |
839 return SET_INTERNAL_VARIABLE (history_timestamp_format_string); | |
840 } | |
5305 | 841 |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
842 DEFUN (history_save, args, nargout, |
5794 | 843 "-*- texinfo -*-\n\ |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
844 @deftypefn {Built-in Function} {@var{val} =} history_save ()\n\ |
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
845 @deftypefnx {Built-in Function} {@var{old_val} =} history_save (@var{new_val})\n\ |
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
846 @deftypefnx {Built-in Function} {} history_save (@var{new_val}, \"local\")\n\ |
5794 | 847 Query or set the internal variable that controls whether commands entered\n\ |
848 on the command line are saved in the history file.\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12990
diff
changeset
|
849 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17219
diff
changeset
|
850 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17219
diff
changeset
|
851 variable is changed locally for the function and any subroutines it calls. \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17219
diff
changeset
|
852 The original variable value is restored when exiting the function.\n\ |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
853 @seealso{history_control, history_file, history_size, history_timestamp_format_string}\n\ |
5794 | 854 @end deftypefn") |
855 { | |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
856 bool old_history_save = ! command_history::ignoring_entries (); |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
857 |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
858 bool tmp = old_history_save; |
5794 | 859 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
860 octave_value retval = set_internal_variable (tmp, args, nargout, |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
861 "history_save"); |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
862 |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
863 if (tmp != old_history_save) |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
864 command_history::ignore_entries (! tmp); |
5794 | 865 |
866 return retval; | |
3016 | 867 } |