For Elvis, this means that edit sessions should be restartable. It is possible to begin an edit session with one Elvis process, exit that process, and then later start a new Elvis process which resumes the previous edit session.
To accomplish this, Elvis stores its state in a file, called the session file. For all practical purposes, the session file is the session.
The name of the session file is stored in the session option. By default, this will be a file in your home directory, named "elvis*.ses", where "*" represents a number chosen at run-time to make the file name unique. You can specify some other name for the session file via the -ssession command-line flag.
If the session file doesn't already exist when Elvis starts running, then Elvis will create it.
When Elvis exits, it will normally delete the session file if this is the Elvis process that created it. If the session file was left over from some other Elvis process, then Elvis will not delete it upon exiting. This is controlled by the tempsession option; if you don't like Elvis' default behavior then you can change it.
Elvis begins by initializing some options to hardcoded values.
Elvis then chooses which user interface it should use. Elvis does this by scanning the command line arguments for a -Ggui flag. If there is no such flag, then it checks for an ELVISGUI environment variable; its value is the name of the interface to use. If neither -Ggui nor ELVISGUI is present, then Elvis tests each user interface and uses the best one that is expected to work. (For example, the "x11" interface is expected to work if there is a DISPLAY environment variable and the X server is accessible. If not, then the "x11" interface is rejected and some other interface is used.)
The session file is then opened or created. For preexisting session files, Elvis scans the session file for any buffers in it, and adds them to its internal list. Elvis can even reload the "undo" versions of some buffers.
Elvis searches through the directories named in the elvispath option for a file named "elvis.ini". If it finds that file, then it loads it into a buffer named "Elvis initialization" and executes its contents as a series of ex commands. See section 10.2.1 for description of the default contents of this file.
After that, it attempts to similarly load some other files, but they aren't executed. Some of them will be executed later. These files are:
.-----------.----------------------.------------------------------. | FILE NAME | BUFFER NAME | PURPOSE | |-----------|----------------------|------------------------------| | elvis.msg | Elvis messages | used to translate messages | | elvis.brf | Elvis before reading | executed before loading file | | elvis.arf | Elvis after reading | executed after loading file | | elvis.bwf | Elvis before writing | executed before saving file | | elvis.awf | Elvis after writing | executed after saving file | ^-----------^----------------------^------------------------------^The "elvis.msg" file is described in section 11: Messages. The other files are described later in this section.
The next step in initialization is to load the first file and display it in a window. To do this, it first creates an empty buffer with the same name as the file. It then executes the "Elvis before reading" buffer (if it exists) on the empty buffer. The file's contents are then read into the buffer. Then the "Elvis after reading" buffer (if it exists) is executed on the new buffer. Finally, Elvis creates a new window that shows the new buffer.
If the -a flag was given on the command line, then Elvis will repeat the above steps for each file named on the command line. On the other hand, if no filenames were given on the command line then Elvis will simply create a single untitled buffer and a window that shows it.
Finally, if a -ttag or -cexcmd flag was given, it is executed in the first window.
" CHOOSE A LOCALE try let! locale= $LC_ALL || $LANGThis chooses a locale. This affects elvis' choice of spelling dictionaries. See the locale and spelldict options.
The "!" suffix on a :let or :set command causes the value to be stored as the new default, so :mkexrc won't have to save it with your customized settings.
" SET SOME SYSTEM DEFAULTS set! lptype=ps2 lplines=60 lpcolumns=80 lpwrap set! ruler showmatch showmodeThis sets a few other options for things like printing and window decorations. Note that for WinElvis, the default lptype is changed to "windows" later.
" DEFINE SOME DIGRAPHS if os=="msdos" || os=="os2" || (os=="win32" && gui!="windows") then source! (elvispath("elvis.pc8")) else source! (elvispath("elvis.lat"))This attempts to locate the "elvis.lat" or "elvis.pc8" file and execute it. Those files contain ex scripts, consisting of a bunch of :digraph commands that set up the digraph table appropriately for the PC-8 or Latin-1 symbol sets. The "!" at the end of the :source command name causes
:source
to silently ignore errors.
" CHOOSE SOME DEFAULT OPTION VALUES BASED ON THE INVOCATION NAME let p=tolower(basename(program)) if p == "ex" || p == "edit" then set! initialstate=ex if p == "view" then set! defaultreadonly if p == "edit" || p == "vedit" then set! novice if home == "" then let home=dirdir(program)These lines initialize certain options according to the name by which Elvis was invoked. Traditionally, invoking vi by the name "ex" causes it to start up in ex mode instead of vi mode, and "view" causes the files to be treated as readonly.
Also, if the home option is unset,
then this tries to set it to the directory containing elvis.
Generally, some OS-specific code will set home
appropriately
before we get here, so this code isn't normally needed.
" IF SPELL-CHECKING IS SUPPORTED, THEN LOAD THE DEFAULTS if feature("spell") then source! (elvispath("elvis.spe"))This initializes the spell checker, if that feature is supported in this version of elvis.
" IF ALIASES ARE SUPPORTED, THEN LOAD THE DEFAULT ALIASES if feature("alias") && security!="restricted" then source! (elvispath("elvis.ali"))This loads some standard aliases, if the alias feature is supported by this version of elvis, and elvis isn't being used as a "restricted" editor.
" SYSTEM TWEAKS GO HERE " " The Linux console can't handle colors and underlining. if gui=="termcap" then { if term=="linux" || (os=="msdos" && (term>>4)=="ansi") then set! nottyunderline if term=="linux" then set! nottyitalic }This is an attempt to work around a bug in the Linux console driver. The Linux console can't mix color attributes with the underline attribute. Also, underlining looks ugly in an MS-DOS console.
" GUI DEFAULT SETUP GOES HERE (may be overridden in .exrc file) switch gui case windows so! (elvispath("elvis.win")) case x11 so! (elvispath("elvis.x11")) case gnome so! (elvispath("elvis.gnome"))These lines set the defaults for the "windows", "x11", and "gnome" user interfaces. For "x11" and "gnome", these set up the toolbar and other features. There isn't actually an "elvis.win" file distributed with Elvis because those features are hardcoded in the Windows version of Elvis. The "!" suffix on the :so command prevents an error message when no file is found.
" SOME MAPS THAT MAKE HTML BROWSING EASIER if feature("html") && feature("autocmd") then { augroup! html au! "These lines affect the behavior of the <Space> and <Enter< keys, while in the html display mode. <Space> will move forward one page, and <Enter< will follow a hypertext link.gt; jumps forward one page au DispMapEnter html map nosave command gt; gt; au DispMapLeave html unmap command gt; " gt; follows a hypertext link au DispMapEnter html map nosave command gt; gt; au DispMapLeave html unmap command gt; augroup END }
" EXECUTE THE STANDARD CUSTOMIZATION SCRIPTS let f=(os=="unix" ? ".elvisrc" : "elvis.rc") if security != "restricted" then { if $EXINIT then eval $EXINIT else source! (exists(home/f)?home/f:home/".exrc") } if security != "restricted" && exrc && getcwd()!=home then safely source! (exists(f)?f:".exrc") set f=""These lines temporarily set the f option to either ".elvisrc" or "elvis.rc", whichever is appropriate for your operating system. They then check whether an environment variable named "EXINIT" is set to a non-empty value. If so, then the value of
EXINIT
is executed as an ex command line;
otherwise the ".elvisrc" or "elvis.rc" file in your home directory is
executed, if it exists.
If that file doesn't exist, then it tries ".exrc"... which probably only makes
sense for Unix, but it is quicker to try & fail then to test before trying.
The "~" notation is UNIX's conventional notation for referring to files in your
home directory; Elvis handles it correctly on non-UNIX systems too.
Note:
There is a hardcoded limit of (normally) 1023 characters for the result of
an expression. If your EXINIT
environment variable's value is
longer than that, Elvis won't be able to execute it.
If EXINIT or .elvisrc/elvis.rc/.exrc (whichever was executed) has set the exrc option then Elvis will execute ".elvisrc" or "elvis.rc" in the current directory, if it exists; if not, then it tries ".exrc". Elvis uses :safely source instead of :source to execute the file for security reasons.
" X11 INTERFACE DEFAULT FONTS GO HERE if gui == "x11" && alias("courier") then if font == "" then courier 14These cause the x11 interface to use 14-point courier fonts, if you don't explicitly name some other font on the command line via -font fontname, or by setting the font option in your .exrc file.
" TAKE A GUESS AT THE BUFFER'S TYPE let! readeol=fileeol(filename)This line tries to guess whether the file is binary or not. This must be done before the file is loaded because for non-binary files Elvis converts newlines to linefeeds as it reads the file.
" TAKE A GUESS AT THE BUFFER'S PREFERRED DISPLAY MODE let e=tolower(dirext(filename)) if knownsyntax(filename) then set! bufdisplay=syntax if os=="unix" && buflines >= 1 then 1s/^#! *[^ ]*\/\([^ ]\+\).*/set! bufdisplay="syntax \1"/x if !newfile then { if readeol=="binary" && bufdisplay=="normal" then set! bufdisplay=hex if e==".man" then set! bufdisplay=man if strlen(e)==2 && isnumber(e>>1) && buflines>=1 then 1s/^\./set! bufdisplay=man/x if e==".tex" then set! bufdisplay=tex if e<<4==".htm" then set! bufdisplay=html if buflines >= 1 && bufdisplay=="hex" then 1s/^<[HIThit!]/set! bufdisplay=html/x if (filename<<5=="http:" || filename<<4=="ftp:") && strlen(e)<4 && bd=="hex" then set! bufdisplay=normal if bufdisplay=="normal" && buflines >= 1 then 1s/^From .*/set! bufdisplay="syntax email"/x if dirdir(filename)=="/tmp" || dirdir(filename)=="/var/tmp" then set! bufdisplay="syntax email" }These lines try to guess the preferred display mode for the file. First it checks to see if the filename's extension is listed in the elvis.syn file; if so, then the buffer is shown in the syntax display mode. Then, for UNIX, if the first line of the file starts with "#!shell", Elvis will use the syntax display mode for that named shell. This is followed by many special cases.
" EXECUTE MODELINES, IF "modelines" OPTION IS SET if modelines && buflines >= 1 && buflines <= modelines * 2 then %s/ex:\(.*\):/\1/x if modelines && buflines > modelines * 2 then { eval 1,(modelines)s/[ev][xi]:\\\(.*\\\):/\1/x eval (buflines - modelines + 1),(buflines) s/[ev][xi]:\\\(.*\\\):/\1/x }These commands search for modelines in the newly loaded file, if the modelines option is set. The modelines are executed via the new "x" option to the :s command.
Note: The second "eval" line is split above merely as a typographical convenience. In the real "elvis.arf" file, the "eval" line and "s" line are actually a single line.
if backup && !newfile then { if os=="unix" then eval ! cp (filename) (filename).bak else eval ! copy (filename) (basename(filename)).bak >NUL }These lines copy the original version of the file to a "*.bak" file. Note that we implement separate Unix and non-Unix versions of the copy command here.
There is no default "elvis.awf" file, because I haven't found any need for one yet.
Only one Elvis process at a time is allowed to use a given session file. To enforce this, when Elvis starts up it sets an "in use" flag in the session file's header. Any later Elvis process will test that flag, and refuse to use a session file which is already in use.
When Elvis crashes, it leaves the "in use" flag set, even though the
process that was using it has died.
You must restart your edit session via "elvis -r
".
The -r
flag tells Elvis to ignore the "in use" flag.
If you aren't using the default session file, then you'll need to add a
"-f sessionfile
" flag to tell Elvis which session file it
should recover from.
If you always use the default session file, and allow several old files
to accumulate after crashes, then "elvis -r
" will always
recover from the lowest-numbered one.
The command "elvis -r -Gquit
" will tell you its name.
If you prefer to recover from a different session file,
you can either delete the lower-numbered session files, or
use the "-f sessionfile
" flag to make Elvis use a different
one.
When this new Elvis process starts up, it will be displaying a new, empty buffer. Don't panic! Your edit buffers are still intact; they just don't happen to be displayed in the initial window. You can use the ":buffer" command to list the buffers.
After a crash, the session file might not be entirely self-consistent.
Because of this, it is dangerous to edit the file using this session file.
You should save your old buffer to a file immediately,
and then exit Elvis.
To save your old buffer give Elvis the command
":(
buffer)w
filename"
where buffer is the name of your buffer
(usually the same as the original file name) and
filename is the name of a new file where you wish to store the text.
Note that the buffer name should be in parentheses!
And for safety's sake, you should not write the salvaged buffer out over the top
of the original text file.
Under normal circumstances Elvis automatically deletes the session file
when it exits, but when recovering after a crash Elvis is more cautious.
It never deletes a recovered session file itself.
After recovering your text and exiting Elvis, you should manually delete the
session file via
"rm /var/tmp/elvis*.ses
", or whatever the session file's name
is.
For DOS/Windows users, the command would be "DEL \TEMP\ELVIS-2.2_0
".
If you can figure out how to reproduce the problem, please let me know! My email address is
kirkenda@cs.pdx.eduelvis*.html
files.
ElvisN, ElvisB,
and ElvisI
as 12-point monospaced fonts
to be used for normal text, bold text, and italic text, respectively.
Similarly, it defines ElvisPN, ElvisPB,
and ElvisPI
as 12-point proportional fonts.
It also defines ElvisPage, ElvisLeftPage,
and ElvisRightPage
procedures for setting the size and position of a page's text on the paper.
If this file doesn't exist or is unreadable, Elvis will use the following
definitions:
/ElvisN /Courier findfont 12 scalefont def /ElvisB /Courier-Bold findfont 12 scalefont def /ElvisI /Courier-Oblique findfont 12 scalefont def /ElvisPN /Times-Roman findfont 12 scalefont def /ElvisPB /Times-Bold findfont 12 scalefont def /ElvisPI /Times-Italic findfont 12 scalefont def /ElvisPage { 12 36 translate } def /ElvisPage { 12 36 translate } def /ElvisLeftPage { 12 750 translate -90 rotate 0.58 0.75 scale } def /ElvisRightPage { newpath 12 394 moveto 576 0 rlineto stroke 12 366 translate -90 rotate 0.58 0.75 scale } def