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 )
( defvar lean-exe " lean "
" Path for the Lean executable " )
( defun lean-execute ( )
" Execute Lean in the current buffer "
( interactive )
( compile ( format " %s %s " lean-exe ( buffer-file-name ) ) ) )
( defun lean-set-keys ( )
( local-set-key " \C -c \C -x " 'lean-execute )
( local-set-key " \C -c \C -l " 'lean-execute ) )
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-01-19 20:03:59 +00:00
' ( " import " " definition " " variable " " variables " " print " " theorem " " axiom " " universe " " alias " " help " " environment " " options " " infix " " infixl " " infixr " " notation " " eval " " check " " exit " " coercion " " end " " using " " namespace " " builtin " " scope " " pop_scope " " set_opaque " " set_option " " rewrite_set " " add_rewrite " " enable_rewrite " " disable_rewrite " ) ;; some keywords
2014-01-11 19:13:20 +00:00
' ( ( " \\ _< \\ (Bool \\ |Int \\ |Nat \\ |Real \\ |Type \\ |TypeU \\ |ℕ \\ |ℤ \\ ) \\ _> " . 'font-lock-type-face )
2014-01-19 18:32:45 +00:00
( " \\ _< \\ (calc \\ |have \\ |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 )
( " \\ _< \\ ( \\ b.*_tac \\ |Cond \\ |OrElse \\ |T \\ (?:hen \\ |ry \\ ) \\ |When \\ |apply \\ |b \\ (?:ack \\ |eta \\ ) \\ |done \\ |exact \\ ) \\ _> " . 'font-lock-constant-face )
2014-01-10 04:44:01 +00:00
( " \\ (universe \\ |theorem \\ |axiom \\ |definition \\ |variable \\ |builtin \\ )[ \t ]* \\ ([^ \t \n ]* \\ ) " ( 2 'font-lock-function-name-face ) )
( " variables[ \t ] \\ ([^:]* \\ ) " ( 1 'font-lock-function-name-face ) )
( " \\ (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-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)