2014-08-07 15:02:04 +00:00
;; Copyright (c) 2013, 2014 Microsoft Corporation. All rights reserved.
;; Released under Apache 2.0 license as described in the file LICENSE.
;;
;; Author: Leonardo de Moura
;; Soonho Kong
;;
2014-01-08 11:25:05 +00:00
( require 'generic-x )
2014-01-09 19:45:31 +00:00
( require 'compile )
2014-07-28 00:03:06 +00:00
( require 'flymake )
2014-08-07 15:02:04 +00:00
( require 'flycheck )
2014-08-07 15:02:27 +00:00
( require 'fill-column-indicator )
( require 'whitespace-cleanup-mode )
2014-08-07 15:02:04 +00:00
( require 'lean-util )
( require 'lean-settings )
( require 'lean-flycheck )
( require 'lean-input )
( defun lean-compile-string ( exe-name args file-name )
" Concatenate exe-name, args, and file-name "
( format " %s %s %s " exe-name args file-name ) )
2014-01-09 19:45:31 +00:00
2014-08-07 15:02:04 +00:00
( defun lean-create-temp-in-system-tempdir ( filename prefix )
" Create a temp lean file and return its name "
2014-07-28 00:03:06 +00:00
( 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-08-07 15:02:04 +00:00
( let ( ( target-file-name
( lean-get-this-if-true-or-that
( buffer-file-name )
( flymake-init-create-temp-buffer-copy 'lean-create-temp-in-system-tempdir ) ) ) )
( compile ( lean-compile-string
( lean-get-executable lean-executable-name )
( lean-get-this-if-true-or-that arg " " )
target-file-name ) ) ) )
2014-07-29 17:57:52 +00:00
( 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-08-07 15:02:27 +00:00
( when ( and lean-rule-column
lean-show-rule-column-method )
( case lean-show-rule-column-method
( 'vline ( setq fci-rule-column lean-rule-column )
( add-hook 'lean-mode-hook 'fci-mode ) ) ) )
( if lean-delete-trailing-whitespace
( add-hook 'lean-mode-hook 'whitespace-cleanup-mode )
( remove-hook 'lean-mode-hook 'whitespace-cleanup-mode ) )
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)