coq.kak (5616B)
1 2 # Detection 3 # -------- 4 5 hook global BufCreate .*\.v %{ 6 set-option buffer filetype coq 7 } 8 9 # Initialization 10 # -------------- 11 12 hook global WinSetOption filetype=coq %{ 13 require-module coq 14 hook window ModeChange pop:insert:.* -group coq-trim-indent coq-trim-indent 15 hook window InsertChar \n -group coq-indent coq-copy-indent-on-newline 16 17 set-option window static_words %opt{coq_static_words} 18 add-highlighter window/coq ref coq 19 20 hook -once -always window WinSetOption filetype=.* %{ 21 remove-highlighter window/coq 22 remove-hooks window coq-indent 23 } 24 } 25 26 provide-module coq %{ 27 28 # Syntax 29 # ------ 30 31 # This is a `looks sensible' keyword syntax highlighting, far from being correct. 32 # Note that only the core language and the proof language is supported, 33 # the Ltac language is not (for now). 34 35 add-highlighter shared/coq regions 36 37 add-highlighter shared/coq/comment region -recurse \Q(* \Q(* \Q*) fill comment 38 add-highlighter shared/coq/string region (?<!")" (?<!")("")*" fill string 39 40 add-highlighter shared/coq/command default-region group 41 42 # This is not any lexical convention of coq, simply highlighting used to make 43 # proofs look better, based on how people usually use notations 44 add-highlighter shared/coq/command/ regex [`!@#$%^&*-=+\\:\;|<>/]+ 0:operator 45 add-highlighter shared/coq/command/ regex \(dfs\)|\(bfs\) 0:operator 46 add-highlighter shared/coq/command/ regex [()\[\]{}] 0:operator 47 48 # numeral literals 49 add-highlighter shared/coq/command/ regex [-]?[0-9][0-9_]*(\.[0-9_]+)?([eE][+-][0-9_]+)? 0:value 50 51 evaluate-commands %sh{ 52 # These are builtin keywords of the Gallina language (without tactics) 53 keywords="_ IF Prop SProp Set Type as at by cofix discriminated else end exists exists2 fix for" 54 keywords="${keywords} forall fun if in lazymatch let match multimatch return then using where with" 55 keywords="${keywords} inside outside" 56 57 # These are (part of) coq top level commands 58 commands="Abort About Add Admitted All Arguments Axiom Back BackTo" 59 commands="${commands} Canonical Cd Check Coercion CoFixpoint Collection Compute Conjecture Context Contextual Corollary" 60 commands="${commands} Declare Defined Definition Delimit Drop End Eval Example Existential Export" 61 commands="${commands} Fact Fail File Fixpoint Focus From Function Generalizable Global Goal Grab" 62 commands="${commands} Hint Hypotheses Hypothesis Immediate Implicit Import Include Inductive" 63 commands="${commands} Lemma Let Library Load LoadPath Local Locate Module No Notation Opaque" 64 commands="${commands} Parameter Parameters Primitive Print Proof Property Proposition Pwd Qed Quit" 65 commands="${commands} Rec Record Redirect Register Remark Remove Require Reset" 66 commands="${commands} Section Search SearchAbout SearchHead SearchPattern SearchRewrite Show Strategy" 67 commands="${commands} Test Theorem Time Timeout Transparent Types Universes Undo Unfocus Unfocused Unset Variable Variables" 68 69 # These are (part of) coq's builtin tactics 70 tactics="abstract absurd admit all apply assert assert_fails" 71 tactics="${tactics} assert_succeeds assumption auto autoapply" 72 tactics="${tactics} autorewrite autounfold btauto by case cbn" 73 tactics="${tactics} cbv change clear clearbody cofix compare" 74 tactics="${tactics} compute congr congruence constructor contradict" 75 tactics="${tactics} cut cutrewrite cycle decide decompose dependent" 76 tactics="${tactics} destruct discriminate do done double" 77 tactics="${tactics} eapply eassert eauto eexact elim elimtype exact exfalso" 78 tactics="${tactics} fail field first firstorder fix fold functional" 79 tactics="${tactics} generalize guard have hnf idtac induction injection" 80 tactics="${tactics} instantiate intro intros intuition inversion" 81 tactics="${tactics} inversion_clear lapply lazy last move omega" 82 tactics="${tactics} pattern pose progress red refine reflexivity" 83 tactics="${tactics} remember rename repeat replace rewrite right ring" 84 tactics="${tactics} set setoid_reflexivity setoid_replace setoid_rewrite" 85 tactics="${tactics} setoid_symmetry setoid_transitivity simpl simple" 86 tactics="${tactics} simplify_eq solve specialize split start stop" 87 tactics="${tactics} subst symmetry tauto transitivity trivial try" 88 tactics="${tactics} under unfold unify unlock" 89 90 echo declare-option str-list coq_static_words ${keywords} ${commands} ${tactics} 91 92 keywords_regex=$(echo ${keywords} | tr ' ' '|') 93 printf %s " 94 add-highlighter shared/coq/command/ regex \b(${keywords_regex})\b 0:keyword 95 " 96 commands_regex=$(echo ${commands} | tr ' ' '|') 97 printf %s " 98 add-highlighter shared/coq/command/ regex ^[\h\n]*(${commands_regex})\b 0:variable 99 " 100 101 tactics_regex=$(echo ${tactics} | tr ' ' '|') 102 printf %s " 103 add-highlighter shared/coq/command/ regex \b(${tactics_regex})\b 0:keyword 104 " 105 } 106 107 # Indentation 108 # ----------- 109 # Coq's syntax is based heavily on keywords and program structure, 110 # not based on explicit, unique delimiters, like braces in C-family. 111 # So it is difficult to properly indent using only regex... 112 # Hence here only a simple mechanism of copying indent is done. 113 define-command -hidden coq-copy-indent-on-newline %{ 114 evaluate-commands -draft -itersel %{ 115 try %{ execute-keys -draft k x s ^\h+ <ret> y gh j P } 116 } 117 } 118 119 define-command -hidden coq-trim-indent %{ 120 evaluate-commands -no-hooks -draft -itersel %{ 121 execute-keys x 122 # remove trailing white spaces 123 try %{ execute-keys -draft s \h + $ <ret> d } 124 } 125 } 126 127 }