GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
oct-hist.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1993-2023 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 /*
27 
28 The functions listed below were adapted from similar functions from
29 GNU Bash, the Bourne Again SHell, copyright (C) 1987, 1989, 1991 Free
30 Software Foundation, Inc.
31 
32  do_history edit_history_readline
33  do_edit_history edit_history_add_hist
34 
35 */
36 
37 #if defined (HAVE_CONFIG_H)
38 # include "config.h"
39 #endif
40 
41 #include <cstdlib>
42 #include <cstring>
43 
44 #include <fstream>
45 #include <string>
46 
47 #include "cmd-hist.h"
48 #include "file-ops.h"
49 #include "lo-mappers.h"
50 #include "lo-sysdep.h"
51 #include "oct-env.h"
52 #include "oct-time.h"
53 #include "str-vec.h"
54 #include "unistd-wrappers.h"
55 
56 #include "defun.h"
57 #include "error.h"
58 #include "errwarn.h"
59 #include "event-manager.h"
60 #include "input.h"
61 #include "oct-hist.h"
62 #include "ovl.h"
63 #include "pager.h"
64 #include "parse.h"
65 #include "sighandlers.h"
66 #include "sysdep.h"
67 #include "interpreter.h"
68 #include "interpreter-private.h"
69 #include "unwind-prot.h"
70 #include "utils.h"
71 #include "variables.h"
72 
74 
75 // Read the edited history lines from STREAM and return them
76 // one at a time. This can read unlimited length lines. The
77 // caller should free the storage.
78 
79 static char *
81 {
82  char c;
83  int line_len = 128;
84  int lindex = 0;
85  char *line = new char [line_len];
86  line[0] = '\0';
87 
88  while (stream.get (c))
89  {
90  if (lindex + 2 >= line_len)
91  {
92  char *tmp_line = new char [line_len += 128];
93  strcpy (tmp_line, line);
94  delete [] line;
95  line = tmp_line;
96  }
97 
98  if (c == '\n')
99  {
100  line[lindex++] = '\n';
101  line[lindex++] = '\0';
102  return line;
103  }
104  else
105  line[lindex++] = c;
106  }
107 
108  if (! lindex)
109  {
110  delete [] line;
111  return nullptr;
112  }
113 
114  if (lindex + 2 >= line_len)
115  {
116  char *tmp_line = new char [lindex+3];
117  strcpy (tmp_line, line);
118  delete [] line;
119  line = tmp_line;
120  }
121 
122  // Finish with newline if none in file.
123 
124  line[lindex++] = '\n';
125  line[lindex++] = '\0';
126  return line;
127 }
128 
129 static void
130 edit_history_add_hist (const std::string& line)
131 {
132  if (! line.empty ())
133  {
134  std::string tmp = line;
135 
136  int len = tmp.length ();
137 
138  if (len > 0 && tmp[len-1] == '\n')
139  tmp.resize (len - 1);
140 
141  if (! tmp.empty ())
142  {
143  if (command_history::add (tmp))
144  {
146 
147  evmgr.append_history (tmp);
148  }
149  }
150  }
151 }
152 
153 static bool
154 get_int_arg (const octave_value& arg, int& val)
155 {
156  bool ok = true;
157 
158  if (arg.is_string ())
159  {
160  std::string tmp = arg.string_value ();
161 
162  ok = sscanf (tmp.c_str (), "%d", &val) == 1;
163  }
164  else if (arg.isnumeric ())
165  val = arg.int_value ();
166  else
167  ok = false;
168 
169  return ok;
170 }
171 
172 static std::string
174  bool insert_curr, const char *warn_for)
175 {
177 
178  int hist_count = hlist.numel () - 1; // switch to zero-based indexing
179 
180  // The current command line is already part of the history list by
181  // the time we get to this point. Delete the cmd from the list when
182  // executing 'edit_history' so that it doesn't show up in the history
183  // but the actual commands performed will.
184 
185  if (! insert_curr)
186  command_history::remove (hist_count);
187 
188  hist_count--; // skip last entry in history list
189 
190  // If no numbers have been specified, the default is to edit the
191  // last command in the history list.
192 
193  int hist_beg = hist_count;
194  int hist_end = hist_count;
195 
196  bool reverse = false;
197 
198  // Process options.
199 
200  int nargin = args.length ();
201 
202  if (nargin == 2)
203  {
204  if (! get_int_arg (args(0), hist_beg)
205  || ! get_int_arg (args(1), hist_end))
206  error ("%s: arguments must be integers", warn_for);
207 
208  if (hist_beg < 0)
209  hist_beg += (hist_count + 1);
210  else
211  hist_beg--;
212  if (hist_end < 0)
213  hist_end += (hist_count + 1);
214  else
215  hist_end--;
216  }
217  else if (nargin == 1)
218  {
219  if (! get_int_arg (args(0), hist_beg))
220  error ("%s: argument must be an integer", warn_for);
221 
222  if (hist_beg < 0)
223  hist_beg += (hist_count + 1);
224  else
225  hist_beg--;
226 
227  hist_end = hist_beg;
228  }
229 
230  if (hist_beg > hist_count || hist_end > hist_count)
231  error ("%s: history specification out of range", warn_for);
232 
233  if (hist_end < hist_beg)
234  {
235  std::swap (hist_end, hist_beg);
236  reverse = true;
237  }
238 
239  std::string name = sys::tempnam ("", "oct-");
240 
241  std::ofstream file = sys::ofstream (name.c_str (), std::ios::out);
242 
243  if (! file)
244  error ("%s: couldn't open temporary file '%s'", warn_for,
245  name.c_str ());
246 
247  if (reverse)
248  {
249  for (int i = hist_end; i >= hist_beg; i--)
250  file << hlist[i] << "\n";
251  }
252  else
253  {
254  for (int i = hist_beg; i <= hist_end; i++)
255  file << hlist[i] << "\n";
256  }
257 
258  file.close ();
259 
260  return name;
261 }
262 
264  : m_interpreter (interp), m_input_from_tmp_file (false),
265  m_timestamp_format_string (default_timestamp_format ())
266 { }
267 
268 void history_system::initialize (bool read_history_file)
269 {
270  command_history::initialize (read_history_file, default_file (),
271  default_size (),
272  sys::env::getenv ("OCTAVE_HISTCONTROL"));
273 
275 
277 }
278 
280 {
281  sys::localtime now;
282 
283  std::string timestamp = now.strftime (m_timestamp_format_string);
284 
285  if (! timestamp.empty ())
286  {
287  if (command_history::add (timestamp))
288  {
290 
291  evmgr.append_history (timestamp);
292  }
293  }
294 }
295 
298  int nargout)
299 {
300  return set_internal_variable (m_input_from_tmp_file, args, nargout,
301  "input_from_tmp_file");
302 }
303 
306  int nargout)
307 {
308  return set_internal_variable (m_timestamp_format_string, args, nargout,
309  "timestamp_format_string");
310 }
311 
312 // Display, save, or load history. Stolen and modified from bash.
313 //
314 // Arg of -w FILENAME means write file, arg of -r FILENAME
315 // means read file, arg of -q means don't number lines. Arg of N
316 // means only display that many items.
317 
319  int nargout)
320 {
321  bool numbered_output = nargout == 0;
322 
323  unwind_action restore_history_filename
324  ([] (const std::string& old_filename)
325  {
326  command_history::set_file (old_filename);
327  }, command_history::file ());
328 
329  string_vector hlist;
330 
331  int nargin = args.length ();
332 
333  // Number of history lines to show (-1 = all)
334  int limit = -1;
335 
336  for (octave_idx_type i = 0; i < nargin; i++)
337  {
338  octave_value arg = args(i);
339 
340  std::string option;
341 
342  if (arg.is_string ())
343  option = arg.string_value ();
344  else if (arg.isnumeric ())
345  {
346  limit = arg.int_value ();
347  if (limit < 0)
348  limit = -limit;
349  continue;
350  }
351  else
352  err_wrong_type_arg ("history", arg);
353 
355 
356  if (option == "-r" || option == "-w" || option == "-a"
357  || option == "-n")
358  {
359  if (i < nargin - 1)
360  {
361  std::string fname
362  = args(++i).xstring_value ("history: filename must be a string for %s option",
363  option.c_str ());
364 
366  }
367  else
369 
370  if (option == "-a")
371  // Append 'new' lines to file.
373 
374  else if (option == "-w")
375  // Write entire history.
377 
378  else if (option == "-r")
379  {
380  // Read entire file.
383  }
384 
385  else if (option == "-n")
386  {
387  // Read 'new' history from file.
390  }
391 
392  else
393  panic_impossible ();
394 
395  return hlist;
396  }
397  else if (option == "-c")
398  {
400  evmgr.clear_history ();
401  }
402  else if (option == "-q")
403  numbered_output = false;
404  else if (option == "--")
405  {
406  i++;
407  break;
408  }
409  else
410  {
411  // The last argument found in the command list that looks like
412  // an integer will be used
413  int tmp;
414 
415  if (sscanf (option.c_str (), "%d", &tmp) == 1)
416  {
417  if (tmp > 0)
418  limit = tmp;
419  else
420  limit = -tmp;
421  }
422 
423  else
424  {
425  if (option.length () > 0 && option[0] == '-')
426  error ("history: unrecognized option '%s'", option.c_str ());
427  else
428  error ("history: bad non-numeric arg '%s'", option.c_str ());
429  }
430  }
431  }
432 
433  hlist = command_history::list (limit, numbered_output);
434 
435  int len = hlist.numel ();
436 
437  if (nargout == 0)
438  {
439  for (octave_idx_type i = 0; i < len; i++)
440  octave_stdout << hlist[i] << "\n";
441  }
442 
443  return hlist;
444 }
445 
447 {
448  std::string name = mk_tmp_hist_file (args, false, "edit_history");
449 
450  if (name.empty ())
451  return;
452 
453  // Call up our favorite editor on the file of commands.
454 
456  std::string cmd = env.editor ();
457  cmd.append (R"( ")" + name + '"');
458 
459  // Ignore interrupts while we are off editing commands. Should we
460  // maybe avoid using system()?
461 
462  volatile interrupt_handler old_interrupt_handler
463  = ignore_interrupts ();
464 
465  int status = sys::system (cmd);
466 
467  set_interrupt_handler (old_interrupt_handler);
468 
469  // Check if text edition was successful. Abort the operation
470  // in case of failure.
471  if (status != EXIT_SUCCESS)
472  error ("edit_history: text editor command failed");
473 
474  // Write the commands to the history file since source_file
475  // disables command line history while it executes.
476 
477  std::fstream file = sys::fstream (name.c_str (), std::ios::in);
478 
479  char *line;
480  //int first = 1;
481  while ((line = edit_history_readline (file)) != nullptr)
482  {
483  // Skip blank lines.
484 
485  if (line[0] == '\n')
486  {
487  delete [] line;
488  continue;
489  }
490 
491  edit_history_add_hist (line);
492 
493  delete [] line;
494  }
495 
496  file.close ();
497 
498  int(*unlink_fptr)(const std::string&) = sys::unlink;
499  unwind_action unlink_action (unlink_fptr, name);
501 
502  // FIXME: instead of sourcing a file, we should just iterate through
503  // the list of commands, parsing and executing them one at a time as
504  // if they were entered interactively.
505 
506  source_file (name);
507 }
508 
510 {
511  std::string name = mk_tmp_hist_file (args, false, "run_history");
512 
513  if (name.empty ())
514  return;
515 
516  int(*unlink_fptr)(const std::string&) = sys::unlink;
517  unwind_action unlink_action (unlink_fptr, name);
519 
520  // FIXME: instead of sourcing a file, we should just iterate through
521  // the list of commands, parsing and executing them one at a time as
522  // if they were entered interactively.
523 
524  source_file (name);
525 }
526 
528 {
529  std::string file;
530 
531  std::string env_file = sys::env::getenv ("OCTAVE_HISTFILE");
532 
533  if (! env_file.empty ())
534  file = env_file;
535 
536  if (file.empty ())
537  {
538  // Default to $DATA/octave/history, where $DATA is the platform-
539  // dependent location for (roaming) user data files.
540 
541  std::string user_data_dir = sys::env::get_user_data_directory ();
542 
543  std::string hist_dir = user_data_dir + sys::file_ops::dir_sep_str ()
544  + "octave";
545 
546  file = sys::env::make_absolute ("history", hist_dir);
547  }
548 
549 
550  return file;
551 }
552 
554 {
555  int size = 1000;
556 
557  std::string env_size = sys::env::getenv ("OCTAVE_HISTSIZE");
558 
559  if (! env_size.empty ())
560  {
561  int val;
562 
563  if (sscanf (env_size.c_str (), "%d", &val) == 1)
564  size = (val > 0 ? val : 0);
565  }
566 
567  return size;
568 }
569 
571 {
572  return
573  "# Octave " OCTAVE_VERSION ", %a %b %d %H:%M:%S %Y %Z <"
574  + sys::env::get_user_name ()
575  + '@'
576  + sys::env::get_host_name ()
577  + '>';
578 }
579 
580 DEFMETHOD (edit_history, interp, args, ,
581  doc: /* -*- texinfo -*-
582 @deftypefn {} {} edit_history
583 @deftypefnx {} {} edit_history @var{cmd_number}
584 @deftypefnx {} {} edit_history @var{first} @var{last}
585 Edit the history list using the editor named by the variable @env{EDITOR}.
586 
587 The commands to be edited are first copied to a temporary file. When you
588 exit the editor, Octave executes the commands that remain in the file. It
589 is often more convenient to use @code{edit_history} to define functions
590 rather than attempting to enter them directly on the command line.
591 The block of commands is executed as soon as you exit the editor.
592 To avoid executing any commands, simply delete all the lines from the buffer
593 before leaving the editor.
594 
595 When invoked with no arguments, edit the previously executed command;
596 With one argument, edit the specified command @var{cmd_number};
597 With two arguments, edit the list of commands between @var{first} and
598 @var{last}. Command number specifiers may also be negative where -1
599 refers to the most recently executed command.
600 The following are equivalent and edit the most recently executed command.
601 
602 @example
603 @group
604 edit_history
605 edit_history -1
606 @end group
607 @end example
608 
609 When using ranges, specifying a larger number for the first command than the
610 last command reverses the list of commands before they are placed in the
611 buffer to be edited.
612 @seealso{run_history, history}
613 @end deftypefn */)
614 {
615  // FIXME: should this be limited to the top-level context?
616  if (args.length () > 2)
617  print_usage ();
618 
619  history_system& history_sys = interp.get_history_system ();
620 
621  history_sys.do_edit_history (args);
622 
623  return ovl ();
624 }
625 
626 DEFMETHOD (history, interp, args, nargout,
627  doc: /* -*- texinfo -*-
628 @deftypefn {} {} history
629 @deftypefnx {} {} history @var{opt1} @dots{}
630 @deftypefnx {} {@var{H} =} history ()
631 @deftypefnx {} {@var{H} =} history (@var{opt1}, @dots{})
632 If invoked with no arguments, @code{history} displays a list of commands
633 that you have executed.
634 
635 Valid options are:
636 
637 @table @code
638 @item @var{n}
639 @itemx -@var{n}
640 Display only the most recent @var{n} lines of history.
641 
642 @item -c
643 Clear the history list.
644 
645 @item -q
646 Don't number the displayed lines of history. This is useful for cutting
647 and pasting commands using the X Window System.
648 
649 @item -r @var{file}
650 Read the file @var{file}, appending its contents to the current
651 history list. If the name is omitted, use the default history file
652 (normally @file{~/.octave_hist}).
653 
654 @item -w @var{file}
655 Write the current history to the file @var{file}. If the name is
656 omitted, use the default history file (normally @file{~/.octave_hist}).
657 @end table
658 
659 For example, to display the five most recent commands that you have
660 typed without displaying line numbers, use the command
661 @kbd{history -q 5}.
662 
663 If invoked with a single output argument, the history will be saved to that
664 argument as a cell string and will not be output to screen.
665 @seealso{edit_history, run_history}
666 @end deftypefn */)
667 {
668  // FIXME: should this be limited to the top-level context?
669 
670  history_system& history_sys = interp.get_history_system ();
671 
672  // Call do_history even if nargout is zero to display history list.
673 
674  string_vector hlist = history_sys.do_history (args, nargout);
675 
676  return nargout > 0 ? ovl (Cell (hlist)) : ovl ();
677 }
678 
679 DEFMETHOD (run_history, interp, args, ,
680  doc: /* -*- texinfo -*-
681 @deftypefn {} {} run_history
682 @deftypefnx {} {} run_history @var{cmd_number}
683 @deftypefnx {} {} run_history @var{first} @var{last}
684 Run commands from the history list.
685 
686 When invoked with no arguments, run the previously executed command;
687 
688 With one argument, run the specified command @var{cmd_number};
689 
690 With two arguments, run the list of commands between @var{first} and
691 @var{last}. Command number specifiers may also be negative where -1
692 refers to the most recently executed command. For example, the command
693 
694 @example
695 @group
696 run_history
697  OR
698 run_history -1
699 @end group
700 @end example
701 
702 @noindent
703 executes the most recent command again.
704 The command
705 
706 @example
707 run_history 13 169
708 @end example
709 
710 @noindent
711 executes commands 13 through 169.
712 
713 Specifying a larger number for the first command than the last command
714 reverses the list of commands before executing them.
715 For example:
716 
717 @example
718 @group
719 disp (1)
720 disp (2)
721 run_history -1 -2
722 @result{}
723  2
724  1
725 @end group
726 @end example
727 
728 @seealso{edit_history, history}
729 @end deftypefn */)
730 {
731  // FIXME: should this be limited to the top-level context?
732 
733  history_system& history_sys = interp.get_history_system ();
734 
735  if (args.length () > 2)
736  print_usage ();
737 
738  history_sys.do_run_history (args);
739 
740  return ovl ();
741 }
742 
743 DEFUN (history_control, args, nargout,
744  doc: /* -*- texinfo -*-
745 @deftypefn {} {@var{val} =} history_control ()
746 @deftypefnx {} {@var{old_val} =} history_control (@var{new_val})
747 Query or set the internal variable that specifies how commands are saved
748 to the history list.
749 
750 The default value is an empty character string, but may be overridden by the
751 environment variable @w{@env{OCTAVE_HISTCONTROL}}.
752 
753 The value of @code{history_control} is a colon-separated list of values
754 controlling how commands are saved on the history list. If the list
755 of values includes @code{ignorespace}, lines which begin with a space
756 character are not saved in the history list. A value of @code{ignoredups}
757 causes lines matching the previous history entry to not be saved.
758 A value of @code{ignoreboth} is shorthand for @code{ignorespace} and
759 @code{ignoredups}. A value of @code{erasedups} causes all previous lines
760 matching the current line to be removed from the history list before that
761 line is saved. Any value not in the above list is ignored. If
762 @code{history_control} is the empty string, all commands are saved on
763 the history list, subject to the value of @code{history_save}.
764 @seealso{history_file, history_size, history_timestamp_format_string,
765 history_save}
766 @end deftypefn */)
767 {
768  octave_value retval;
769 
770  std::string old_history_control = command_history::histcontrol ();
771 
772  std::string tmp = old_history_control;
773 
774  retval = set_internal_variable (tmp, args, nargout, "history_control");
775 
776  if (tmp != old_history_control)
778 
779  return retval;
780 }
781 
782 DEFUN (history_size, args, nargout,
783  doc: /* -*- texinfo -*-
784 @deftypefn {} {@var{val} =} history_size ()
785 @deftypefnx {} {@var{old_val} =} history_size (@var{new_val})
786 Query or set the internal variable that specifies how many entries
787 to store in the history file.
788 
789 The default value is @code{1000}, but may be overridden by the environment
790 variable @w{@env{OCTAVE_HISTSIZE}}.
791 @seealso{history_file, history_timestamp_format_string, history_save}
792 @end deftypefn */)
793 {
794  octave_value retval;
795 
796  int old_history_size = command_history::size ();
797 
798  int tmp = old_history_size;
799 
800  retval = set_internal_variable (tmp, args, nargout,
801  "history_size", -1,
803 
804  if (tmp != old_history_size)
806 
807  return retval;
808 }
809 
810 DEFUN (history_file, args, nargout,
811  doc: /* -*- texinfo -*-
812 @deftypefn {} {@var{val} =} history_file ()
813 @deftypefnx {} {@var{old_val} =} history_file (@var{new_val})
814 Query or set the internal variable that specifies the name of the file used to
815 store command history.
816 
817 All future commands issued during the current Octave session will be written to
818 this new file (if the current setting of @code{history_save} allows for this).
819 
820 The default value is @file{@w{@env{$DATA}}/octave/history}, where
821 @w{@env{$DATA}} is the platform-specific location for (roaming) user data files
822 (e.g., @w{@env{$XDG_DATA_HOME}} or, if that is not set, @file{~/.local/share}
823 on Unix-like operating systems or @w{@env{%APPDATA%}} on Windows). The default
824 value may be overridden by the environment variable @w{@env{OCTAVE_HISTFILE}}.
825 
826 Programming Notes:
827 
828 If you want to permanently change the location of Octave's history file you
829 need to issue the @code{history_file} command in every new Octave session.
830 This can be achieved by using Octave's @file{.octaverc} startup file.
831 
832 If you also want to read the saved history commands of past Octave sessions
833 from this different history file, then you need to use the additional command
834 @code{history -r} after setting the new value of the history file. Example
835 code in Octave's startup file to do this might look like this:
836 
837 @example
838 @group
839 history_file ("~/new/.octave_hist");
840 if (exist (history_file ()))
841  history ("-r", history_file());
842 endif
843 @end group
844 @end example
845 
846 @seealso{history, history_control, history_save, history_size,
847 history_timestamp_format_string}
848 @end deftypefn */)
849 {
850  octave_value retval;
851 
852  std::string old_history_file = command_history::file ();
853 
854  std::string tmp = old_history_file;
855 
856  retval = set_internal_variable (tmp, args, nargout, "history_file");
857 
858  if (tmp != old_history_file)
860 
861  return retval;
862 }
863 
864 DEFMETHOD (history_timestamp_format_string, interp, args, nargout,
865  doc: /* -*- texinfo -*-
866 @deftypefn {} {@var{val} =} history_timestamp_format_string ()
867 @deftypefnx {} {@var{old_val} =} history_timestamp_format_string (@var{new_val})
868 @deftypefnx {} {@var{old_val} =} history_timestamp_format_string (@var{new_val}, "local")
869 Query or set the internal variable that specifies the format string
870 for the comment line that is written to the history file when Octave
871 exits.
872 
873 The format string is passed to @code{strftime}. The default value is
874 
875 @example
876 "# Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>"
877 @end example
878 
879 When called from inside a function with the @qcode{"local"} option, the
880 variable is changed locally for the function and any subroutines it calls.
881 The original variable value is restored when exiting the function.
882 @seealso{strftime, history_file, history_size, history_save}
883 @end deftypefn */)
884 {
885  history_system& history_sys = interp.get_history_system ();
886 
887  return history_sys.timestamp_format_string (args, nargout);
888 }
889 
890 /*
891 %!test
892 %! history_timestamp_format_string ("# Example history marker", "local");
893 %! assert (history_timestamp_format_string (), "# Example history marker")
894 %!test <*57843>
895 %! history_timestamp_format_string ("", "local");
896 %! assert (history_timestamp_format_string (), "")
897 */
898 
899 DEFUN (history_save, args, nargout,
900  doc: /* -*- texinfo -*-
901 @deftypefn {} {@var{val} =} history_save ()
902 @deftypefnx {} {@var{old_val} =} history_save (@var{new_val})
903 @deftypefnx {} {@var{old_val} =} history_save (@var{new_val}, "local")
904 Query or set the internal variable that controls whether commands entered
905 on the command line are saved in the history file.
906 
907 When called from inside a function with the @qcode{"local"} option, the
908 variable is changed locally for the function and any subroutines it calls.
909 The original variable value is restored when exiting the function.
910 @seealso{history_control, history_file, history_size,
911 history_timestamp_format_string}
912 @end deftypefn */)
913 {
914  octave_value retval;
915 
916  bool old_history_save = ! command_history::ignoring_entries ();
917 
918  bool tmp = old_history_save;
919 
920  retval = set_internal_variable (tmp, args, nargout, "history_save");
921 
922  if (tmp != old_history_save)
924 
925  return retval;
926 }
927 
OCTAVE_END_NAMESPACE(octave)
charNDArray max(char d, const charNDArray &m)
Definition: chNDArray.cc:230
Definition: Cell.h:43
static void read(bool=true)
Definition: cmd-hist.cc:702
static void initialize(bool, const std::string &, int, const std::string &)
Definition: cmd-hist.cc:545
static void append(const std::string &="")
Definition: cmd-hist.cc:736
static void set_file(const std::string &)
Definition: cmd-hist.cc:562
static void clear(void)
Definition: cmd-hist.cc:633
static bool add(const std::string &)
Definition: cmd-hist.cc:618
static void set_size(int)
Definition: cmd-hist.cc:592
static void remove(int)
Definition: cmd-hist.cc:626
static bool ignoring_entries(void)
Definition: cmd-hist.cc:612
static int size(void)
Definition: cmd-hist.cc:599
static void ignore_entries(bool=true)
Definition: cmd-hist.cc:605
static void process_histcontrol(const std::string &)
Definition: cmd-hist.cc:579
static std::string file(void)
Definition: cmd-hist.cc:573
static std::string histcontrol(void)
Definition: cmd-hist.cc:586
static void read_range(int=-1, int=-1, bool=true)
Definition: cmd-hist.cc:715
static string_vector list(int=-1, bool=false)
Definition: cmd-hist.cc:750
static void write(const std::string &="")
Definition: cmd-hist.cc:729
Definition: oct-env.h:40
Provides threadsafe access to octave.
void append_history(const std::string &hist_entry)
void clear_history(void)
OCTINTERP_API void set_history(void)
void do_edit_history(const octave_value_list &args=octave_value_list())
Definition: oct-hist.cc:446
bool input_from_tmp_file(void) const
Definition: oct-hist.h:60
history_system(interpreter &interp)
Definition: oct-hist.cc:263
void do_run_history(const octave_value_list &args=octave_value_list())
Definition: oct-hist.cc:509
octave_value timestamp_format_string(const octave_value_list &args, int nargout)
Definition: oct-hist.cc:305
void initialize(bool read_history_file=false)
Definition: oct-hist.cc:268
bool m_input_from_tmp_file
Definition: oct-hist.h:96
static std::string default_timestamp_format(void)
Definition: oct-hist.cc:570
std::string timestamp_format_string(void) const
Definition: oct-hist.h:73
interpreter & m_interpreter
Definition: oct-hist.h:93
std::string m_timestamp_format_string
Definition: oct-hist.h:100
static int default_size(void)
Definition: oct-hist.cc:553
static std::string default_file(void)
Definition: oct-hist.cc:527
string_vector do_history(const octave_value_list &args=octave_value_list(), int nargout=0)
Definition: oct-hist.cc:318
void write_timestamp(void)
Definition: oct-hist.cc:279
event_manager & get_event_manager(void)
Definition: interpreter.h:328
environment & get_environment(void)
Definition: interpreter.h:241
octave_idx_type length(void) const
Definition: ovl.h:113
int int_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.h:857
bool isnumeric(void) const
Definition: ov.h:795
bool is_string(void) const
Definition: ov.h:682
std::string string_value(bool force=false) const
Definition: ov.h:1019
octave_idx_type numel(void) const
Definition: str-vec.h:100
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTINTERP_API void print_usage(void)
Definition: defun-int.h:72
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
Definition: defun.h:111
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition: defun.h:56
void error(const char *fmt,...)
Definition: error.cc:979
#define panic_impossible()
Definition: error.h:508
void err_wrong_type_arg(const char *name, const char *s)
Definition: errwarn.cc:166
int unlink(const std::string &name)
Definition: file-ops.cc:677
std::string tempnam(const std::string &dir, const std::string &pfx)
Definition: file-ops.cc:697
std::string dir_sep_str(void)
Definition: file-ops.cc:240
event_manager & __get_event_manager__(void)
int system(const std::string &cmd_str)
Definition: lo-sysdep.cc:59
std::fstream fstream(const std::string &filename, const std::ios::openmode mode)
Definition: lo-sysdep.cc:410
std::ofstream ofstream(const std::string &filename, const std::ios::openmode mode)
Definition: lo-sysdep.cc:438
#define OCTAVE_VERSION
Definition: main.in.cc:63
static char * edit_history_readline(std::fstream &stream)
Definition: oct-hist.cc:80
static void edit_history_add_hist(const std::string &line)
Definition: oct-hist.cc:130
static std::string mk_tmp_hist_file(const octave_value_list &args, bool insert_curr, const char *warn_for)
Definition: oct-hist.cc:173
static bool get_int_arg(const octave_value &arg, int &val)
Definition: oct-hist.cc:154
void source_file(const std::string &file_name, const std::string &context, bool verbose, bool require_file)
Definition: oct-parse.cc:10319
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:211
#define octave_stdout
Definition: pager.h:314
interrupt_handler set_interrupt_handler(const volatile interrupt_handler &h, bool restart_syscalls)
Definition: sighandlers.cc:348
interrupt_handler ignore_interrupts(void)
Definition: sighandlers.cc:337
static string_vector make_absolute(const string_vector &sv)
Definition: utils.cc:536
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)
Definition: variables.cc:584
F77_RET_T len
Definition: xerbla.cc:61