octave: Commands for History
2.4.5 Commands for Manipulating the History
-------------------------------------------
Octave normally keeps track of the commands you type so that you can
recall previous commands to edit or execute them again. When you exit
Octave, the most recent commands you have typed, up to the number
specified by the variable ‘history_size’, are saved in a file. When
Octave starts, it loads an initial list of commands from the file named
by the variable ‘history_file’.
Here are the commands for simple browsing and searching the history
list.
‘<LFD>’
‘<RET>’
Accept the current line regardless of where the cursor is. If the
line is non-empty, add it to the history list. If the line was a
history line, then restore the history line to its original state.
‘C-p’
Move ‘up’ through the history list.
‘C-n’
Move ‘down’ through the history list.
‘M-<’
Move to the first line in the history.
‘M->’
Move to the end of the input history, i.e., the line you are
entering!
‘C-r’
Search backward starting at the current line and moving ‘up’
through the history as necessary. This is an incremental search.
‘C-s’
Search forward starting at the current line and moving ‘down’
through the history as necessary.
On most terminals, you can also use the up and down arrow keys in
place of ‘C-p’ and ‘C-n’ to move through the history list.
In addition to the keyboard commands for moving through the history
list, Octave provides three functions for viewing, editing, and
re-running chunks of commands from the history list.
-- : history
-- : history OPT1 ...
-- : H = history ()
-- : H = history (OPT1, ...)
If invoked with no arguments, ‘history’ displays a list of commands
that you have executed.
Valid options are:
‘N’
‘-N’
Display only the most recent N lines of history.
‘-c’
Clear the history list.
‘-q’
Don’t number the displayed lines of history. This is useful
for cutting and pasting commands using the X Window System.
‘-r FILE’
Read the file FILE, appending its contents to the current
history list. If the name is omitted, use the default history
file (normally ‘~/.octave_hist’).
‘-w FILE’
Write the current history to the file FILE. If the name is
omitted, use the default history file (normally
‘~/.octave_hist’).
For example, to display the five most recent commands that you have
typed without displaying line numbers, use the command ‘history -q
5’.
If invoked with a single output argument, the history will be saved
to that argument as a cell string and will not be output to screen.
DONTPRINTYET See also: edit_history XREFedit_history, *noterun_history:
DONTPRINTYET See also: edit_history XREFedit_history, run_history
XREFrun_history.
-- : edit_history
-- : edit_history CMD_NUMBER
-- : edit_history FIRST LAST
Edit the history list using the editor named by the variable
‘EDITOR’.
The commands to be edited are first copied to a temporary file.
When you exit the editor, Octave executes the commands that remain
in the file. It is often more convenient to use ‘edit_history’ to
define functions rather than attempting to enter them directly on
the command line. The block of commands is executed as soon as you
exit the editor. To avoid executing any commands, simply delete
all the lines from the buffer before leaving the editor.
When invoked with no arguments, edit the previously executed
command; With one argument, edit the specified command CMD_NUMBER;
With two arguments, edit the list of commands between FIRST and
LAST. Command number specifiers may also be negative where -1
refers to the most recently executed command. The following are
equivalent and edit the most recently executed command.
edit_history
edit_history -1
When using ranges, specifying a larger number for the first command
than the last command reverses the list of commands before they are
placed in the buffer to be edited.
DONTPRINTYET See also: run_history XREFrun_history, *notehistory:
DONTPRINTYET See also: run_history XREFrun_history, history
XREFhistory.
-- : run_history
-- : run_history CMD_NUMBER
-- : run_history FIRST LAST
Run commands from the history list.
When invoked with no arguments, run the previously executed
command;
With one argument, run the specified command CMD_NUMBER;
With two arguments, run the list of commands between FIRST and
LAST. Command number specifiers may also be negative where -1
refers to the most recently executed command. For example, the
command
run_history
OR
run_history -1
executes the most recent command again. The command
run_history 13 169
executes commands 13 through 169.
Specifying a larger number for the first command than the last
command reverses the list of commands before executing them. For
example:
disp (1)
disp (2)
run_history -1 -2
⇒
2
1
DONTPRINTYET See also: edit_history XREFedit_history, *notehistory:
DONTPRINTYET See also: edit_history XREFedit_history, history
XREFhistory.
Octave also allows you customize the details of when, where, and how
history is saved.
-- : VAL = history_save ()
-- : OLD_VAL = history_save (NEW_VAL)
-- : history_save (NEW_VAL, "local")
Query or set the internal variable that controls whether commands
entered on the command line are saved in the history file.
When called from inside a function with the "local" option, the
variable is changed locally for the function and any subroutines it
calls. The original variable value is restored when exiting the
function.
DONTPRINTYET See also: history_control XREFhistory_control, *noteDONTPRINTYET DONTPRINTYET See also: history_control XREFhistory_control,
history_file XREFhistory_file, *notehistory_size:
DONTPRINTYET DONTPRINTYET DONTPRINTYET See also: history_control XREFhistory_control,
history_file XREFhistory_file, history_size
XREFhistory_size, *notehistory_timestamp_format_string:
DONTPRINTYET DONTPRINTYET DONTPRINTYET See also: history_control XREFhistory_control,
history_file XREFhistory_file, history_size
XREFhistory_size, history_timestamp_format_string
XREFhistory_timestamp_format_string.
-- : VAL = history_control ()
-- : OLD_VAL = history_control (NEW_VAL)
Query or set the internal variable that specifies how commands are
saved to the history list.
The default value is an empty character string, but may be
overridden by the environment variable ‘OCTAVE_HISTCONTROL’.
The value of ‘history_control’ is a colon-separated list of values
controlling how commands are saved on the history list. If the
list of values includes ‘ignorespace’, lines which begin with a
space character are not saved in the history list. A value of
‘ignoredups’ causes lines matching the previous history entry to
not be saved. A value of ‘ignoreboth’ is shorthand for
‘ignorespace’ and ‘ignoredups’. A value of ‘erasedups’ causes all
previous lines matching the current line to be removed from the
history list before that line is saved. Any value not in the above
list is ignored. If ‘history_control’ is the empty string, all
commands are saved on the history list, subject to the value of
‘history_save’.
DONTPRINTYET See also: history_file XREFhistory_file, *notehistory_size:
DONTPRINTYET DONTPRINTYET See also: history_file XREFhistory_file, history_size
XREFhistory_size, *notehistory_timestamp_format_string:
DONTPRINTYET DONTPRINTYET DONTPRINTYET See also: history_file XREFhistory_file, history_size
XREFhistory_size, history_timestamp_format_string
XREFhistory_timestamp_format_string, *notehistory_save:
DONTPRINTYET DONTPRINTYET DONTPRINTYET See also: history_file XREFhistory_file, history_size
XREFhistory_size, history_timestamp_format_string
XREFhistory_timestamp_format_string, history_save
XREFhistory_save.
-- : VAL = history_file ()
-- : OLD_VAL = history_file (NEW_VAL)
Query or set the internal variable that specifies the name of the
file used to store command history.
The default value is ‘~/.octave_hist’, but may be overridden by the
environment variable ‘OCTAVE_HISTFILE’.
DONTPRINTYET See also: history_size XREFhistory_size, *notehistory_save:
DONTPRINTYET DONTPRINTYET See also: history_size XREFhistory_size, history_save
XREFhistory_save, *notehistory_timestamp_format_string:
DONTPRINTYET DONTPRINTYET See also: history_size XREFhistory_size, history_save
XREFhistory_save, history_timestamp_format_string
XREFhistory_timestamp_format_string.
-- : VAL = history_size ()
-- : OLD_VAL = history_size (NEW_VAL)
Query or set the internal variable that specifies how many entries
to store in the history file.
The default value is ‘1000’, but may be overridden by the
environment variable ‘OCTAVE_HISTSIZE’.
DONTPRINTYET See also: history_file XREFhistory_file, *note history_timestamp_format_string:
XREFhistory_timestamp_format_string, history_save
XREFhistory_save.
-- : VAL = history_timestamp_format_string ()
-- : OLD_VAL = history_timestamp_format_string (NEW_VAL)
-- : history_timestamp_format_string (NEW_VAL, "local")
Query or set the internal variable that specifies the format string
for the comment line that is written to the history file when
Octave exits.
The format string is passed to ‘strftime’. The default value is
"# Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@HOST>"
When called from inside a function with the "local" option, the
variable is changed locally for the function and any subroutines it
calls. The original variable value is restored when exiting the
function.
DONTPRINTYET See also: strftime XREFstrftime, *notehistory_file:
DONTPRINTYET DONTPRINTYET See also: strftime XREFstrftime, history_file
XREFhistory_file, history_size XREFhistory_size, *noteDONTPRINTYET DONTPRINTYET See also: strftime XREFstrftime, history_file
XREFhistory_file, history_size XREFhistory_size,
history_save XREFhistory_save.
-- : VAL = EDITOR ()
-- : OLD_VAL = EDITOR (NEW_VAL)
-- : EDITOR (NEW_VAL, "local")
Query or set the internal variable that specifies the default text
editor.
The default value is taken from the environment variable ‘EDITOR’
when Octave starts. If the environment variable is not
initialized, ‘EDITOR’ will be set to "emacs".
When called from inside a function with the "local" option, the
variable is changed locally for the function and any subroutines it
calls. The original variable value is restored when exiting the
function.
DONTPRINTYET See also: edit XREFedit, *noteedit_history:
DONTPRINTYET See also: edit XREFedit, edit_history
XREFedit_history.