     START-INFO-DIR-ENTRY * ProofGeneral::Organize your proofs with Emacs!
     END-INFO-DIR-ENTRY

Proof General
*************

This file documents version 2.0 of Proof General, a generic Emacs interface for proof assistants.

Proof General 2.0 has been tested with XEmacs 20.4 and FSF GNU Emacs 20.2.  It is supplied ready customized for the proof assistants Coq, Lego, and Isabelle.

Introducing Proof General
*************************

A proof assistant is a computerized helper for developing mathematical proofs.

Proof General is a generic Emacs interface for proof assistants, developed at the LFCS in the University of Edinburgh.  It works best under XEmacs, but can also be used with FSF GNU Emacs.

You do not have to be an Emacs militant to use Proof General!

The interface is designed to be very easy to use.  You develop your proof script in-place rather than line-by-line and later reassembling the pieces.  Proof General keeps track of which proof steps have been processed by the prover, and prevents you editing them accidently.  You can undo steps as usual.

The main aim of Proof General is to provide a powerful and configurable Emacs mode to help user-interaction with numerous interactive proof assistants.  Please help us with this aim!  Configure Proof General for your own proof assistant, by adding features at the generic level of Proof General wherever possible.  See Adapting Proof General to New Provers for more details, and send ideas, comments, patches, and code to proofgen@dcs.ed.ac.uk.

Quick start guide
=================

Proof General may have been installed for you already. If so, when you visit a proof script file for your proof assistant, the corresponding Proof General mode will be invoked automatically:

Prover   Extensions   Modes
LEGO     .l    lego-mode
Coq      .v    coq-mode
Isabelle   .thy,.ML   isa-mode

You can also invoke the mode command directly, e.g., type M-x lego-mode, to turn a buffer into a lego script buffer.

You'll find commands to process the proof script are available from the toolbar, menus, and keyboard.  Type C-h m to get a list of the keyboard shortcuts for the current mode.  The commands available should be easy to understand, but the rest of this manual describes them in some detail.

The proof assistant itself is started automatically inside Emacs as an "inferior" process when you ask for some of the proof script to be processed.  You can also start the proof assistant directly from the menu command "Start proof assistant".

To follow an example use of Proof General on a LEGO proof, see Walkthrough example in LEGO.  If you know the syntax for proof scripts in another theorem prover, you can easily adapt the details given there.

If Proof General has not already been installed, you should insert the line:

             (load "PROOF-GENERAL-HOME/generic/proof-site.el")

into your ~/.emacs file, where PROOF-GENERAL-HOME is the top-level directory that was created when Proof General was unpacked.

See Obtaining and Installing Proof General, if you need more information.

Features of Proof General
=========================

Why would you want to use Proof General?

Here is an outline of its main features.

  * Simplified communication
     The proof assistant's shell is normally hidden from the user. Communication takes place via two or three buffers.  The script buffer holds input, the commands to construct a proof.  The goals buffer displays the current list of subgoals to be solved.  The response buffer displays other output from the proof assistant. This means that the user only sees the output from the most recent proof step, rather than a screen full of output from the proof assistant.

     For more details, see Basic Script Management, Script buffers and Summary of Proof General buffers.

  * Script management
     Proof General colours proof script regions blue when they have already been processed by the prover, and colours regions red when the prover is currently processing them.  The appearance of Emacs buffers always matches the proof assistant's state. Coloured parts of the buffer cannot be edited.  Proof General has functions for asserting or retracting parts of a proof script, which alters the coloured regions.

     For more details, see Basic Script Management, Script processing commands. and Advanced Script Management.

  * Script editing mode
     Proof General provides useful facilities for editing proof scripts, including syntax hilighting and a menu to jump to particular goals, definitions, or declarations. Special editing functions send lines of proof script to the proof assistant, or undo previous proof steps.

     For more details, see Script editing commands and Script processing commands.

  * Toolbar and menus
     A script buffer has a toolbar with navigation buttons for processing parts of the proof script.  A menu provides further functions for operations in the proof assistant, as well as customization of Proof General.

     For more details, see Toolbar commands, Proof assistant commands, and Customizing Proof General.

Supported proof assistants
==========================

