2014-01-08 11:25:05 +00:00
( require 'generic-x )
2014-01-09 17:32:47 +00:00
( require 'lean-input )
2014-01-09 19:45:31 +00:00
( require 'compile )
2014-07-28 00:03:06 +00:00
( require 'flymake )
2014-01-09 19:45:31 +00:00
( defvar lean-exe " lean "
" Path for the Lean executable " )
2014-07-28 00:03:06 +00:00
( defun flymake-create-temp-lean-in-system-tempdir ( filename prefix )
( make-temp-file ( or prefix " flymake " ) nil " .lean " ) )
2014-07-29 17:57:52 +00:00
( defun lean-execute ( &optional arg )
2014-01-09 19:45:31 +00:00
" Execute Lean in the current buffer "
2014-07-29 17:57:52 +00:00
( interactive " sarg: " )
2014-07-28 00:03:06 +00:00
( if ( buffer-file-name )
2014-07-29 17:57:52 +00:00
( compile ( format " %s %s %s " lean-exe ( if arg arg " " ) ( buffer-file-name ) ) )
( compile ( format " %s $s %s " lean-exe ( if arg arg " " ) ( flymake-init-create-temp-buffer-copy ) 'flymake-create-temp-lean-in-system-tempdir ) ) ) )
( defun lean-std-exe ( )
( interactive )
( lean-execute ) )
( defun lean-hott-exe ( )
( interactive )
( lean-execute " --hott " ) )
2014-01-09 19:45:31 +00:00
( defun lean-set-keys ( )
2014-07-29 17:57:52 +00:00
( local-set-key " \C -c \C -x " 'lean-std-exe )
( local-set-key " \C -c \C -l " 'lean-std-exe )
( local-set-key " \C -c \C -k " 'lean-hott-exe ) )
2014-01-08 11:25:05 +00:00
2014-01-10 03:57:00 +00:00
( define-abbrev-table 'lean-mode-abbrev-table ' (
( " var " " variable " )
( " vars " " variables " )
( " def " " definition " )
( " th " " theorem " )
) )
2014-01-08 11:25:05 +00:00
( define-generic-mode
'lean-mode ;; name of the mode to create
' ( " -- " ) ;; comments start with
2014-07-31 23:49:19 +00:00
' ( " import " " abbreviation " " opaque_hint " " tactic_hint " " definition " " renaming " " inline " " hiding " " exposing " " parameter " " parameters " " proof " " qed " " conjecture " " hypothesis " " lemma " " corollary " " variable " " variables " " print " " theorem " " axiom " " inductive " " with " " structure " " universe " " alias " " help " " environment " " options " " precedence " " postfix " " prefix " " calc_trans " " calc_subst " " calc_refl " " infix " " infixl " " infixr " " notation " " eval " " check " " exit " " coercion " " end " " private " " using " " namespace " " builtin " " including " " instance " " section " " set_option " " add_rewrite " " extends " ) ;; some keywords
2014-07-22 16:43:18 +00:00
' ( ( " \\ _< \\ (bool \\ |int \\ |nat \\ |real \\ |Prop \\ |Type \\ |ℕ \\ |ℤ \\ ) \\ _> " . 'font-lock-type-face )
2014-07-11 03:08:51 +00:00
( " \\ _< \\ (calc \\ |have \\ |obtains \\ |show \\ |by \\ |in \\ |let \\ |forall \\ |fun \\ |exists \\ |if \\ |then \\ |else \\ |assume \\ |take \\ |obtain \\ |from \\ ) \\ _> " . font-lock-keyword-face )
2014-01-08 11:25:05 +00:00
( " \" [^ \" ]* \" " . 'font-lock-string-face )
2014-01-17 18:14:57 +00:00
( " \\ (-> \\ |↔ \\ |/ \\ \\ \\ |== \\ | \\ \\ / \\ |[*+/<=>¬∧∨≠≤≥-] \\ ) " . 'font-lock-constant-face )
2014-01-11 19:13:20 +00:00
( " \\ (λ \\ |→ \\ |∃ \\ |∀ \\ |: \\ |:= \\ ) " . font-lock-constant-face )
2014-07-03 01:37:53 +00:00
( " \\ _< \\ ( \\ b.*_tac \\ |Cond \\ |or_else \\ |t \\ (?:hen \\ |ry \\ ) \\ |when \\ |assumption \\ |apply \\ |b \\ (?:ack \\ |eta \\ ) \\ |done \\ |exact \\ ) \\ _> " . 'font-lock-constant-face )
2014-07-31 23:49:19 +00:00
( " \\ _< \\ (universe \\ |inductive \\ |theorem \\ |axiom \\ |lemma \\ |hypothesis \\ |abbreviation \\ |definition \\ |variable \\ |parameter \\ ) \\ _>[ \t \{ \[ ]* \\ ([^ \t \n ]* \\ ) " ( 2 'font-lock-function-name-face ) )
2014-07-17 19:48:06 +00:00
( " \\ _< \\ (variables \\ |parameters \\ ) \\ _>[ \t \( \{ \[ ]* \\ ([^:]* \\ ) " ( 2 'font-lock-function-name-face ) )
2014-01-10 04:44:01 +00:00
( " \\ (set_opaque \\ |set_option \\ )[ \t ]* \\ ([^ \t \n ]* \\ ) " ( 2 'font-lock-constant-face ) )
2014-01-11 19:13:20 +00:00
( " \\ _<_ \\ _> " . 'font-lock-preprocessor-face )
2014-08-01 01:35:57 +00:00
( " \\ _<sorry \\ _> " . 'font-lock-warning-face )
2014-01-10 04:10:57 +00:00
;;
)
2014-01-08 11:25:05 +00:00
' ( " \\ .lean$ " ) ;; files for which to activate this mode
' ( ( lambda ( )
2014-01-09 17:32:47 +00:00
( set-input-method " Lean " )
2014-01-09 17:48:18 +00:00
( set ( make-local-variable 'lisp-indent-function )
'common-lisp-indent-function )
2014-01-09 19:45:31 +00:00
( lean-set-keys )
2014-01-10 03:57:00 +00:00
( setq local-abbrev-table lean-mode-abbrev-table )
( abbrev-mode 1 )
2014-01-09 17:48:18 +00:00
) )
2014-01-08 11:25:05 +00:00
" A mode for Lean files " ;; doc string for this mode
)
2014-01-09 17:32:47 +00:00
( provide 'lean-mode )
2014-01-08 11:25:05 +00:00
; (regexp-opt '("Int" "Bool" "Nat" "Type" "Real") t)
; (regexp-opt '("let" "in" "have" "calc" "forall" "exists") t)
; (regexp-opt '("=" "->" "≠" "∨ " "∧" "¬" "/\\" "\\/" "+" "-" "*" "/" "<" ">" "≤" "≥" "==" "∀" "∃" "→" "λ" ":") t)
2014-01-10 04:10:57 +00:00
; (regexp-opt '("apply" "exact" "trivial" "absurd" "beta" "apply" "unfold" "done" "back" "Try" "Then" "OrElse" "OrElse" "Cond" "When" "unfold_all" ) t)