#include <cstdlib>
#include <cstring>
#include <string>
#include <fstream>
#include <sys/types.h>
#include <unistd.h>
#include "cmd-hist.h"
#include "file-ops.h"
#include "lo-mappers.h"
#include "oct-env.h"
#include "oct-time.h"
#include "str-vec.h"
#include <defaults.h>
#include "defun.h"
#include "error.h"
#include "gripes.h"
#include "input.h"
#include "oct-hist.h"
#include "oct-obj.h"
#include "pager.h"
#include "parse.h"
#include "sighandlers.h"
#include "sysdep.h"
#include "toplev.h"
#include "unwind-prot.h"
#include "utils.h"
#include "variables.h"
Go to the source code of this file.
Functions | |
static std::string | default_history_file (void) |
static int | default_history_size (void) |
static std::string | default_history_timestamp_format (void) |
DEFUN (history_file, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{val} =} history_file ()\n\ @deftypefnx {Built-in Function} {@var{old_val} =} history_file (@var{new_val})\n\ Query or set the internal variable that specifies the name of the\n\ file used to store command history. The default value is\n\ @file{~/.octave_hist}, but may be overridden by the environment\n\ variable @w{@env{OCTAVE_HISTFILE}}.\n\ @seealso{history_size, saving_history, history_timestamp_format_string}\n\ @end deftypefn") | |
DEFUN (run_history, args,,"-*- texinfo -*-\n\ @deftypefn {Command} {} run_history [@var{first}] [@var{last}]\n\ Similar to @code{edit_history}, except that the editor is not invoked,\n\ and the commands are simply executed as they appear in the history list.\n\ @seealso{edit_history}\n\ @end deftypefn") | |
DEFUN (history_control, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{val} =} history_control ()\n\ @deftypefnx {Built-in Function} {@var{old_val} =} history_control (@var{new_val})\n\ Query or set the internal variable that specifies how commands are saved\n\ to the history list. The default value is an empty character string,\n\ but may be overridden by the environment variable\n\ @w{@env{OCTAVE_HISTCONTROL}}.\n\ \n\ The value of @code{history_control} is a colon-separated list of values\n\ controlling how commands are saved on the history list. If the list\n\ of values includes @code{ignorespace}, lines which begin with a space\n\ character are not saved in the history list. A value of @code{ignoredups}\n\ causes lines matching the previous history entry to not be saved.\n\ A value of @code{ignoreboth} is shorthand for @code{ignorespace} and\n\ @code{ignoredups}. A value of @code{erasedups} causes all previous lines\n\ matching the current line to be removed from the history list before that\n\ line is saved. Any value not in the above list is ignored. If\n\ @code{history_control} is the empty string, all commands are saved on\n\ the history list, subject to the value of @code{saving_history}.\n\ @seealso{history_file, history_size, history_timestamp_format_string, saving_history}\n\ @end deftypefn") | |
DEFUN (history_size, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{val} =} history_size ()\n\ @deftypefnx {Built-in Function} {@var{old_val} =} history_size (@var{new_val})\n\ Query or set the internal variable that specifies how many entries\n\ to store in the history file. The default value is @code{1024},\n\ but may be overridden by the environment variable @w{@env{OCTAVE_HISTSIZE}}.\n\ @seealso{history_file, history_timestamp_format_string, saving_history}\n\ @end deftypefn") | |
DEFUN (history_timestamp_format_string, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{val} =} history_timestamp_format_string ()\n\ @deftypefnx {Built-in Function} {@var{old_val} =} history_timestamp_format_string (@var{new_val})\n\ @deftypefnx {Built-in Function} {} history_timestamp_format_string (@var{new_val}, \"local\")\n\ Query or set the internal variable that specifies the format string\n\ for the comment line that is written to the history file when Octave\n\ exits. The format string is passed to @code{strftime}. The default\n\ value is\n\ \n\ @example\n\ \"# Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>\"\n\ @end example\n\ \n\ When called from inside a function with the \"local\" option, the variable is\n\ changed locally for the function and any subroutines it calls. The original\n\ variable value is restored when exiting the function.\n\ @seealso{strftime, history_file, history_size, saving_history}\n\ @end deftypefn") | |
DEFUN (saving_history, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{val} =} saving_history ()\n\ @deftypefnx {Built-in Function} {@var{old_val} =} saving_history (@var{new_val})\n\ @deftypefnx {Built-in Function} {} saving_history (@var{new_val}, \"local\")\n\ Query or set the internal variable that controls whether commands entered\n\ on the command line are saved in the history file.\n\ \n\ When called from inside a function with the \"local\" option, the variable is\n\ changed locally for the function and any subroutines it calls. The original\n\ variable value is restored when exiting the function.\n\ @seealso{history_control, history_file, history_size, history_timestamp_format_string}\n\ @end deftypefn") | |
DEFUN (edit_history, args,,"-*- texinfo -*-\n\ @deftypefn {Command} {} edit_history [@var{first}] [@var{last}]\n\ If invoked with no arguments, @code{edit_history} allows you to edit the\n\ history list using the editor named by the variable @w{@env{EDITOR}}. The\n\ commands to be edited are first copied to a temporary file. When you\n\ exit the editor, Octave executes the commands that remain in the file.\n\ It is often more convenient to use @code{edit_history} to define functions\n\ rather than attempting to enter them directly on the command line.\n\ By default, the block of commands is executed as soon as you exit the\n\ editor. To avoid executing any commands, simply delete all the lines\n\ from the buffer before exiting the editor.\n\ \n\ The @code{edit_history} command takes two optional arguments specifying\n\ the history numbers of first and last commands to edit. For example,\n\ the command\n\ \n\ @example\n\ edit_history 13\n\ @end example\n\ \n\ @noindent\n\ extracts all the commands from the 13th through the last in the history\n\ list. The command\n\ \n\ @example\n\ edit_history 13 169\n\ @end example\n\ \n\ @noindent\n\ only extracts commands 13 through 169. Specifying a larger number for\n\ the first command than the last command reverses the list of commands\n\ before placing them in the buffer to be edited. If both arguments are\n\ omitted, the previous command in the history list is used.\n\ @seealso{run_history}\n\ @end deftypefn") | |
DEFUN (history, args,,"-*- texinfo -*-\n\ @deftypefn {Command} {} history options\n\ If invoked with no arguments, @code{history} displays a list of commands\n\ that you have executed. Valid options are:\n\ \n\ @table @code\n\ @item -w @var{file}\n\ Write the current history to the file @var{file}. If the name is\n\ omitted, use the default history file (normally @file{~/.octave_hist}).\n\ \n\ @item -r @var{file}\n\ Read the file @var{file}, appending its contents to the current\n\ history list. If the name is omitted, use the default history file\n\ (normally @file{~/.octave_hist}).\n\ \n\ @item @var{n}\n\ Display only the most recent @var{n} lines of history.\n\ \n\ @item -q\n\ Don't number the displayed lines of history. This is useful for cutting\n\ and pasting commands using the X Window System.\n\ @end table\n\ \n\ For example, to display the five most recent commands that you have\n\ typed without displaying line numbers, use the command\n\ @kbd{history -q 5}.\n\ @end deftypefn") | |
static void | do_edit_history (int argc, const string_vector &argv) |
static void | do_history (int argc, const string_vector &argv) |
static void | do_run_history (int argc, const string_vector &argv) |
static void | edit_history_add_hist (const std::string &line) |
static char * | edit_history_readline (std::fstream &stream) |
static void | edit_history_repl_hist (const std::string &command) |
void | initialize_history (bool read_history_file) |
static std::string | mk_tmp_hist_file (int argc, const string_vector &argv, int insert_curr, const char *warn_for) |
void | octave_history_write_timestamp (void) |
static void | unlink_cleanup (const char *file) |
Variables | |
bool | input_from_tmp_history_file = false |
static std::string | Vhistory_timestamp_format_string = default_history_timestamp_format () |
static std::string default_history_file | ( | void | ) | [static] |
Definition at line 75 of file oct-hist.cc.
References file_ops::concat(), octave_env::get_home_directory(), and octave_env::getenv().
Referenced by initialize_history().
static int default_history_size | ( | void | ) | [static] |
Definition at line 92 of file oct-hist.cc.
References octave_env::getenv(), and size().
Referenced by initialize_history().
static std::string default_history_timestamp_format | ( | void | ) | [static] |
Definition at line 110 of file oct-hist.cc.
References octave_env::get_host_name(), and octave_env::get_user_name().
DEFUN | ( | history_file | , | |
args | , | |||
nargout | ||||
) |
Definition at line 709 of file oct-hist.cc.
References command_history::file(), command_history::set_file(), and set_internal_variable().
DEFUN | ( | run_history | , | |
args | ||||
) |
Definition at line 628 of file oct-hist.cc.
References do_run_history(), and error_state.
DEFUN | ( | history_control | , | |
args | , | |||
nargout | ||||
) |
Definition at line 650 of file oct-hist.cc.
References command_history::histcontrol(), command_history::process_histcontrol(), and set_internal_variable().
DEFUN | ( | history_size | , | |
args | , | |||
nargout | ||||
) |
Definition at line 686 of file oct-hist.cc.
References set_internal_variable(), command_history::set_size(), and command_history::size().
DEFUN | ( | history_timestamp_format_string | , | |
args | , | |||
nargout | ||||
) |
Definition at line 733 of file oct-hist.cc.
References SET_INTERNAL_VARIABLE.
DEFUN | ( | saving_history | , | |
args | , | |||
nargout | ||||
) |
Definition at line 756 of file oct-hist.cc.
References command_history::ignore_entries(), command_history::ignoring_entries(), and set_internal_variable().
DEFUN | ( | edit_history | , | |
args | ||||
) |
Definition at line 534 of file oct-hist.cc.
References do_edit_history(), and error_state.
DEFUN | ( | history | , | |
args | ||||
) |
Definition at line 585 of file oct-hist.cc.
References do_history(), and error_state.
static void do_edit_history | ( | int | argc, | |
const string_vector & | argv | |||
) | [static] |
Definition at line 424 of file oct-hist.cc.
References unwind_protect::add_fcn(), edit_history_add_hist(), edit_history_readline(), edit_history_repl_hist(), input_from_tmp_history_file, mk_tmp_hist_file(), octave_ignore_interrupts(), octave_set_interrupt_handler(), unwind_protect::protect_var(), source_file(), unlink_cleanup(), Vecho_executing_commands, and VEDITOR.
Referenced by DEFUN().
static void do_history | ( | int | argc, | |
const string_vector & | argv | |||
) | [static] |
Definition at line 132 of file oct-hist.cc.
References unwind_protect::add_fcn(), command_history::append(), error(), command_history::file(), Array< T >::length(), command_history::list(), octave_stdout, panic_impossible, command_history::read(), command_history::read_range(), command_history::set_file(), and command_history::write().
Referenced by DEFUN().
static void do_run_history | ( | int | argc, | |
const string_vector & | argv | |||
) | [static] |
Definition at line 492 of file oct-hist.cc.
References unwind_protect::add_fcn(), input_from_tmp_history_file, mk_tmp_hist_file(), unwind_protect::protect_var(), source_file(), unlink_cleanup(), and Vecho_executing_commands.
Referenced by DEFUN().
static void edit_history_add_hist | ( | const std::string & | line | ) | [static] |
Definition at line 301 of file oct-hist.cc.
References command_history::add().
Referenced by do_edit_history().
static char* edit_history_readline | ( | std::fstream & | stream | ) | [static] |
Definition at line 214 of file oct-hist.cc.
Referenced by do_edit_history().
static void edit_history_repl_hist | ( | const std::string & | command | ) | [static] |
Definition at line 270 of file oct-hist.cc.
References command_history::get_entry(), Array< T >::length(), command_history::list(), and command_history::replace_entry().
Referenced by do_edit_history().
void initialize_history | ( | bool | read_history_file | ) |
Definition at line 515 of file oct-hist.cc.
References default_history_file(), default_history_size(), octave_env::getenv(), and command_history::initialize().
Referenced by octave_main().
static std::string mk_tmp_hist_file | ( | int | argc, | |
const string_vector & | argv, | |||
int | insert_curr, | |||
const char * | warn_for | |||
) | [static] |
Definition at line 318 of file oct-hist.cc.
References error(), Array< T >::length(), command_history::list(), octave_tempnam(), command_history::remove(), and usage().
Referenced by do_edit_history(), and do_run_history().
void octave_history_write_timestamp | ( | void | ) |
Definition at line 524 of file oct-hist.cc.
References command_history::add(), octave_base_tm::strftime(), and Vhistory_timestamp_format_string.
Referenced by do_octave_atexit().
static void unlink_cleanup | ( | const char * | file | ) | [static] |
Definition at line 418 of file oct-hist.cc.
Referenced by do_edit_history(), and do_run_history().
bool input_from_tmp_history_file = false |
Definition at line 72 of file oct-hist.cc.
Referenced by do_edit_history(), and do_run_history().
std::string Vhistory_timestamp_format_string = default_history_timestamp_format () [static] |
Definition at line 123 of file oct-hist.cc.
Referenced by octave_history_write_timestamp().