Proof General comes ready-customised for these proof assistants:

  * LEGO Proof General for LEGO Version 1.3.1

     All features of Proof General are supported. See LEGO Proof General for more details.

  * Coq Proof General for Coq Version 6.2

     All features of Proof General are supported except multiple files. See Coq Proof General for more details.

  * Isabelle Proof General for Isabelle 98-1

     All features of Proof General are supported, except for an external tags program.  Isabelle Proof General handles theory files as well as ML (proof script files), and has an extensive theory file editing mode taken from Isamode (http://www.dcs.ed.ac.uk/home/da/Isamode). See Isabelle Proof General for more details.

Proof General is designed to be generic, so you can adapt it to other proof assistants if you know a little bit of Emacs Lisp.

  * Your Proof General for your favourite proof assistant

     See Adapting Proof General to New Provers for more details of how to make Proof General work with another proof assistant.

Prerequisites for this manual
=============================

This manual assumes that you understand a little about using Emacs, for example, switching between buffers using C-x b and understanding that key sequences like C-x b mean "control-x followed by b".

The manual also assumes you have a basic understanding of your proof assistant and the language and files it uses for proof scripts.  But even without this, Proof General is not useless: you can use the interface to replay proof scripts for any proof assistant without knowing how to start it up or issue commands, etc.  This is the beauty of a common interface mechanism.

To get more from Proof General and adapt it to your liking, it helps to know a little bit about how Emacs lisp packages can be customized via the Customization mechanism.  It's really easy to use.  See Easy customization and see Easy customization ((xemacs)) for details.

To get the absolute most from Proof General, to improve it or to adapt it for new provers, you'll need to know a little bit of Emacs lisp. Emacs is self-documenting, so you can begin from C-h and find out everything!  Here are some useful commands:

C-h i
     info

C-h m
     describe-mode

C-h b
     describe-bindings

C-h f
     describe-function

C-h v
     describe-variable

Most of this manual covers the user-level view and customization of Proof General.  Towards the end we consider adapting Proof General to new proof assistants, and document some of the internals of Proof General.  The manual concludes with some credits and references. See the table of contents for details.

Basic Script Management
***********************

This chapter is an introduction to using the script management facilities of Proof General.  We begin with a quick walkthrough example, then describe the concepts and functions in more detail.

Walkthrough example in LEGO
===========================

Here's a short example in LEGO to see how script management is used. The file you are asked to type below is included in the distribution as lego/example.l.  If you're not using LEGO, substitute some lines from a simple proof for your proof assistant, or consult the example file provided with Proof General.

First, find a new file by doing C-x C-f and typing as the filename example.l.  This should load LEGO Proof General and the toolbar and Proof General menus will appear.  This walkthrough is keyboard based, although you could easily use the toolbar and menu functions instead.

Now turn on active terminator minor mode by typing C-c ; and enter:

     Module example Import lib_logic;

Active terminator minor mode sends commands to the proof assistant as you type them.  The command should now be lit in pink (or inverse video if you don't have a colour display).  As LEGO imports each module, a line will appear in the minibuffer showing the creation of context marks. Eventually the command should turn blue, indicating that LEGO has successfully processed it. Then type (on a separate line if you like):

     Goal bland_commutes: {A,B:Prop} (and A B) -> (and B A);

The goal should be echoed in the goals buffer.

     Intros;

Whoops! That was the wrong command. Press C-c C-u to pretend that didn't happen.

     intros; andI;

A proof summary will appear in the goals buffer.

     Refine H; intros; Immed; Refine H; intros; Immed;

finishes the Goal.

     Save bland_commutes;

Moving the mouse pointer over the locked region now reveals that the entire proof has been aggregated into a single segment. Suppose we decide to call the goal something more sensible. Moving the cursor up into the locked region, somewhere between Goal and Save, we enter C-c u.  The segment is transferred back into the editing region. Now we correct the goal name, move the cursor to the end of the buffer, and type C-c RET.  Proof mode queues the commands for processing and executes them.

Proof scripts
=============

A proof script is a sequence of commands which constructs definitions, declarations and proofs in a proof assistant. Proof General is designed to work with text-based interactive proof assistants, where the mode of working is usually a dialogue between the human and the proof assistant.

Primitive interfaces for proof assistants simply present a shell-like view of this dialogue: the human repeatedly types commands to the shell until the proof is completed.  The system responds at each step, perhaps with a new list of subgoals to be solved, or perhaps with a failure report.  Proof General manages the dialogue to only show the human the information which is relevant at each step.

Often we want to keep a record of the proof commands used to prove a theorem, to build up a library of proved results.  An easy way to store a proof is to keep a text file which contains a proof script; the proof assistant usually provides facilities to read a proof script from a file instead of the terminal.  Using the file, we can replay the proof script to prove the theorem again.

Using only a primitive shell interface, it can be tedious to construct proof scripts with cut-and-paste.  Proof General helps out by issuing commands directly from a proof script file, while it is being written and edited.  Proof General can also be used conveniently to replay a proof step-by-step, to see the progress at each stage.

Scripting is the process of building up a proof script file or replaying a proof.  When scripting, Proof General sends proof commands to the proof assistant one at a time, and prevents you from editing commands which have been successfully completed by the proof assistant. Regions of the proof script are analysed based on syntax and the behaviour of the proof assistant after each proof command.

Script buffers
==============

A script buffer is a buffer displaying a proof script.  Its Emacs mode is particular to the proof assistant you are using (but it inherits from proof-script mode).

A script buffer is divided into three regions: locked, queue and editing.  The proof commands in the script buffer can include a number of Goal-save sequences.

Locked, queue, and editing regions
----------------------------------

A script buffer is divided into three regions:

  * The locked region appears in blue (underlined on monochrome displays) and contains commands which have been sent to the proof process and verified. The commands in the locked region cannot be edited.

  * The queue region appears in pink (inverse video) and contains commands waiting to be sent to the proof process. Like those in the locked region, these commands can't be edited.

  * The editing region contains the commands the user is working on, and can be edited as normal Emacs text.

These three regions appear in the buffer in the order above; that is, the locked region is always at the start of the buffer, and the editing region always at the end. The queue region only exists if there is input waiting to be sent to the proof process.

Proof mode has two fundamental operations which transfer commands between these regions: assertion and retraction.

Assertion causes commands from the editing region to be transferred to the queue region and sent one by one to the proof process. If the command is accepted, it is transferred to the locked region, but if an error occurs it is signalled to the user, and the offending command is transferred back to the editing region together with any remaining commands in the queue.

Assertion corresponds to processing proof commands, and makes the locked region grow.

Retraction causes commands to be transferred from the locked region to the editing region (again via the queue region) and the appropriate 'undo' commands to be sent to the proof process.

Retraction corresponds to undoing commands, and makes the locked region shrink.  See Script processing commands details the commands available for doing assertion and retraction.

Goal-save sequences
-------------------

A proof script contains a sequence of commands used to prove one or more theorems.

As commands in a proof script are transferred to the locked region, they are aggregated into segments which constitute the smallest units which can be undone. Typically a segment consists of a declaration or definition, or all the text from a goal command to the corresponding save command, or the individual commands in the proof of an unfinished goal.  As the mouse moves over the the region, the segment containing the pointer will be highlighted.

Proof General therefore assumes that the proof script has a series of proofs which look something like this:

        goal MYTHM is G
        ...
        save theorem MYTHM

interspersed with comments, definitions, and the like.  Of course, the exact syntax and terminology will depend on the proof assistant you use.

The name MYTHM can appear in the menu for the proof script to help quickly find a proof (see Support for function menus).

Active scripting buffer
-----------------------

You can edit as many script buffers as you want simultaneously, but only one buffer at a time can be used to process a proof script incrementally: this is the active scripting buffer.

The active scripting buffer has a special indicator: the word Scripting appears in its mode line.

Proof General will give an error message: Cannot have more than one active scripting buffer! if you attempt to use the script processing commands in a new script buffer when there is already an active scripting buffer which is only partly completed.  If you get this error message, you must choose either to assert the remainder of the active buffer, or to retract what has been proved so far, before you can start scripting in another buffer.

See Switching between proof scripts for more explanation of this.

Summary of Proof General buffers
================================

Proof General manages several kinds of buffers in Emacs.  Here is a summary of the different kinds of buffers you will use when developing proofs.

  * The proof shell buffer is an Emacs shell buffer used to run your proof assistant.  Usually it is hidden from view (but see Working directly with the proof shell). Communication with the proof shell takes place via two or three intermediate buffers.

  * A script buffer, as we have explained, is a buffer for editing a proof script.  The active scripting buffer is the script buffer which is currently being used to send commands to the proof shell.

  * The goals buffer displays the list of subgoals to be solved for a proof in progress.  During a proof it is usually displayed together with the script buffer. The goals buffer has facility for proof-by-pointing, although this is disabled in Proof General 2.0.

  * The response buffer displays other output from the proof assistant, for example error messages or informative messages. The response buffer is displayed whenever Proof General puts a new message in it.

Normally Proof General will automatically reveal and hide the goals and response buffers as necessary during scripting.  However there are ways to customize the way the buffers are displayed (see Display customization).

The menu Proof General -> Buffers provides a convenient way to display or switch to one of the four buffers: active scripting, goals, response, or shell.

Script editing commands
=======================

Proof General provides a few functions for editing proof scripts. Specific proof assistant code may elaborate on these basics.

Indentation is controlled by the user option proof-script-indent (see User options).  When indentation is enabled, Proof General will indent lines of proof script with the usual Emacs functions, particularly TAB, indent-for-tab-command.

Unfortunately, indentation in Proof General 2.0 is somewhat slow and buggy.  Therefore with large proof scripts, we recommend proof-script-indent is turned off.

Here are the commands for moving around in a proof script, with their default key bindings:

C-c C-e
     proof-find-next-terminator

C-c C-a
     proof-goto-command-start.

C-c '
     proof-goto-end-of-locked-interactive

 -- Command: proof-find-next-terminator
     Set point after next proof-terminal-char.

The variable proof-terminal-char is a prover-specific character to terminate proof commands. LEGO and Isabelle use ;. Coq employs ..

 -- Command: proof-goto-command-start
     Move point to start of current command.

 -- Command: proof-goto-end-of-locked-interactive
     Switch to proof-script-buffer and jump to the end of the locked region. Must be an active scripting buffer.

Script processing commands
==========================

Here are the commands for asserting and retracting portions of the proof script, together with their default key bindings.  Note that assertion and retraction commands can only be issued when the queue is empty.  You will get an error message Proof Process Busy! if you try to assert or retract when the queue is being processed. (In fact, this is an unnecessary restriction imposed by the original design of Proof General.  There is nothing to stop future versions of Proof General allowing the queue region to be extended or shrunk, whilst the prover is processing it.)

C-c C-n
     proof-assert-next-command-interactive

C-c RET
     proof-assert-next-command-interactive

C-c C-u
     proof-undo-last-successful-command-interactive

C-c u
     proof-retract-until-point-interactive

C-c b
     proof-process-buffer

C-c TERMINATOR-CHARACTER
     proof-active-terminator-minor-mode

The last command, proof-active-terminator-minor-mode, is triggered using the character which terminates proof commands for your proof assistant's script language.  For LEGO and Isabelle, use C-c ;, for Coq, use C-c ..  This not really a script processing command. Instead, if enabled, it causes subsequent key presses of ; or . to automatically activate proof-assert-next-command-interactive for convenience.

Rather than use any other way of reading a proof script, a good reason to use C-c C-b (proof-process-buffer) is that with a faulty proof script (e.g., a script you are adapting to prove a different theorem), Proof General will stop exactly where the proof script fails, showing you the error message and the last processed command.  So you can easily continue development from exactly the right place in the script.

 -- Command: proof-assert-next-command-interactive
     Process until the end of the next unprocessed command after point. If inside a comment, just process until the start of the comment.

 -- Command: proof-undo-last-successful-command-interactive
     Undo last successful command at end of locked region. The text is also deleted from the proof script.

 -- Command: proof-retract-until-point-interactive
     Tell the proof process to retract until point. If invoked outside a locked region, undo the last successfully processed command.

 -- Command: proof-process-buffer
     Process the current buffer and set point at the end of the buffer.

 -- Command: proof-active-terminator-minor-mode &optional arg
     Toggle Proof General's active terminator minor mode. With arg, turn on the Active Terminator minor mode if and only if arg is positive.

     If active terminator mode is enabled, pressing a terminator will automatically activate proof-assert-next-command for convenience.

Toolbar commands
================

The toolbar provides a selection of functions for asserting and retracting portions of the script, and inserting "goal" and "save" type commands.

These functions are available only from the toolbar, menu Proof General -> Scripting, or via M-x.  There are no keybindings for them by default.

 -- Command: proof-toolbar-goal
     Insert a goal command into the script buffer, issue it to prover.

 -- Command: proof-toolbar-retract
     Retract entire buffer.

 -- Command: proof-toolbar-undo
     Undo last successful in locked region, without deleting it.

 -- Command: proof-toolbar-next
     Assert next command in proof to proof process. Move point if the end of the locked position is invisible.

 -- Command: proof-toolbar-use
     Process the whole buffer

 -- Command: proof-toolbar-restart
     Restart scripting via proof-shell-restart.

 -- Command: proof-toolbar-qed
     Insert a save theorem command into the script buffer, issue it.

Proof assistant commands
========================

There are several commands for interacting with the proof assistant away from a proof script.  Here are the keybindings and functions.

C-c C-p
     proof-prf

C-c c
     proof-ctxt

C-c h
     proof-help

C-c C-c
     proof-interrupt-process

C-c t
     proof-try-command

C-c C-v
     proof-execute-minibuffer-cmd

 -- Command: proof-prf
     List proof state.

 -- Command: proof-ctxt
     List context.

 -- Command: proof-help
     Print help message giving syntax.

 -- Command: proof-interrupt-process
     Interrupt the proof assistant.  Warning! This may confuse Proof General.

 -- Command: proof-try-command &optional unclosed-comment-fun
     Process the command at point, but don't add it to the locked region.

     Supplied to let the user to test the types and values of expressions. Checks via the function proof-state-preserving-p that the command won't change the proof state, but this isn't guaranteed to be foolproof and may cause Proof General to lose sync with the prover.

     Default action if inside a comment is just to go until the start of the comment. If you want something different, put it inside UNCLOSED-COMMENT-FUN.

 -- Command: proof-execute-minibuffer-cmd
     Prompt for a command in the minibuffer and send it to proof assistant. The command isn't added to the locked region.

     Warning! No checking whatsoever is done on the command, so this is even more dangerous than proof-try-command.

As if the last few commands weren't dangerous enough, there's also a command which explicitly adjusts the end of the locked region, to be used in extreme circumstances only.  See Working directly with the proof shell.

There are a few commands for stopping, starting, and restarting the proof assistant process which have menu entries but no key bindings. As with any Emacs command, you can invoke these with M-x.

 -- Command: proof-shell-start
     Initialise a shell-like buffer for a proof assistant.

     Also generates goal and response buffers. Does nothing if proof assistant is already running.

 -- Command: proof-shell-restart
     Clear script buffers and send proof-shell-restart-cmd. All locked regions are cleared and the active scripting buffer deactivated.  The restart command should re-synchronize Proof General with the proof assistant.

 -- Command: proof-shell-exit
     Query the user and exit the proof process.

     This simply kills the proof-shell-buffer relying on the hook function proof-shell-kill-function to do the hard work.

Advanced Script Management
**************************

What we really mean by advanced is that Proof General supports large proof developments. These are typically spread across various files which depend on each other in some way. Proof General knows enough about the dependencies to allow script management across multiple files.

Switching between proof scripts
===============================

Basic modularity in large proof developments can be achieved by splitting proof scripts across various files. Let's assume that you are in the middle of a proof development. You are working on a soundness proof of Hoare Logic in a file called (The suffix may depend of the specific proof assistant you are using e.g, LEGO's proof script files have to end with .l.) HSound.l. It depends on a number of other files which develop underlying concepts e.g. syntax and semantics of expressions, assertions, imperative programs. You notice that the current lemma is too difficult to prove because you have forgotten to prove some more basic properties about determinism of the programming language. Or perhaps a previous definition is too cumbersome or even wrong.

At this stage, you would like to visit the appropriate file, say sos.l and retract to where changes are required. Then, using script management, you want to develop some more basic theory in sos.l. Once this task has been completed (possibly involving retraction across even earlier files) and the new development has been asserted, you want to switch back to HSound.l and replay to the point you got stuck previously.

Some hours (or days) later you have completed the soundness proof and are ready to tackle new challenges. Perhaps, you want to prove a property that builds on soundness or you want to prove an orthogonal property such as completeness.

Proof General lets you do all of this while maintaining the consistency between proof script buffers and the state of the proof assistant. However, you cannot have more than one buffer where only a fraction of the proof script contains a locked region. Before you can employ script management in  another proof script buffer, you must either fully assert or retract the current script buffer.

View of processed files
=======================

Proof General is aware of all files that the proof assistant has processed or is currently processing. In fact, it relies on the proof assistant explicitly telling Proof General whenever it processes a new file which corresponds (For example, LEGO generates additional compiled (optimised) proof script files for efficiency.) to a file containing a proof script. For further technical details, see Handling multiple files.

If the current proof script buffer depends on background material from other files, proof assistants typically process these files automatically. If you visit such a file, the whole file is locked as having been processed in a single step. From the user's point of view, you can only retract but not assert in this buffer. Furthermore, retraction is only possible to the beginning of the buffer.

To be more precise, buffers are locked as soon the proof assistant notifies Proof General of processing a file different from the current proof script. Thus, if you visit the file while the proof assistant is still processing the file, it is already completely locked. If the proof assistant is not happy with the script and complains with an error message, the buffer will still be marked as having been completely processed. Sorry. You need to visit the troublesome file, retract (which will always retract to the beginning of the file) and debug the problem e.g., by asserting all of the buffer under the supervision of Proof General, see Script processing commands.

In case you wondered, inconsistencies may arise when you have unsaved changes in a proof script buffer and the proof assistant suddenly decides to automatically process the corresponding file. The good news is that Proof General detects this problem and flashes up a warning in the response buffer. You might then want to visit the modified buffer, save it and retract to the beginning. Then you are back on track.

Retracting across files
=======================

Make sure that the current script buffer has either been completely asserted or retracted. Then you can retract proof scripts in a different file. Simply visit a file that has been processed earlier and retract in it, using the retraction commands from Script processing commands. Apart from removing parts of the locked region in this buffer, all files which depend on it will be retracted (and thus unlocked) automatically. Proof General reminds you that now is a good time to save any unmodified buffers.

Asserting across files
======================

Make sure that the current script buffer has either been completely asserted or retracted. Then you can assert proof scripts in a different file. Simply visit a file that contains no locked region and assert some command with the usual assertion commands, see Script processing commands. Proof General reminds you that now is a good time to save any unmodified buffers. This is particularly useful as assertion may cause the proof assistant to automatically process other files.

Working directly with the proof shell
=====================================

Occasionally you may want to review the dialogue of the entire session with the proof assistant, or check that it hasn't done something unexpected. Experienced users may also want to directly communicate with the proof assistant rather than sending commands via the minibuffer, see Proof assistant commands.

Although the proof shell is usually hidden from view, it is run in a buffer which provides the usual full editing and history facilities of Emacs shells (see the package comint.el distributed with your version of Emacs). You can switch to it using the menu:

       Proof-General -> Buffers -> Shell

Warning: you can probably cause confusion by typing in the shell buffer!  Proof General may lose track of the state of the proof assistant.

Proof General watches the output from the proof assistant to guess when a file is loaded or when a proof step is taken or undone, but it may not be guaranteed when the restricted interface is by-passed.  What happens depends on how complete the communication is between Proof General and the prover (which depends on the particular instantiation of Proof General).

To resynchronise, you have two options. If you are lucky, it might suffice to

C-c C-z
     move the end of the locked region backwards to the end of the segment containing the point.

Otherwise, you will need to restart script management altogether (see Proof assistant commands).

Support for other Packages
**************************

Proof General makes some configuration for other Emacs packages which provide various useful facilities.  Sometimes this configuration is at the proof assistant specific level, but we suggest that it should be made for all proof assistants, as a convention.

The packages currently supported are font-lock fume-func, outline-mode and etags.

Syntax Highlighting
===================

In XEmacs 20.4, proof script buffer are coloured (fontified as they say) by default. To automatically switch on fontification in FSF GNU Emacs 20.2, you need to configure the font-lock package yourself. This can be achieved by modifying the PROVER-mode-hooks where PROVER is either lego, coq or isa. For example, for LEGO you need to specify

      (add-hook 'lego-mode-hooks 'turn-on-font-lock)

in your ~/.emacs file.

Support for function menus
==========================

The Emacs package fume-func is a handy facility to make a menu from the names of entities declared in a buffer.  Proof General configures fume-func so that you can quickly jump to particular proofs in a script buffer.  (This is done with the configuration variables proof-goal-with-hole-regexp and proof-save-with-hole-regexp.)

If you want to use fume-func, you may need to enable it for yourself.  The package is distributed with XEmacs, but not enabled by default.  To enable it you should find the file func-menu.el and follow the instructions there.  At the time of writing, the current version of XEmacs is 20.4, supplied with function menu version 2.45, which suggests the following code for your .emacs file:

        (require 'func-menu)
        (define-key global-map 'f8 'function-menu)
        (add-hook 'find-file-hooks 'fume-add-menubar-entry t)
        (define-key global-map "\C-cl" 'fume-list-functions)
        (define-key global-map "\C-cg" 'fume-prompt-function-goto)
        (define-key global-map '(shift button3) 'mouse-function-menu)
        (define-key global-map '(meta  button1) 'fume-mouse-function-goto)

If you have another version of Emacs, you should check the fume-func.el file supplied with it.

Support for outline mode
========================

Proof General configures Emacs variables (outline-regexp and outline-heading-end-regexp) so that outline minor mode can be used on proof script files.  The headings taken for outlining are the "goal" statements at the start of goal-save sequences, see Goal-save sequences. If you want to use outline to hide parts of the proof script in the locked region, you need to disable proof-strict-read-only.

Use M-x outline-minor-mode to turn on outline minor mode. Functions for navigating, hiding, and revealing the proof script are available in menus.

See Outline Mode ((xemacs)) for more information about outline mode.

Support for tags
================

An Emacs "tags table" is a description of how a multi-file system is broken up into files.  It lists the names of the component files and the names and positions of the functions (or other named subunits) in each file.  Grouping the related files makes it possible to search or replace through all the files with one command.  Recording the function names and positions makes possible the M-. command which finds the definition of a function by looking up which of the files it is in.

Some instantiations of Proof General (currently LEGO and Coq) are supplied with external programs for making tags tables.  Once a tag table has been made for your proof developments, you can use the Emacs tags mechanisms to find tags, and complete symbols from tags table.

One useful key binding you might want to make is to set the usual completion key M-tab to run tag-complete-symbol to use completion from names in the tag table.  To set this binding in Proof General script buffers, put this code in your .emacs file:

     (add-hook 'proof-mode-hook
       (lambda () (local-set-key '(meta tab) 'tag-complete-symbol)))

Since this key binding interferes with a default binding that users may already have customized, Proof General doesn't do this automatically.

For more information on how to use tags, see Tags ((xemacs)).

Customizing Proof General
*************************

There are two kinds of customization for Proof General: it can be customized for a user's preferences using a particular proof assistant, or it can be customized by an Emacs expert to add a new proof assistant. Here we cover the user-level customization for Proof General, see Adapting Proof General to New Provers for how to configure for a new proof assistant.

We only consider settings for Proof General itself.  The support for a particular proof assistant can provide extra customization settings. See the chapters covering each assistant for details.

Easy customization
==================

Proof General uses the Emacs customization library to provide a friendly interface.

You can access the customization settings for Proof General via the menu:

        Options -> Customize -> Emacs -> External -> Proof General

in XEmacs.

In FSF GNU Emacs, use the menu:

        Help -> Customize -> Specific group

and type proof-general RET.

The complete set of customization settings will only be available after Proof General has been fully loaded.  Proof General is fully loaded when you visit a script file for the first time. (or if you type M-x load-library RET proof RET.)  When visiting a script file, there is a more direct route to the settings:

        Proof-General -> Customize

Using the customize facility is straightforward.  You can select the setting to customize via the menus, or with M-x customize-variable.  When you have selected a setting, you are shown a buffer with its current value, and facility to edit it.  Once you have edited it, you can use the special buttons SET, SAVE and DONE.  You must use one of SET or SAVE to get any effect.  The SAVE button stores the setting in your .emacs file.

Notice that in the customize menus, the variable names mentioned later in this chapter may have been abbreviated (without the "proof-" or similar prefixes).  Also, some of the option settings may have more descriptive names (for example, ON and OFF) than the low-level lisp values (non-nil, nil) which are mentioned in this chapter.  These features make customize much more friendly than raw lisp.

For more help, see Easy Customization (xemacs).

Display customization
=====================

If you are working on a workstation with a window system, you can use Emacs to manage several frames on the display, to keep the goals buffer displayed in a fixed place on your screen and in a certain font, for example.  A convenient way to do this is via special-display-regexps, for example:

     (setq special-display-regexps
             (cons "\\*Inferior.*-\\(goals\\|response\\)\\*"
              special-display-regexps))

 -- User Option: proof-auto-delete-windows
     If non-nil, automatically remove windows when they are cleaned. For example, at the end of a proof the goals buffer window will be cleared; if this flag is set it will automatically be removed. If you want to fix the sizes of your windows you may want to set this variable to 'nil' to avoid windows being deleted automatically. If you use multiple frames, only the windows in the currently selected frame will be automatically deleted.

     The default value is nil.

User options
============

Here are the remaining user options for Proof General.  These can be set via the customization system, via the old-fashioned M-x edit-options mechanism, or simply by adding setq's to your .emacs file.  The first approach is strongly recommended.

 -- User Option: proof-prog-name-ask
     If non-nil, query user which program to run for the inferior process.

     The default value is nil.

 -- User Option: proof-rsh-command
     Shell command prefix to run a command on a remote host. For example,

             ssh bigjobs

     Would cause Proof General to issue the command ssh bigjobs isabelle to start Isabelle remotely on our large compute server called bigjobs.

     The protocol used should be configured so that no user interaction (passwords, or whatever) is required to get going.

     The default value is "".

 -- User Option: proof-toolbar-inhibit
     Non-nil prevents toolbar being used for script buffers.

     The default value is nil.

 -- User Option: proof-toolbar-follow-mode
     Choice of how point moves with toolbar commands. One of the symbols: 'locked, 'follow, 'ignore. If 'locked, point sticks to the end of the locked region with toolbar commands. If 'follow, point moves just when needed to display the locked region end. If 'ignore, point is never moved after toolbar movement commands.

     The default value is locked.

 -- User Option: proof-window-dedicated
     Whether response and goals buffers have dedicated windows. If t, windows displaying responses from the prover will not be switchable to display other windows.  This may help manage your display, but can sometimes be inconvenient, especially for experienced Emacs users. Moreover, this option may cause problems with multi-frame use because of a bug.

     The default value is nil.

 -- User Option: proof-strict-read-only
     Whether Proof General is strict about the read-only region in buffers. If non-nil, an error is given when an attempt is made to edit the read-only region.  If nil, Proof General is more relaxed (but may give you a reprimand!)

     The default value is strict.

 -- User Option: proof-script-indent
     If non-nil, enable indentation code for proof scripts. Currently the indentation code can be rather slow for large scripts, and is critical on the setting of regular expressions for particular provers.  Enable it if it works for you.

     The default value is nil.

 -- User Option: proof-one-command-per-line
     If non-nil, format for newlines after each proof command in a script. This option is not fully-functional at the moment.

     The default value is nil.

 -- User Option: proof-splash-inhibit
     Non-nil prevents splash screen display when Proof General is loaded.

     The default value is nil.

Changing faces
==============

The fonts and colours that Proof General uses are configurable.  If you alter these through the customize menus, only the particular kind of display in use (colour window system, monochrome window system, console, ...) will be affected.

 -- Face: proof-queue-face
     Face for commands in proof script waiting to be processed.

 -- Face: proof-locked-face
     Face for locked region of proof script (processed commands).

 -- Face: proof-declaration-name-face
     Face for declaration names in proof scripts. Exactly what uses this face depends on the proof assistant.

 -- Face: proof-tacticals-name-face
     Face for names of tacticals in proof scripts. Exactly what uses this face depends on the proof assistant.

 -- Face: proof-error-face
     Face for error messages from proof assistant.

 -- Face: proof-warning-face
     Face for warning messages. Warning messages can come from proof assistant or from Proof General itself.

The slightly bizarre name of the next face comes from the idea that while large amounts of output are being sent from the prover, some messages should be displayed to the user while the bulk of the output is hidden.  The messages which are displayed may have a special annotation to help Proof General recognize them, and this is an "eager" annotation in the sense that it should be processed as soon as it is observed by Proof General.

 -- Face: proof-eager-annotation-face
     Face for messages from proof assistant.

Tweaking configuration settings
===============================

This section is a note for advanced users.

Configuration settings are the per-prover customizations of Proof General.  These are not intended to be adjusted by the user.  But occasionally you may like to test changes to these settings to improve the way Proof General works.  You may want to do this when a proof assistant has a flexible proof script language in which one can define new tactics or even operations, and you want Proof General to recognize some of these which the default settings don't mention.  So please feel free to try adjusting the configuration settings and report to us if you find better default values than the ones we have provided.

The configuration settings appear in the customization group prover-config, or via the menu

         Proof-General -> Internals ->  Prover Config

One basic example of a setting you may like to tweak is:

 -- Variable: proof-assistant-home-page
     Web address for information on proof assistant

Most of the others are more complicated.  For more details of the settings, see Adapting Proof General to New Provers.  To browse them, you can look through the customization groups prover-config, proof-script and proof-shell.  The group proof-script contains the configuration variables for scripting, and the group proof-shell contains those for interacting with the proof assistant.

Unfortunately, although you can use the customization mechanism to set and save these variables, saving them may have no effect because the default settings are often hard-wired into the proof assistant code. Ones we expect may need changing appear as proof assistant specific configurations.  For example, proof-assistant-home-page is set in the LEGO code from the value of the customization setting lego-www-home-page.  At present there is no easy way to save changes to other configuration variables across sessions, other than by editing the source code.  Please contact us if this proves to be a problem for any variable.

LEGO Proof General
******************

LEGO proof script mode is a mode derived from proof script mode for editing LEGO scripts. An important convention is that proof script buffers must start with a module declaration. If the proof script buffer's file name is fermat.l, then it must commence with a declaration of the form

     Module fermat;

If, in the development of the module fermat, you require material from other module e.g., lib_nat and galois, you need to specify this dependency as part of the module declaration:

     Module fermat Import lib_nat galois;

No need to worry too much about efficiency. When you retract back to a module declaration to add a new import item, LEGO does not actually retract the previously imported modules. Therefore, reasserting the extended module declaration really only processes the newly imported modules.

Using the LEGO Proof General, you never ever need to use administrative LEGO commands such as Forget, ForgetMark, KillRef, Load, Make, Reload and Undo again (And please, don't even think of including those in your LEGO proof script!). You can concentrate on your actual proof developments. Script management in Proof General will invoke the appropriate commands for you. Proving with LEGO has never been easier.

LEGO specific commands
======================

In addition to the commands provided by the generic Proof General (as discussed in the previous sections) the LEGO Proof General provides a few extensions. In proof scripts, there are some abbreviations for common commands:

C-c i
     intros

C-c I
     Intros

C-c R
     Refine

LEGO tags
=========

The LEGO Proof General provides the program legotags to generate tags for LEGO proof scripts. Invoking legotags *.l produces a file TAGS for all LEGO modules in the current directory (You might want to ask your local system administrator to tag the directories lib_Prop, lib_Type and lib_TYPE of the LEGO library.). See Support for tags for further details on tags.

LEGO customizations
===================

We refer to chapter Customizing Proof General for an introduction to the customisation mechanism. In addition to customizations at the generic level, for LEGO you can also customize:

 -- User Option: lego-tags
     The directory of the TAGS table for the LEGO library

     The default value is "/usr/lib/lego/lib_Type/".

 -- Variable: lego-www-home-page
     Lego home page URL.

 -- Variable: lego-help-menu-list
     List of menu itemsfor LEGO specific help.

     See the documentation of easy-menu-define

Coq Proof General
*****************

Coq proof script mode is a mode derived from proof script mode for editing Coq scripts. As well as custom popup menus, it has the following commands:

C-c C-s
     search for items in the library of a given type.  This runs the Search command of Coq.

In addition, there are some abbreviations for common commands, which add text to the buffer:

C-c I
     Intros

C-c a
     Apply

Sorry, there is currently very little specific documentation written for Coq Proof General. If any Coq user would like to contribute, please send a message to proofgen@dcs.ed.ac.uk.

Type C-h C-m to get a list of all Coq specific commands and browse the customize menus to find out what customization options there are for Coq.

Isabelle Proof General
**********************

Isabelle Proof General includes a mode for editing theory files taken from David Aspinall's Isamode interface, http://www.dcs.ed.ac.uk/home/da/Isamode.  Detailed documentation for the theory file mode is included with Isamode, there are some notes on the special functions available and customization settings below.

Theory files
============

Isabelle Proof General attempts to lock theory files as well as ML files when they are loaded.  Theory files are always completely locked or completely unlocked, because they are processed atomically.

Proof General attempts to load the theory file for a .ML file automatically before you start scripting.  This is tricky because Isabelle's theory loader assumes that .ML files are always read together with theory files.  At the moment Proof General uses an altered version of use_thy which doesn't load the top-level ML file in this case.

Compared to Isamode's theory editing mode, some of the functions and key bindings for interacting with Isabelle have been removed, and two new functions are available.

The key C-c C-b (isa-process-thy-file) will cause Isabelle to read the theory file being edited.  This causes the file and all its children (both theory and ML files) to be read.  Any top-level ML file associated with this theory file is also read.

The key C-c C-u (isa-retract-thy-file) will retract (unlock) the theory file being edited.  This unlocks the file and all its children (theory and ML files); no changes occur in Isabelle itself.

 -- Command: isa-process-thy-file file
     Process the theory file FILE.  If interactive, use buffer-file-name.

 -- Command: isa-retract-thy-file file
     Retract the theory file FILE. If interactive, use buffer-file-name.

Isabelle specific commands
==========================

Switching to theory files
-------------------------

In Isabelle proof script mode, C-c C-o (thy-find-other-file) finds and switches to the associated theory file, that is, the file with the same base name but extension .thy swapped for .ML.

The same function (and keybinding) switches back to an ML file from the theory file.

 -- Command: thy-find-other-file &optional samewindow
     Find associated .ML or .thy file. Finds and switch to the associated ML file (when editing a theory file) or theory file (when editing an ML file). If SAMEWINDOW is non-nil (interactively, with an optional argument) the other file replaces the one in the current window.

Isabelle customizations
=======================

Here are some of the user options specific to Isabelle.  You can set these as usual with the customization mechanism.

 -- Variable: isabelle-web-page
     URL of web page for Isabelle.

 -- User Option: thy-use-sml-mode
     If non-nil, invoke sml-mode inside "ML" section of theory files. This option is left-over from Isamode.  Really, it would be more useful if the script editing mode of Proof General itself could be based on sml-mode, but at the moment there is no way to do this.

     The default value is nil.

 -- Variable: thy-indent-level
     Indentation level for Isabelle theory files.  An integer.

 -- User Option: thy-indent-level
     Indentation level for Isabelle theory files.  An integer.

 -- Variable: thy-sections
     Names of theory file sections and their templates. Each item in the list is a pair of a section name and a template. A template is either a string to insert or a function. Useful functions are:

            thy-insert-header, thy-insert-class, thy-insert-default-sort,
            thy-insert-const, thy-insert-rule.

     The nil template does nothing. You can add extra sections to theory files by extending this variable.

 -- Variable: thy-template
     Template for theory files. Contains a default selection of sections in a traditional order. You can use the following format characters:

     %t --- replaced by theory name.

     %p --- replaced by names of parents, separated by + characters.

Adapting Proof General to New Provers
*************************************

Proof General has about 60 configuration variables which are set on a per-prover basis to configure the various features.  It may sound like a lot but don't worry!  Many of the variables occur in pairs (typically regular expressions matching the start and end of some text), and you can begin by setting just a few variables to get the basic features of script management working.

The configuration variables are declared in the file generic/proof-config.el.  Documentation below is based on the contents of that file.

Overview of adding a new prover
===============================

Each proof assistant supported has its own subdirectory under proof-home-directory, used to store a root elisp file and any other files needed to adapt the proof assistant for Proof General.

Here is how to go about adding support for a new prover.

  * Make a directory called myassistant/ under the Proof General home directory proof-home-directory, to put the specific customization and associated files in.

  * Add a file myassistant.el to the new directory.

  * Edit proof-site.el to add a new entry to the proof-assistants-table variable.  The new entry should look like this:

              (myassistant "My New Assistant" "\\.myasst$")

     The first item is used to form the name of the internal variables for the new mode as well as the directory and file where it loads from.  The second is a string, naming the proof assistant.  The third item is a regular expression to match names of proof script files for this assistant.  See the documentation of proof-assistant-table for more details.

  * Define the new modes in myassistant.el, by looking at the files for the currently supported assistants for example. Basically you need to define some modes using define-derived-mode and set the configuration variables.  It's important that your modes invoke the callbacks proof-config-done and proof-shell-config-done once they've set the configuration variables.

You could begin by setting minimum number of the variables, then adjust the settings via the customize menus, under Proof-General -> Internals.

 -- User Option: proof-assistant-table
     Proof General's table of supported proof assistants. Extend this table to add a new proof assistant. Each entry is a list of the form

              (SYMBOL NAME AUTOMODE-REGEXP)

     The NAME is a string, naming the proof assistant. The SYMBOL is used to form the name of the mode for the assistant, SYMBOL-mode, run when files with AUTOMODE-REGEXP are visited.  SYMBOL is also used to form the name of the directory and elisp file for the mode, which will be

              PROOF-HOME-DIRECTORY/SYMBOL/SYMBOL.el

     where PROOF-HOME-DIRECTORY is the value of the variable proof-home-directory.

     The default value is ((isa "Isabelle" "\\.ML$\\|\\.thy$") (lego "LEGO" "\\.l$") (coq "Coq" "\\.v$")).

Major modes used by Proof General
=================================

 -- Variable: proof-mode-for-shell
     Mode for proof shell buffers. Usually customised for specific prover. Suggestion: this can be set in the shell mode configuration.

 -- Variable: proof-mode-for-response
     Mode for proof response buffer. Usually customised for specific prover. Suggestion: this can be set in the shell mode configuration.

 -- Variable: proof-mode-for-pbp
     Mode for proof state display buffers. Usually customised for specific prover. Suggestion: this can be set in the shell mode configuration.

 -- Variable: proof-mode-for-script
     Mode for proof script buffers. This is used by Proof General to find out which buffers contain proof scripts. Suggestion: this can be set in the script mode configuration.

Menus and user-level commands
=============================

 -- Variable: proof-assistant-home-page
     Web address for information on proof assistant

 -- Variable: proof-ctxt-string
     Command to display the context in proof assistant.

 -- Variable: proof-help-string
     Command to ask for help in proof assistant.

 -- Variable: proof-prf-string
     Command to display proof state in proof assistant.

 -- Variable: proof-goal-command
     Command to set a goal in the proof assistant.  String or fn. If a string, the format character %s will be replaced by the goal string. If a function, should return a command string to insert when called interactively.

 -- Variable: proof-save-command
     Command to save a proved theorem in the proof assistant.  String or fn. If a string, the format character %s will be replaced by the theorem name. If a function, should return a command string to insert when called interactively.

Proof script settings
=====================

The following variables should be set before proof-config-done is called.  These configure the mode for the script buffer, including highlighting, etc.

 -- Variable: proof-terminal-char
     Character which terminates a command in a script buffer.

 -- Variable: proof-comment-start
     String which starts a comment in the proof assistant command language. The script buffer's comment-start is set to this string plus a space.

 -- Variable: proof-comment-end
     String which ends a comment in the proof assistant command language. The script buffer's comment-end is set to this string plus a space.

 -- Variable: proof-save-command-regexp
     Matches a save command

 -- Variable: proof-save-with-hole-regexp
     Regexp which matches a command to save a named theorem. Match number 2 should be the name of the theorem saved. Used for setting names of goal..save regions and for default func-menu configuration in proof-script-find-next-goalsave.

 -- Variable: proof-goal-command-regexp
     Matches a goal command.

 -- Variable: proof-goal-with-hole-regexp
     Regexp which matches a command used to issue and name a goal. Match number 2 should be the name of the goal issued. Used for setting names of goal..save regions and for default func-menu configuration in proof-script-find-next-goalsave.

 -- Variable: proof-script-next-entity-regexps
     Regular expressions to control finding definitions in script. This is the list of the form

             (ANYENTITY-REGEXP
              DISCRIMINATOR-REGEXP  ... DISCRIMINATOR-REGEXP)

     The idea is that ANYENTITY-REGEXP matches any named entity in the proof script, on a line where the name appears.  This is assumed to be the start or the end of the entity.  The discriminators then test which kind of entity has been found, to get its name.  A DISCRIMINATOR-REGEXP has one of the forms

            (REGEXP MATCHNO)
            (REGEXP MATCHNO 'backward BACKREGEXP)
            (REGEXP MATCHNO 'forward FORWARDREGEXP)

     If REGEXP matches the string captured by ANYENTITY-REGEXP, then MATCHNO is the match number for the substring which names the entity.

     If 'backward BACKREGEXP is present, then the start of the entity is found by searching backwards for BACKREGEXP.

     Conversely, if 'forward FORWARDREGEXP is found, then the end of the entity is found by searching forwards for FORWARDREGEXP.

     Otherwise, the start and end of the entity will be the region matched by ANYENTITY-REGEXP.

     This mechanism allows fairly complex parsing of the buffer, in particular, it allows for goal..save regions which are named only at the end.  However, it does not parse strings, comments, or parentheses.

     This variable may not need to be set: a default value which should work for goal..saves is calculated from proof-goal-with-hole-regexp, proof-goal-command-regexp, and proof-save-with-hole-regexp.

 -- Variable: proof-lift-global
     This function lifts local lemmas from inside goals out to top level. This function takes the local goalsave span as an argument. Set this to nil of the proof assistant does not support nested goals.

 -- Variable: proof-count-undos-fn
     Compute number of undos in a target segment

 -- Variable: proof-find-and-forget-fn
     Function returning a command string to forget back to before its argument span. The special string proof-no-command means there is nothing to do.

 -- Variable: proof-goal-hyp-fn
     Function which returns cons cell if point is at a goal/hypothesis. First element of cell is a symbol, 'goal' or 'hyp'.  The second element is a string: the goal or hypothesis itself.  This is used when parsing the proofstate output.

 -- Variable: proof-kill-goal-command
     Command to kill a goal.

 -- Variable: proof-global-p
     Whether a command is a global declaration.  Predicate on strings or nil. This is used to handle nested goals allowed by some provers.

 -- Variable: proof-state-preserving-p
     A predicate, non-nil if its argument (a command) preserves the proof state.

 -- Variable: proof-activate-scripting-hook
     Hook run when a buffer is switched into scripting mode. The current buffer will be the newly active scripting buffer.

     This hook may be useful for synchronizing with the proof assistant, for example, to switch to a new theory.

 -- Variable: proof-stack-to-indent
     Prover-specific code for indentation.

 -- Variable: proof-parse-indent
     Proof-assistant specific function for parsing. Invoked in proof-parse-to-point. Must be a function taking two arguments, a character (the current character) and a stack reflecting indentation, and must return a stack. The stack is a list of the form (c . p) where c is a character representing the type of indentation and p records the column for indentation. The generic proof-parse-to-point function supports parentheses and commands. It represents these with the characters ?(, ?[ and proof-terminal-char.

Proof shell settings
====================

The variables in this section are the largest group.  They concern the proof shell mode.  The first group of variables are hooks invoked at various points.  The second group of variables are concerned with matching the output from the proof assistant.

Variables here are put into the customize group proof-shell.

These should be set in the shell mode configuration, before proof-shell-config-done is called.

To understand the customizations for the proof shell, you may want to refer to the comint.el (Command interpreter) package distributed with Emacs.  This package controls several shell-like modes available in Emacs.

Commands
--------

 -- Variable: proof-prog-name
     System command to run program name in proof shell. Suggestion: this can be set in proof-pre-shell-start-hook from a variable which is in the proof assistant's customization group.  This allows different proof assistants to coexist (albeit in separate Emacs sessions).

 -- Variable: proof-shell-init-cmd
     The command for initially configuring the proof process.

 -- Variable: proof-shell-restart-cmd
     A command for re-initialising the proof process.

 -- Variable: proof-shell-quit-cmd
     A command to quit the proof process.  If nil, send EOF instead.

 -- Variable: proof-shell-cd
     Command to the proof assistant to change the working directory.

Settings for matching output from proof process
-----------------------------------------------

 -- Variable: proof-shell-wakeup-char
     A special character which terminates an annotated prompt. Set to nil if proof assistant does not support annotated prompts.

 -- Variable: proof-shell-first-special-char
     First special character. Codes above this character can have special meaning to Proof General, and are stripped from the prover's output strings.

 -- Variable: proof-shell-prompt-pattern
     Proof shell's value for comint-prompt-pattern.

 -- Variable: proof-shell-annotated-prompt-regexp
     Regexp matching a (possibly annotated) prompt pattern. Output is grabbed between pairs of lines matching this regexp. To help matching you may be able to annotate the proof assistant prompt with a special character not appearing in ordinary output. The special character should appear in this regexp, and should be the value of proof-shell-wakeup-char.

 -- Variable: proof-shell-abort-goal-regexp
     Regexp matching output from an aborted proof.

 -- Variable: proof-shell-error-regexp
     Regexp matching an error report from the proof assistant. We assume that an error message corresponds to a failure in the last proof command executed.  So don't match mere warning messages with this regexp. Moreover, an error message should not be matched as an eager annotation (see proof-shell-eager-annotation-start) otherwise it will be lost.

 -- Variable: proof-shell-interrupt-regexp
     Regexp matching output indicating the assistant was interrupted. Similar notes apply as for proof-shell-error-regexp.

 -- Variable: proof-shell-proof-completed-regexp
     Regexp matching output indicating a finished proof.

 -- Variable: proof-shell-clear-response-regexp
     Regexp matching output telling Proof General to clear the response buffer. This feature is useful to give the prover more control over what output is shown to the user.  Set to nil to disable.

 -- Variable: proof-shell-start-goals-regexp
     Regexp matching the start of the proof state output.

 -- Variable: proof-shell-end-goals-regexp
     Regexp matching the end of the proof state output.

 -- Variable: proof-shell-eager-annotation-start
     Eager annotation field start.  A regular expression or nil. An eager annotation indicates to Emacs that some following output should be displayed immediately and not accumulated for parsing. Set to nil to disable this feature.

 -- Variable: proof-shell-eager-annotation-end
     Eager annotation field end.  A regular expression or nil. An eager annotation indicates to Emacs that some following output should be displayed immediately and not accumulated for parsing.

     The default value is "\n" to match up to the end of the line.

 -- Variable: proof-shell-assumption-regexp
     A regular expression matching the name of assumptions.

Hooks and function variables
----------------------------

 -- Variable: proof-shell-insert-hook
     Hooks run by proof-shell-insert before inserting a command. Can be used to configure the proof assistant to the interface in various ways -- for example, to observe or alter the commands sent to the prover, or to sneak in extra commands to configure the prover (e.g. setting the pretty printer's line width if a window width size has changed).

     This hook is called by proof-shell-insert.  The call takes place inside a save-excursion with the proof-shell-buffer current, just before inserting the text in the variable STRING.  The hook can massage STRING or insert additional text directly into the proof-shell-buffer.  Before sending STRING, it will be stripped of carriage returns.

     NB: You should be very careful about setting this hook.  Proof General relies on a careful synchronization with the process between inputs and outputs.  It expects to see a prompt for each input it sends from the queue.  If you add extra input here and it causes more prompts than expected, things will break!  Massaging the STRING variable may be safer since it is stripped of carriage returns before being sent.

 -- Variable: proof-pre-shell-start-hook
     Hooks run before proof shell is started. This may be set to a function which configures the proof shell variables.

 -- Variable: proof-shell-handle-error-hook
     Hooks run after an error has been reported in the response buffer.

 -- Variable: proof-shell-process-file
     A pair (REGEXP . FUNCTION) to match a processed file name.

     If REGEXP matches output, then the function FUNCTION is invoked on the output string chunk. It must return a script file name (with complete path) the system is currently processing. In practice, FUNCTION is likely to inspect the match data.  If it returns the empty string, the file name of the scripting buffer is used instead.  If it returns nil, no action is taken.

     Care has to be taken in case the prover only reports on compiled versions of files it is processing. In this case, FUNCTION needs to reconstruct the corresponding script file name. The new (true) file name is added to the front of proof-included-files-list.

 -- Variable: proof-shell-retract-files-regexp
     A REGEXP to match that the prover has retracted across file boundaries.

     At this stage, Proof General's view of the processed files is out of date and needs to be updated with the help of the function proof-shell-compute-new-files-list.

 -- Variable: proof-shell-compute-new-files-list
     Function to update proof-included-files list.

     It needs to return an up to date list of all processed files. Its output is stored in proof-included-files-list. Its input is the string of which proof-shell-retract-files-regexp matched a substring. In practice, this function is likely to inspect the previous (global) variable proof-included-files-list and the match data triggered by proof-shell-retract-files-regexp.

 -- Variable: proof-shell-process-output-system-specific
     Set this variable to handle system specific output. Errors, start of proofs, abortions of proofs and completions of proofs are recognised in the function proof-shell-process-output. All other output from the proof engine is simply reported to the user in the RESPONSE buffer.

     To catch further special cases, set this variable to a pair of functions '(condf . actf). Both are given (cmd string) as arguments. cmd is a string containing the currently processed command. string is the response from the proof system. To change the behaviour of proof-shell-process-output, (condf cmd string) must return a non-nil value. Then (actf cmd string) is invoked. See the documentation of proof-shell-process-output for the required output format.

Splash screen settings
======================

The splash screen can be configured, in a rather limited way.

 -- Variable: proof-splash-time
     Minimum number of seconds to display splash screen for. The splash screen may be displayed for a couple of seconds longer than this, depending on how long it takes the machine to initialise Proof General.

 -- Variable: proof-splash-contents
     Evaluated to configure splash screen displayed when entering Proof General. If an element is a string or an image specifier, it is displayed centred on the window on its own line.  If it is nil, a new line is inserted.

 -- Variable: proof-splash-extensions
     Prover specific extensions of splash screen. These are evaluated and appended to proof-splash-contents.

Goals buffer configuration
==========================

The goals buffer configuration will allow configuration of Proof General for proof by pointing or similar features.  At the moment these settings are disabled.

 -- Variable: pbp-change-goal
     Command to change to the goal %s

 -- Variable: pbp-goal-command
     Command informing the prover that pbp-button-action has been requested on a goal.

 -- Variable: pbp-hyp-command
     Command informing the prover that pbp-button-action has been requested on an assumption.

 -- Variable: pbp-error-regexp
     Regexp indicating that the proof process has identified an error.

 -- Variable: proof-shell-result-start
     Regexp matching start of an output from the prover after pbp commands. In particular, after a pbp-goal-command or a pbp-hyp-command.

 -- Variable: proof-shell-result-end
     Regexp matching end of output from the prover after pbp commands. In particular, after a pbp-goal-command or a pbp-hyp-command.

Global constants
================

The settings here are internal constants used by Proof General. You don't need to configure these for your proof assistant unless you want to modify or extend the defaults.

 -- Variable: proof-general-name
     Proof General name used internally and in menu titles.

 -- User Option: proof-proof-general-home-page
     Web address for Proof General

     The default value is "http://www.dcs.ed.ac.uk/home/proofgen".

 -- Variable: proof-universal-keys
     List of keybindings made for the script, goals and response buffer. Elements of the list are tuples (k . f) where k is a keybinding (vector) and f the designated function.

Handling multiple files
=======================

Large proof developments are typically spread across multiple files. Many provers support such developments by keeping track of dependencies and automatically processing scripts. Proof General supports this mechanism. The user's point of view is explored further in Advanced Script Management. Here, we describe the more technical nitty gritty. This is what you need to know when you customise another proof assistant to work with Proof General.

The key idea is that we leave it to the specific proof assistant to worry about managing multiple files. But whenever the proof assistant processes or retracts a file it must clearly say so.

Proof General considers OUTPUT delimited by the the two regular expressions proof-shell-eager-annotation-start and proof-shell-eager-annotation-end as being important. It displays the OUTPUT in the Response buffer and analyses their contents further. Among possibly other important messages characterised by these regular expressions, the prover must tell the interface whenever it processes a file and retracts across file boundaries. The variable proof-included-files-list records the file history.

 -- Variable: proof-included-files-list
     List of files currently included in proof process. This list contains files in canonical truename format.

     Whenever a new file is being processed, it gets added to this list via the proof-shell-process-file configuration settings. When the prover retracts across file boundaries, this list is resynchronised via the proof-shell-retract-files-regexp and proof-shell-compute-new-files-list configuration settings.

     Only files which have been fully processed should be included here. Proof General itself will automatically add the filenames of script buffers which are completely read, when scripting is deactivated or switched to another buffer.

     Currently there is no generic provision for removing files which are only partly read-in due to an error.

You should not set this variable directly. The generic Proof General will modify proof-included-files-list itself. Instead, for a specific proof assistant you need to customise proof-shell-process-file, proof-shell-retract-files-regexp and proof-shell-compute-new-files-list. See Hooks and function variables.

Internals of Proof General
**************************

This chapter sketches some of the internal functions and variables of Proof General, to help developers who wish to understand or modify the code.

Most of the documentation below is generated automatically from the comments in the code.  Because Emacs lisp is interpreted and self-documenting, the best way to find your way around the source is inside Emacs once Proof General is loaded.  Read the source files, and use functions such as C-h v and C-h f.

The code is split into files.  The following sections document the important files, kept in the generic/ subdirectory.

Spans
=====

Spans are an abstraction of XEmacs extents used to help bridge the gulf between FSF GNU Emacs and XEmacs.  In FSF GNU Emacs, spans are implemented using overlays.

See the files span-extent.el and span-overlay.el for the implementation of the common interface in each case.

Proof General site configuration
================================

The file proof-site.el contains the initial configuration for Proof General for the site (or user) and the choice of provers.

The first part of the configuration is to set proof-home-directory to the directory that proof-site.el is located in, or to the variable of the environment variable PROOFGENERAL_HOME if that is set.

 -- Variable: proof-home-directory
     Directory where Proof General is installed. Ends with slash. Default value taken from environment variable PROOFGENERAL_HOME if set, otherwise based on where the file proof-site.el was loaded from. You can use customize to set this variable.

Further directory variables allow the files of Proof General to be split up and installed across a system if need be, rather than under the proof-home-directory root.

 -- Variable: proof-images-directory
     Where Proof General image files are installed. Ends with slash.

 -- Variable: proof-info-directory
     Where Proof General Info files are installed.

After defining these settings, we define a mode stub for each proof assistant enabled.  The mode stub will autoload Proof General for the right proof assistant when a file is visited with the corresponding extension.  The proof assistants enabled are the ones listed in the proof-assistants setting.

 -- User Option: proof-assistants
     Choice of proof assistants to use with Proof General. A list of symbols chosen from: 'isa 'lego 'coq. Each proof assistant defines its own instance of Proof General, providing session control, script management, etc.  Proof General will be started automatically for the assistants chosen here. To avoid accidently invoking a proof assistant you don't have, only select the proof assistants you (or your site) may need. NOTE: to change proof assistant, you must start a new Emacs session.

     The default value is (isa lego coq).

The file proof-site.el also defines a version variable.

 -- Variable: proof-version
     Version string identifying Proof General release.

Global variables
================

Global variables are defined in proof.el.  The same file defines a few utility functions and some triggers to load in the other files.

 -- Variable: proof-script-buffer
     The currently active scripting buffer or nil if none.

 -- Variable: proof-shell-buffer
     Process buffer where the proof assistant is run.

 -- Variable: proof-goals-buffer
     The goals buffer (also known as the pbp buffer).

 -- Variable: proof-buffer-type
     Symbol indicating the type of this buffer: 'script, 'shell, or 'pbp.

 -- Variable: proof-included-files-list
     List of files currently included in proof process. This list contains files in canonical truename format.

     Whenever a new file is being processed, it gets added to this list via the proof-shell-process-file configuration settings. When the prover retracts across file boundaries, this list is resynchronised via the proof-shell-retract-files-regexp and proof-shell-compute-new-files-list configuration settings.

     Only files which have been fully processed should be included here. Proof General itself will automatically add the filenames of script buffers which are completely read, when scripting is deactivated or switched to another buffer.

     Currently there is no generic provision for removing files which are only partly read-in due to an error.

 -- Variable: proof-shell-proof-completed
     Flag indicating that a completed proof has just been observed.

The proof.el also loads proof-config.el which declares the proof assistant configuration variables for Proof General. See Adapting Proof General to New Provers for details.

Proof script mode
=================

The file proof-script.el contains the main code for proof script mode, as well as definitions of menus, keybindings, and user-level functions.

Proof scripts have two important variables for the locked and queue regions.  These variables are local to each script buffer (although we only really need one queue span in total rather than one per buffer).

 -- Variable: proof-locked-span
     The locked span of the buffer. Each script buffer has its own locked span, which may be detached from the buffer. Proof General allows buffers in other modes also to be locked; these also have a non-nil value for this variable.

 -- Variable: proof-queue-span
     The queue span of the buffer.  May be detached if inactive or empty.

Various utility functions manipulate and examine the spans.  An important one is proof-init-segmentation.

 -- Function: proof-init-segmentation
     Initialise the queue and locked spans in a proof script buffer. Allocate spans if need be.  The spans are detached from the buffer, so the locked region is made empty by this function.

For locking files loaded by a proof assistant, we use the next function.

 -- Function: proof-mark-buffer-atomic buffer
     Mark BUFFER as having been processed in a single step.

     If buffer already contains a locked region, only the remainder of the buffer is closed off atomically.

     This works for buffers which are not in proof scripting mode too, to allow other files loaded by proof assistants to be marked read-only.

Atomic locking is instigated by the next function, which uses the variables proof-included-files-list documented earlier (see Handling multiple files and see Global variables).

 -- Function: proof-register-possibly-new-processed-file file
     Register a possibly new FILE as having been processed by the prover.

Another important function activates scripting for the current script buffer.  This may involve switching from one scripting buffer to another.

 -- Function: proof-activate-scripting
     Activate scripting for the current script buffer.

     The current buffer is prepared for scripting.  No changes are necessary if it is already in Scripting minor mode. Otherwise, it will become the current scripting buffer provided the current scripting buffer has either no locked region or everything in it has been processed.

     If we're changing scripting buffer and the old one is associated with a file, add it to proof-included-files-list.

     When a new script buffer has scripting minor mode turned on, the hooks proof-activate-scripting-hook are run.  This can be a useful place to configure the proof assistant for scripting in a particular file, for example, loading the correct theory, or whatever.

     Finally, this may be a good time to ask if the user wants to save some buffers.

The next function is the main one used for parsing the proof script buffer.

 -- Function: proof-segment-up-to pos &optional next-command-end
     Create a list of (type,int,string) tuples from end of locked region to POS. Each tuple denotes the command and the position of its terminator, type is one of 'comment, or 'cmd. 'unclosed-comment may be consed onto the start if the segment finishes with an unclosed comment. If optional NEXT-COMMAND-END is non-nil, we contine past POS until the next command end.

The function proof-semis-to-vanillas is used to convert a parsed region of the script into a series of commands to be sent to the proof assistant.

 -- Function: proof-semis-to-vanillas semis &optional callback-fn
     Convert a sequence of terminator positions to a set of vanilla extents. Proof terminator positions SEMIS has the form returned by the function proof-segment-up-to.

The function proof-assert-until-point is the main one used to process commands in the script buffer.  It's actually used to implement the assert-until-point, active terminator keypress, and find-next-terminator behaviours.  In different cases we want different things, but usually the information (i.e. are we inside a comment) isn't available until we've actually run proof-segment-up-to (point), hence all the different options when we've done so.

 -- Function: proof-assert-until-point &optional unclosed-comment-fun ignore-proof-process-p
     Process the region from the end of the locked-region until point. Default action if inside a comment is just process as far as the start of the comment.

     If you want something different, put it inside UNCLOSED-COMMENT-FUN. If IGNORE-PROOF-PROCESS-P is set, no commands will be added to the queue and the buffer will not be activated for scripting.

proof-assert-next-command is a variant of this function.

 -- Function: proof-assert-next-command &optional unclosed-comment-fun ignore-proof-process-p dont-move-forward for-new-command
     Process until the end of the next unprocessed command after point. If inside a comment, just process until the start of the comment.

     If you want something different, put it inside UNCLOSED-COMMENT-FUN. If IGNORE-PROOF-PROCESS-P is set, no commands will be added to the queue. Afterwards, move forward to near the next command afterwards, unless DONT-MOVE-FORWARD is non-nil.  If FOR-NEW-COMMAND is non-nil, a space or newline will be inserted automatically.

The main command for retracting parts of a script is proof-retract-until-point.

 -- Function: proof-retract-until-point &optional delete-region
     Set up the proof process for retracting until point. In particular, set a flag for the filter process to call proof-done-retracting after the proof process has successfully reset its state. If DELETE-REGION is non-nil, delete the region in the proof script corresponding to the proof command sequence. If invoked outside a locked region, undo the last successfully processed command.

To clean up when scripting is stopped, a script buffer is killed, or the proof assistant exits, we use the functions proof-deactivate-scripting, proof-restart-buffers, and proof-script-remove-all-spans-and-deactivate.

 -- Command: proof-deactivate-scripting
     Deactivate scripting, if the current script buffer is active. Set proof-script-buffer to nil and turn off the modeline indicator. If the locked region doesn't cover the entire file, retract it.

 -- Function: proof-restart-buffers buffers
     Remove all extents in BUFFERS and maybe reset proof-script-buffer. No effect on a buffer which is nil or killed.  If one of the buffers is the current scripting buffer, then proof-script-buffer will deactivated.

 -- Function: proof-script-remove-all-spans-and-deactivate
     Remove all spans from scripting buffers via proof-restart-buffers.

Proof shell mode
================

The proof shell mode code is in the file proof-shell.el.  Proof shell mode is defined to inherit from comint-mode using define-derived-mode near the end of the file.  The bulk of the code in the file is concerned with sending code to and from the shell, and processing output for the associated buffers (goals and response).

Clever process handling is a tricky issue.  Proof General attempts to manage the process strictly, by maintaining a queue of commands to send to the process.  Once a command has been processed, another one is popped off the queue and sent.

There are several important internal variables which control interaction with the process.

 -- Variable: proof-shell-busy
     A lock indicating that the proof shell is processing. When this is non-nil, proof-shell-ready-prover will give an error.

 -- Variable: proof-marker
     Marker in proof shell buffer pointing to previous command input.

 -- Variable: proof-action-list
     A list of

            (SPAN,COMMAND,ACTION)

     triples, which is a queue of things to do. See the functions proof-start-queue and proof-exec-loop.

 -- Variable: proof-analyse-using-stack
     Choice of syntax tree encoding for terms.

     If nil, prover is expected to make no optimisations. If non-nil, the pretty printer of the prover only reports local changes. For LEGO 1.3.1 use nil, for Coq 6.2, use t.

The function proof-shell-start is used to initialise a shell buffer and the associated buffers.

 -- Command: proof-shell-start
     Initialise a shell-like buffer for a proof assistant.

     Also generates goal and response buffers. Does nothing if proof assistant is already running.

The function proof-shell-kill-function performs the converse function of shutting things down; it is used as a hook function for kill-buffer-hook.  Then no harm occurs if the user kills the shell directly, or if it is done more cautiously via proof-shell-exit.  The function proof-shell-restart allows a less drastic way of restarting scripting, other than killing and restarting the process.

 -- Function: proof-shell-kill-function
     Function run when a proof-shell buffer is killed. Attempt to shut down the proof process nicely and clear up all the locked regions and state variables. Value for kill-buffer-hook in shell buffer. Also called by proof-shell-bail-out if the process is exited by hand (or exits by itself).

 -- Command: proof-shell-exit
     Query the user and exit the proof process.

     This simply kills the proof-shell-buffer relying on the hook function proof-shell-kill-function to do the hard work.

 -- Function: proof-shell-bail-out process event
     Value for the process sentinel for the proof assistant process. If the proof assistant dies, run proof-shell-kill-function to cleanup and remove the associated buffers.  The shell buffer is left around so the user may discover what killed the process.

 -- Command: proof-shell-restart
     Clear script buffers and send proof-shell-restart-cmd. All locked regions are cleared and the active scripting buffer deactivated.  The restart command should re-synchronize Proof General with the proof assistant.

Input
.....

Input to the proof shell via the queue region is managed by the functions proof-start-queue and proof-shell-exec-loop.

 -- Function: proof-start-queue start end alist
     Begin processing a queue of commands in ALIST. If START is non-nil, START and END are buffer positions in the active scripting buffer for the queue region.

 -- Function: proof-shell-exec-loop
     Process the proof-action-list.

     proof-action-list contains a list of (SPAN COMMAND ACTION) triples.

     If this function is called with a non-empty proof-action-list, the head of the list is the previously executed command which succeeded. We execute (ACTION SPAN) on the first item, then (ACTION SPAN) on any following items which have proof-no-command as their cmd components.  If a there is a next command, send it to the process. If the action list becomes empty, unlock the process and remove the queue region.

     The return value is non-nil if the action list is now empty.

A useful utility function for sending a single command to the process is proof-shell-invisible-command.  This should be used to implement user-level functions rather than attempting to manipulate the proof action list directly.

 -- Function: proof-shell-invisible-command cmd &optional wait
     Send CMD to the proof process. If optional WAIT command is non-nil, wait for processing to finish before and after sending the command.

Input is actually inserted into the shell buffer and sent to the process by the low-level function proof-shell-insert.

 -- Function: proof-shell-insert string
     Insert STRING at the end of the proof shell, call comint-send-input. First call proof-shell-insert-hook. Then strip STRING of carriage returns before inserting it and updating proof-marker to point to the end of the newly inserted text. NB: This means that any output received up til now but not processed by the proof-shell-filter will be lost!   We must be careful to synchronize with the process.  This function is used particularly in proof-start-queue and proof-shell-exec-loop.

Output
......

Two main functions deal with output, proof-shell-process-output and proof-shell-process-urgent-message.  In effect we consider the output to be two streams intermingled: the "urgent" messages which have "eager" annotations, as well as the ordinary ruminations from the prover.

The idea is to conceal as much irrelevant information from the user as possible; only the remaining output between prompts and after the last urgent message will be a candidate for the goal or response buffer. The variable proof-shell-urgent-message-marker tracks the last urgent message seen.

 -- Function: proof-shell-process-output cmd string
     Process shell output (resulting from CMD) by matching on STRING. CMD is the first part of the proof-action-list that lead to this output. This function deals with errors, start of proofs, abortions of proofs and completions of proofs. All other output from the proof engine is simply reported to the user in the response buffer by setting proof-shell-delayed-output to a cons cell of (INSERT . TEXT) where TEXT is the text to be inserted.

     To extend this function, set proof-shell-process-output-system-specific.

     This function - it can return one of 4 things: 'error, 'interrupt, 'loopback, or nil. 'loopback means this was output from pbp, and should be inserted into the script buffer and sent back to the proof assistant.

 -- Variable: proof-shell-urgent-message-marker
     Marker in proof shell buffer pointing to end of last urgent message.

 -- Function: proof-shell-process-urgent-message message
     Analyse urgent MESSAGE for various cases. Included file, retracted file, cleared response buffer, or if none of these apply, display.

The main processing point which triggers other actions is proof-shell-filter.

 -- Function: proof-shell-filter str
     Filter for the proof assistant shell-process. A function for comint-output-filter-functions.

     Deal with output and issue new input from the queue.

     Handle urgent messages first.  As many as possible are processed, using the function proof-shell-process-urgent-messages.

     Otherwise wait until an annotated prompt appears in the input. If proof-shell-wakeup-char is set, wait until we see that in the output chunk STR.  This optimizes the filter a little bit.

     If a prompt is seen, run proof-shell-process-output on the output between the new prompt and the last input (position of proof-marker) or the last urgent message (position of proof-shell-urgent-message-marker), whichever is later. For example, in this case:

           PROMPT INPUT
           OUTPUT-1
           URGENT-MESSAGE
           OUTPUT-2
           PROMPT

     proof-marker is set after INPUT by proof-shell-insert and proof-shell-urgent-message-marker is set after URGENT-MESSAGE. Only OUTPUT-2 will be processed.  For this reason, error messages and interrupt messages should not be considered urgent messages.

     Output is processed using proof-shell-filter-process-output.

     The first time that a prompt is seen, proof-marker is initialised to the end of the prompt.  This should correspond with initializing the process.  The ordinary output before the first prompt is ignored (urgent messages, however, are always processed).

 -- Function: proof-shell-filter-process-output string
     Subroutine of proof-shell-filter to process output STRING.

     Appropriate action is taken depending on the what proof-shell-process-output returns: maybe handle an interrupt, an error, or deal with ordinary output which is a candidate for the goal or response buffer.  Ordinary output is only displayed when the proof action list becomes empty, to avoid a confusing rapidly changing output.

Credits, History and References
*******************************

Credits
=======

LEGO Proof General (the successor of lego-mode) was crafted by Thomas Kleymann and Dilip Sequeira. It is now maintained by Paul Callaghan <P.C.Callaghan@durham.ac.uk>. Coq Proof General was crafted by Healfdene Goguen. It is now maintained by Patrick Loiseleur <Patrick.Loiseleur@lri.fr>. Isabelle Proof General was crafted and is being maintained by David Aspinall <isabelle@dcs.ed.ac.uk>.

The generic base for Proof General was developed by Kleymann, Sequeira, Goguen and Aspinall (in order of appearance). It follows some of the ideas used in Project CROAP (http://www.inria.fr/croap/). The Proof General project was initiated in 1994 and coordinated until October 1998 by Thomas Kleymann. Since October 1998, David Aspinall is in charge of Proof General.

An early version of this manual was prepared by Dilip Sequeira.  The present version was written by David Aspinall and Thomas Kleymann.

The project has benefited from funding by EPSRC (Applicatins of a Type Theory Based Proof Assistant) and the EC (Types for Proofs and Programs). During the development of Proof General, the following people helped by providing feedback, testing, or code: Pascal Brisset, Rod Burstall, Paul Callaghan, Martin Hofmann, James McKinna, and Markus Wenzel.  Thanks to all of you!

History
=======

It all started some time in 1994. There was no Emacs interface for LEGO. Back then, Emacs militants worked directly with the Emacs shell to interact with the LEGO system.

David Aspinall managed to convince Thomas Kleymann that programming in Emacs Lisp isn't so difficult after all. In fact, Aspinall had at the time already implemented an Emacs interface for Isabelle with bells and whistles, called Isamode (http://www.dcs.ed.ac.uk/home/da/Isamode). Soon after, the package lego-mode was born. Users were able to develop proof scripts in one buffer. Support was provided to automatically send parts of the script to the proof process. The last official version with the name lego-mode (1.9) was released in May 1995.

The interface project really took off the ground in November 1996. Yves Bertot had been working on a sophisticated user interface for the Coq system (CtCoq) based on the generic environment Centaur. He visited the Edinburgh LEGO group for a week to transfer proof-by-pointing technology. Even though proof-by-pointing is an inherently structure-conscious algorithm, within a week, Yves Bertot, Dilip Sequeira and Thomas Kleymann managed to implement a first prototype of proof-by-pointing in the Emacs interface for LEGO.

Perhaps we could reuse even more of the CtCoq system. It being a structure editor did no longer seem to be such an obstacle. Moreover, to conveniently use proof-by-pointing in actual developments, one would need better support for script management.

In 1997, Dilip Sequeira implemented script management in our Emacs interface for LEGO following the recipe in [BT98]  (Notice the publication date. We really do provide cutting-edge technology!). Inspired by the project CROAP, the implementation made some effort to be generic.

In October 1997, Healfdene Goguen ported lego-mode to Coq. Parts of the generic code in the lego package was outsourced (and made even more generic) in a new generic package called proof. Dilip Sequeira wrote a manual and we shipped out the package to friends for testing.

In June 1998, David Aspinall reentered the picture by providing an instantiation for Isabelle. Actually, our previous version wasn't quite as generic as we had hoped. Whereas LEGO and Coq are similar systems in many ways, Isabelle was really a different beast. Fierce reengineering and various improvements were provided by David Aspinall and Thomas Kleymann to really make the code generic.

It was time to come up with a better name than just proof mode. David Aspinall suggested Proof General. He also cooked up some images and a toolbar. Proof General 2.0 is the first official release, ready to conquer the world. Why not adapt Proof General to your favourite proof system?

References
==========

Script management as used in Proof General is described in the paper:

  * [BT98] Yves Bertot and Laurent Théry. A generic approach to building user interfaces for theorem provers. Journal of Symbolic Computation, 25(7), pp. 161-194, February 1998.

Proof General has the beginnings of support for proof by pointing, as described in the document:

  * [BKS97] Yves Bertot, Thomas Kleymann-Schreiber and Dilip Sequeira. Implementing Proof by Pointing without a Structure Editor. LFCS Technical Report ECS-LFCS-97-368. Also published as Rapport de recherche de l'INRIA Sophia Antipolis RR-3286

Obtaining and Installing Proof General
**************************************

Proof General has its own home page (http://www.dcs.ed.ac.uk/home/proofgen) hosted at Edinburgh.  Visit this page for the latest news!

Obtaining Proof General
=======================

You can obtain Proof General from the URL

     http://www.dcs.ed.ac.uk/home/proofgen/download.html.

The distribution is available in three forms

  * A source tarball,
     http://www.dcs.ed.ac.uk/home/proofgen/ProofGeneral-latest.tar.gz

  * A Linux RPM package (for any architecture),
     http://www.dcs.ed.ac.uk/home/proofgen/ProofGeneral-latest.noarch.rpm

  * A developer's tarball,
     http://www.dcs.ed.ac.uk/home/proofgen/ProofGeneral-devel-latest.tar.gz

Both the source tarball and the RPM package include the generic elisp code, code for LEGO, Coq, and Isabelle, installation instructions (reproduced below) and this documentation.

The developer's tarball contains our full source tree, including all of the elisp and documentation, along with our low-level list of things to do, sources for the images, some make files used to generate the release itself from our CVS repository, and some test files.  Developers interested in accessing our CVS repository directly should contact proofgen@dcs.ed.ac.uk.

Installing Proof General from tarball
=====================================

Copy the distribution to some directory MYDIR. Unpack it there. For example:

     # cd MYDIR
     # gunzip ProofGeneral-VERSION.tar.gz
     # tar -xpf ProofGeneral-VERSION.tar

If you downloaded the version called LATEST, you'll find it unpacks to a numeric version number.

Proof General will now be in some subdirectory of MYDIR.  The name of the subdirectory will depend on the version number of Proof General. For example, it might be ProofGeneral-2.0.  It's convenient to link it to a fixed name:

     # ln -sf ProofGeneral-2.0 ProofGeneral

Now put this line in your .emacs file:

         (load-file "MYDIR/ProofGeneral/generic/proof-site.el")

Installing Proof General from RPM package
=========================================

To install an RPM package you need to be root.  Then type

     # rpm -Uvh ProofGeneral-latest.noarch.rpm

Now add the line:

        (load-file "/usr/share/emacs/ProofGeneral/generic/proof-site.el")

to your .emacs or the site-wide initialisation file site-start.el.

Setting the names of binaries
=============================

The load-file command you have added will load proof-site which sets the Emacs load path for Proof General and add auto-loads and modes for the supported assistants.

The default names for proof assistant binaries may work on your system. If not, you will need to set the appropriate variables.  The easiest way to do this (and most other customization of Proof General) is via the Customize mechanism, see the menu item:

       Proof-General -> Customize -> NAME OF ASSISTANT -> Prog Name

The Proof-General menu is available from script buffers after Proof General is loaded.  To load it manually, type

       M-x load-library RET proof RET

Notice that the customization mechanism is only available in Emacs 20.x and XEmacs.  If you cannot use customize, simply add a line like this:

       (setq isabelle-prog-name "/usr/bin/isabelle FOL")

to your .emacs file.

Notes for syssies
=================

Here are some more notes for installing Proof General in more complex ways.  Only attempt things in this section if you really understand what you're doing.

Byte compilation
----------------

Compilation of the Emacs lisp files improves efficiency but can sometimes cause compatibility problems, especially if you use more than one version of Emacs at the same time.  Furthermore, we develop Proof General with source files so may miss problems with the byte compiled versions.  If you discover problems using the byte-compiled .elc files which aren't present using the source .el files, please report them to us.

You can compile Proof General by typing make in the directory where you installed it.

Site-wide installation
----------------------

If you are installing Proof General site-wide, you can put the components in the standard directories of the filesystem if you prefer, providing the variables in proof-site.el are adjusted accordingly, see Proof General site configuration.  Make sure that the generic/ and assistant-specific elisp files are kept in subdirectories (coq/, isa., lego.) of proof-home-directory so that the autoload directory calculations are correct.

To prevent every user needing to edit their own .emacs files, you can put the load-file command to load proof-site.el into site-start.el or similar.  Consult the Emacs documentation for more details if you don't know where to find this file.

Removing support for unwanted provers
-------------------------------------

You cannot run more than one instance of Proof General at a time: so if you're using Coq, visiting an .ML file will not load Isabelle Proof General, and the buffer remains in fundamental mode.  If there are some assistants supported that you never want to use, you can adjust the variable proof-assistants in proof-site.el to remove the extra autoloads.  This is advisable in case the extensions clash with other Emacs modes, for example sml-mode for .ML files, or Verilog mode for .v files.

See Proof General site configuration to find out how to disable support for provers you don't use.

Known bugs and workarounds
**************************

We mention some of the known problems with Proof General here.  The list is not a description of all bugs and may be out of date.

Please consult the file BUGS (http://www.dcs.ed.ac.uk/home/proofgen/ProofGeneral/BUGS) in the distribution for more detailed and up-to-date information.

If you discover a problem which isn't mentioned in BUGS, please let us know by sending a note to proofgen@dcs.ed.ac.uk.

Bugs at the generic level
=========================

Undo in XEmacs
--------------

When proof-strict-read-only is non-nil, ordinary undo in script buffer can edit the "uneditable region" in XEmacs.  This doesn't happen in FSF GNU Emacs.  Test case: Insert some nonsense text after the locked region.  Kill the line. Process to the next command.  Press C-x u, nonsense text appears in locked region.

Workaround: be careful with undo.

Font locking and read-only in FSF GNU Emacs
-------------------------------------------

When proof-strict-read-only is set and font lock is switched on, spurious "Region read only" errors are given which break font lock.

Workaround: turn off proof-strict-read-only, font lock, or for the best of all possible worlds, switch to XEmacs.

Pressing keyboard quit C-g
--------------------------

Using C-g can leave script management in a mess.  The code is not properly protected from Emacs interrupts.

Workaround: Don't type C-g while script management is processing.  If you do, use proof-shell-restart to restart the system.

Bugs specific to LEGO Proof General
===================================

Retraction and Discharge
------------------------

After a Discharge, retraction ought to only be possible back to the first declaration/definition which is discharged. However, LEGO Proof General does not know that Discharge has such a non-local effect. See Granularity of atomic command sequences for a proposal on how to fix this bug.

Workaround: retract back to the first declaration/definition which is discharged.

Retraction and proving
----------------------

Getting retraction right is tricky when working on proofs.

Definitions in a proof state
............................

A thorny issue are local definitions in a proof state. LEGO cannot undo them explicitly.

Workaround: retract back to a command before a definition.

Normalisation in proofs
.......................

Normalisation commands such as Dnf, Hnf Normal cannot be undone in a proof state by Proof General.

Workaround: retract back to the start of the proof.

Not saving proofs.
..................

After LEGO has issued a *** QED *** you may undo steps in the proof as long as you don't issue a Save command or start a new proof. LEGO Proof General assumes that all proofs are terminated with a proper Save command.

Workaround: Always issue a Save command after completing a proof. If you forget one, you should retract to a point before the offending proof development.

Bugs specific to Coq Proof General
==================================

Hard-wired tactics
------------------

The collection of tactics which Proof General is aware of is hard-wired. Thus, user-defined tactics cannot be retracted.

Workaround: You may need to retract to the start of the proof.

Sections
--------

The Coq Proof General does not know about Coq's section mechanism.

Bugs specific to Isabelle Proof General
=======================================

Here are some bugs and problems specific to Isabelle Proof General.

Clash with sml-mode
-------------------

Since Isabelle proof scripts are not differentiated from .ML files, Proof General may compete with sml-mode (if you use it) for controlling these buffers.  To ensure Proof General wins, load it last.

Workaround: use another extension for real ML files, e.g. .sml, and disable .ML from entering sml-mode.

Indentation
-----------

Isabelle Proof General doesn't support Proof General's indentation code to indent proof scripts.  In any case, Proof General's indentation code is somewhat broken.

Workaround: indent your script by hand.

Scripting language limitations
------------------------------

Since Isabelle uses ML as a top-level language for writing proof-scripts, Proof General may have difficulty understanding scripts which stray too far away from the standard functions, tactics, and tacticals.  You will usually notice when a function, or whatever, doesn't get highlighted as you might expect.  This probably has no detrimental impact on the interface unless you use your own variants of the goal or qed forms.

Workaround: Restrict yourself to standard proof script functions, or customize some of the variables from isa.el and isa-syntax.el appropriately.

Interaction with theory database
--------------------------------

Isabelle Proof General has a fragment written in ML which defines a modified interface to the theory database.  In particular, some internal state records which files have been retracted by the interface, although no changes are made inside Isabelle itself.  This means that re-asserting a retracted file does not need to re-load it if it has not changed.  (It is a shame that the standard theory loader provides no such "retraction" mechanism for unlinking loaded theories).

This means that Proof General can get confused if you use the theory loader primitives directly in the proof shell, and the state inside Emacs may not agree with Isabelle.  You have been warned!

Plans and ideas
***************

This section contains some tentative plans and ideas for improving Proof General.  Please send us contributions to this wish list, or better still, offers to implement something from it!

Proof by pointing and similar features
======================================

This is a note by David Aspinall about proof by pointing and similar features.

In fact, Proof General already contains code for proof by pointing, for a reference see History.  However, it is slightly LEGO specific and not robust enough.

Proof-by-pointing requires rather heavy support from the proof assistant.  There are two aspects to the support:

  * term structure mark-up

  * proof by pointing command generation

Term structure mark-up is useful in itself: it allows the user to explore the structure of a term using the mouse (the smallest subexpression that the mouse is over is highlighted), and easily copy subterms from the output to a proof script.

Command generation for proof by pointing might be specific to a particular logic in use, if we hope to generate a proof command unambiguously for any particular click. However, Proof General could easily be generalised to offer the user a context-sensitive choice of next commands to apply, which may be more useful in practice, and a worthy addition to Proof General.

Granularity of atomic command sequences
=======================================

This is a proposal by Thomas Kleymann for generalising the way Proof General handles sequences of proof commands (see Goal-save sequences), particularly to make retraction more flexible.

The locked region of a script buffer contains the initial segment of the proof script which has been processed successfully. It consists of atomic sequences of commands (ACS). Retraction is supported to the beginning of every ACS. By default, every command is an ACS. But the granularity of atomicity should be able to be adjusted.

This is essential when arbitrary retraction is not supported. Usually, after a theorem has been proved, one may only retract to the start of the goal. One needs to mark the proof of the theorem as an ACS. At present, support for goal-save sequences Goal-save sequences has been hard wired. No other ACS are currently supported. We propose the following to overcome this deficiency:

proof-atomic-sequents-list
     is a list of instructions for setting up ACSs. Each instruction is a list of the form (END START &optional FORGET-COMMAND). END is a regular expression to recognise the last command in an ACS. START is a function. Its input is the last command of an ACS. Its output is a regular expression to recognise the first command of the ACS. It is evaluated once and, starting with the command matched by END, the output is successively matched against previously processed commands until a match occurs (or the beginning of the current buffer is reached). The region determined by (START,END) is locked as an ACS. Optionally, the ACS is annotated with the actual command to retract the ACS. This is computed by applying FORGET-COMMAND to the first and last command of the ACS.

     For convenience one might also want to allow START to be the symbol t as a convenient short-hand for '(lambda (str) ".") which always matches.

Browser mode for script files and theories
==========================================

This is a proposal by David Aspinall for a browser window.

A browser window should provide support for browsing script files and theories.  We should be able to inspect data in varying levels of detail, perhaps using outlining mechanisms.  For theories, it would be nice to query the running proof assistant.  This may require support from the assistant in the form of output which has been specially marked-up with an SGML like syntax, for example.

A browser would be useful to:

  * Provide impoverished proof assistants with a browser

  * Extend the uniform interface of Proof General to theory browsing

  * Interact closely with proof script writing

The last point is the most important. We should be able to integrate a search mechanism for proofs of similar theorems, theorems containing particular constants, etc.