lisp.kak (3286B)
1 # http://common-lisp.net 2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 3 4 # Detection 5 # ‾‾‾‾‾‾‾‾‾ 6 7 hook global BufCreate .*[.](lisp) %{ 8 set-option buffer filetype lisp 9 } 10 11 # Initialization 12 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 13 14 hook global WinSetOption filetype=lisp %{ 15 require-module lisp 16 17 hook window ModeChange pop:insert:.* -group lisp-trim-indent lisp-trim-indent 18 hook window InsertChar \n -group lisp-indent lisp-indent-on-new-line 19 set-option buffer extra_word_chars '_' '+' '-' '*' '/' '@' '$' '%' '^' '&' '_' '=' '<' '>' '~' '.' 20 21 hook -once -always window WinSetOption filetype=.* %{ remove-hooks window lisp-.+ } 22 } 23 24 hook -group lisp-highlight global WinSetOption filetype=lisp %{ 25 add-highlighter window/lisp ref lisp 26 hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/lisp } 27 } 28 29 provide-module lisp %{ 30 31 # Highlighters 32 # ‾‾‾‾‾‾‾‾‾‾‾‾ 33 34 add-highlighter shared/lisp regions 35 add-highlighter shared/lisp/code default-region group 36 add-highlighter shared/lisp/string region (?<!#\\)" (?<!\\)(\\\\)*" fill string 37 add-highlighter shared/lisp/comment region ';' '$' fill comment 38 39 add-highlighter shared/lisp/code/ regex (#?(['`:]|,@?))?\b[a-zA-Z][\w!$%&*+./:<=>?@^_~-]* 0:variable 40 add-highlighter shared/lisp/code/ regex \b(nil|true|false)\b 0:value 41 add-highlighter shared/lisp/code/ regex (((\Q***\E)|(///)|(\Q+++\E)){1,3})|(1[+-])|(<|>|<=|=|>=) 0:operator 42 add-highlighter shared/lisp/code/ regex \b(def[a-z]+|if|do|let|lambda|catch|and|assert|while|def|do|fn|finally|let|loop|new|quote|recur|set!|throw|try|var|case|if-let|if-not|when|when-first|when-let|when-not|(cond(->|->>)?))\b 0:keyword 43 add-highlighter shared/lisp/code/ regex \*[a-zA-Z][\w!$%&*+./:<=>?@^_~-]*\* 0:variable 44 add-highlighter shared/lisp/code/ regex (\b\d+)?\.\d+([eEsSfFdDlL]\d+)?\b 0:value 45 46 # Commands 47 # ‾‾‾‾‾‾‾‾ 48 49 define-command -hidden lisp-trim-indent %{ 50 # remove trailing white spaces 51 try %{ execute-keys -draft -itersel x s \h+$ <ret> d } 52 } 53 54 declare-option \ 55 -docstring 'regex matching the head of forms which have options *and* indented bodies' \ 56 regex lisp_special_indent_forms \ 57 '(?:def.*|if(-.*|)|let.*|lambda|with-.*|when(-.*|))' 58 59 define-command -hidden lisp-indent-on-new-line %{ 60 # registers: i = best align point so far; w = start of first word of form 61 evaluate-commands -draft -save-regs '/"|^@iw' -itersel %{ 62 execute-keys -draft 'gk"iZ' 63 try %{ 64 execute-keys -draft '[bl"i<a-Z><gt>"wZ' 65 66 try %{ 67 # If a special form, indent another (indentwidth - 1) spaces 68 execute-keys -draft '"wze<a-k>\A' %opt{lisp_special_indent_forms} '\z<ret>' 69 execute-keys -draft '"wze<a-L>s.{' %sh{printf $(( kak_opt_indentwidth - 1 ))} '}\K.*<ret><a-;>;"i<a-Z><gt>' 70 } catch %{ 71 # If not "special" form and parameter appears on line 1, indent to parameter 72 execute-keys -draft '"wz<a-K>[()\[\]{}]<ret>e<a-l>s\h\K[^\s].*<ret><a-;>;"i<a-Z><gt>' 73 } 74 } 75 try %{ execute-keys -draft '[rl"i<a-Z><gt>' } 76 try %{ execute-keys -draft '[Bl"i<a-Z><gt>' } 77 execute-keys -draft ';"i<a-z>a&,' 78 } 79 } 80 81 }