; isa-mode.el Emacs support for Isabelle proof assistant ;; Copyright (C) 1993-2000 LFCS Edinburgh, David Aspinall. ;; License: GPL (GNU GENERAL PUBLIC LICENSE) ;; Author: David Aspinall ;; ;; $Id$ ;; ;; ----------------------------------------------------------------- ;; ;; This file and the rest of Isabelle Proof General contain code taken ;; from David Aspinall's Isamode system, a personal project undertaken ;; 1993-1999 as a contribution to the Isabelle community. ;; ;; ----------------------------------------------------------------- ;; In case Isa mode was invoked directly or by -*- isa -*- at ;; the start of the file, ensure that Isa mode is used from now ;; on for .thy and .ML files. ;; FIXME: be less messy with auto-mode-alist here (remove dups) (setq auto-mode-alist (cons '("\\.ML$\\|\\.thy$" . isa-mode) auto-mode-alist)) (require 'proof) (require 'isa-syntax) (require 'isabelle-system) ;;; ;;; ======== User settings for Isabelle ======== ;;; ;;; proof-site provides us with the cusomization groups ;;; ;;; 'isabelle - User options for Isabelle Proof General ;;; 'isabelle-config - Configuration of Isabelle Proof General ;;; (constants, but may be nice to tweak) ;;; ;;; ======== Configuration of generic modes ======== ;;; (defcustom isa-outline-regexp (proof-ids-to-regexp '("goal" "Goal" "prove_goal")) "Outline regexp for Isabelle ML files" :type 'regexp :group 'isabelle-config) ;;; End of a command needs parsing to find, so this is approximate. (defcustom isa-outline-heading-end-regexp ";[ \t\n]*" "Outline heading end regexp for Isabelle ML files." :type 'regexp :group 'isabelle-config) (defvar isa-shell-outline-regexp "\370[ \t]*\\([0-9]+\\)\\.") (defvar isa-shell-outline-heading-end-regexp "$") (defun isa-mode-config-set-variables () "Configure generic proof scripting/thy mode variables for Isabelle. Settings here are the ones which are needed for both shell mode and script mode." (setq proof-assistant-home-page isabelle-web-page proof-mode-for-script 'isa-proofscript-mode ;; proof script syntax proof-terminal-char ?\; ; ends a proof proof-script-comment-start "(*" ; comment in a proof proof-script-comment-end "*)" ; ;; Next few used for func-menu and recognizing goal..save regions in ;; script buffer. proof-save-command-regexp isa-save-command-regexp proof-goal-command-regexp isa-goal-command-regexp proof-goal-with-hole-regexp isa-goal-with-hole-regexp proof-save-with-hole-regexp isa-save-with-hole-regexp ;; Unfortunately the default value of proof-script-next-entity-regexps ;; is no good, because goals with holes in Isabelle are batch ;; commands, and not terminated by saves. So we omit the forward ;; search from the default value. proof-script-next-entity-regexps (list (proof-regexp-alt isa-goal-with-hole-regexp isa-save-with-hole-regexp) (list isa-goal-with-hole-regexp 2) (list isa-save-with-hole-regexp 2 'backward isa-goal-command-regexp)) proof-indent-enclose-offset (- proof-indent) proof-indent-open-offset 0 proof-indent-close-offset 0 proof-indent-any-regexp isa-indent-any-regexp proof-indent-inner-regexp isa-indent-inner-regexp proof-indent-enclose-regexp isa-indent-enclose-regexp proof-indent-open-regexp isa-indent-open-regexp proof-indent-close-regexp isa-indent-close-regexp ;; proof engine commands proof-showproof-command "pr();" proof-goal-command "Goal \"%s\";" proof-save-command "qed \"%s\";" proof-context-command "ProofGeneral.show_context();" proof-info-command "ProofGeneral.help();" proof-kill-goal-command "ProofGeneral.kill_goal();" proof-find-theorems-command "ProofGeneral.thms_containing (space_explode \",\" \"%s\");" proof-shell-start-silent-cmd "Goals.disable_pr();" proof-shell-stop-silent-cmd "Goals.enable_pr();" ;; command hooks proof-goal-command-p 'isa-goal-command-p proof-count-undos-fn 'isa-count-undos proof-find-and-forget-fn 'isa-find-and-forget proof-state-preserving-p 'isa-state-preserving-p ;; close goal..save regions eagerly proof-completed-proof-behaviour 'closeany proof-shell-compute-new-files-list 'isa-shell-compute-new-files-list proof-shell-inform-file-processed-cmd "ProofGeneral.inform_file_processed \"%s\";" proof-shell-inform-file-retracted-cmd "ProofGeneral.inform_file_retracted \"%s\";" ;; span menu proof-script-span-context-menu-extensions 'isabelle-create-span-menu ;; Parsing error messages. Bit tricky to allow for ;; multitude of possible error formats Isabelle spits out. ;; Ideally we shouldn't bother parsing errors that appear ;; in the temporary ML files generated while reading ;; theories, but unfortunately the user sometimes needs to ;; examine them to understand a strange problem... pg-next-error-regexp "\\(error on \\|Error: in '[^']+', \\)line \\([0-9]+\\)\\|The error(s) above occurred" pg-next-error-filename-regexp "\\(Loading theory \"\\|Error: in '\\)\\([^\"']+\\)[\"']" pg-next-error-extract-filename "%s.thy")) (defun isa-shell-mode-config-set-variables () "Configure generic proof shell mode variables for Isabelle." (setq pg-subterm-first-special-char ?\350 proof-shell-wakeup-char ?\372 proof-shell-annotated-prompt-regexp "\\(val it = () : unit\n\\)?> \372" ;; This pattern is just for comint proof-shell-prompt-pattern "^2?[ML-=#>]>? \372?" ;; for issuing command, not used to track cwd in any way. proof-shell-cd-cmd "ThyLoad.add_path \"%s\";" ;; Escapes for filenames inside ML strings. ;; We also make a hack for Isabelle, by switching from backslashes ;; to forward slashes if it looks like we're running on Windows. proof-shell-filename-escapes (if (fboundp 'win32-long-file-name) ; rough test for XEmacs on win32 ;; Patterns to unixfy names. Avoids a deliberate bomb in Isabelle which ;; barfs at paths with these characters in them. '(("\\\\" . "/") ("\"" . "\\\"") ("^[a-zA-Z]:" . "")) ;; Normal case: quotation for backslash, quote mark. '(("\\\\" . "\\\\") ("\"" . "\\\""))) proof-shell-interrupt-regexp "Interrupt" proof-shell-error-regexp "^\364\\*\\*\\*\\|^.*Error:\\|^uncaught exception \\|^Exception-\\( \\|$\\)" ;; matches names of assumptions proof-shell-assumption-regexp isa-id ;; matches subgoal name ;; FIXME: not used yet. In future will be used for ;; proof-by-pointing like features. ;; proof-shell-goal-regexp "\370[ \t]*\\([0-9]+\\)\\." proof-shell-start-goals-regexp "\366" proof-shell-end-goals-regexp "\367" pg-topterm-char ?\370 proof-shell-proof-completed-regexp "^No subgoals!" ;; initial command configures Isabelle by hacking print functions, ;; restoring settings saved by Proof General, etc. proof-shell-pre-sync-init-cmd "ProofGeneral.init false;" proof-shell-init-cmd '(proof-assistant-settings-cmd) proof-shell-restart-cmd "ProofGeneral.isa_restart();" proof-shell-quit-cmd "quit();" ;; NB: settings below only recognize tracing output in Isabelle2002 proof-shell-eager-annotation-start "\360\\|\362" proof-shell-eager-annotation-start-length 1 proof-shell-eager-annotation-end "\361\\|\363" ;; see isa-pre-shell-start for proof-shell-trace-output-regexp ;; Isabelle is learning to talk PGIP... proof-shell-match-pgip-cmd "