Did you know ... Search Documentation:
Pack genutils -- prolog/rcutils.pl
PublicShow source

This module provides confirm_on_halt/0, to make it harder to exit Prolog unintentionally due to over-enthusiastic Ctrl-D pressing, persistent_history/2, to keep and periodically save the current command line history to an arbitrary file, and defines the file_search_path/2 location 'home', which maps to the expand_file_name/2 expansion of '~'.

You might find it useful to put this in your .plrc/.swiplrc, eg

:- if(exists_source(library(rcutils))) :- use_module(library(rcutils)). :- persistent_history('.swipl.history',[interval(300)]). :- confirm_on_halt. :- endif. ===

 confirm_on_halt is det
Installs confirm_halt/0 as a hook to be called before exitting Prolog.
 persistent_history(+File:text, +Opts:options) is det
This disables SWIs built-in persistent command line history mechanism if it is enabled and replaces it with one that saves the history in an arbitrary file. This can be useful if the history file is in a directory that is kept synchronised among many computers, stored, or backed up in some other way. This history includes comment lines that give show the command line arguments given to swipl each time it is started.

If called during SWI Prolog initialisation (ie in the ~/.swiplrc file, in a command line -g goal, or in a program loaded with -s on the command line) then the line editor and history mechanisms will not have been initialised yet, so you must load whichever line editor library you like (readline or editline) first.

Valid options are:

interval(+Interval:number)
If supplied, the history is saved every Interval seconds. Otherwise, the history is only saved when Prolog exits (using at_halt/1).

For example, the author finds it useful to add the following to his ~/.swiplrc:

:- use_module(library(hostname)).
persistent_history :-
   hostname(Hostname),
   atom_concat('.swipl_history.',Hostname,HistFile),
   load_files(library(readline), [if(not_loaded)]),
   set_prolog_flag(readline, readline), % work around bug in readline foreign library
   persistent_history(HistFile,[interval(60)]).

This means that any program can call persistent_history/0 to get a host specific history file, which is useful when a directory is shared or synchronised across several machines.