2014-07-21 02:53:21 +04:00
|
|
|
# http://common-lisp.net
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](lisp) %{
|
2017-11-03 10:34:41 +03:00
|
|
|
set-option buffer filetype lisp
|
2014-07-21 02:53:21 +04:00
|
|
|
}
|
|
|
|
|
2019-04-10 06:54:19 +03:00
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=lisp %{
|
2019-03-13 08:24:33 +03:00
|
|
|
require-module lisp
|
2019-04-10 06:54:19 +03:00
|
|
|
|
2019-10-16 12:19:43 +03:00
|
|
|
hook window ModeChange pop:insert:.* -group lisp-trim-indent lisp-trim-indent
|
2019-04-10 06:54:19 +03:00
|
|
|
hook window InsertChar \n -group lisp-indent lisp-indent-on-new-line
|
2019-07-06 22:25:46 +03:00
|
|
|
set-option buffer extra_word_chars '_' '+' '-' '*' '/' '@' '$' '%' '^' '&' '_' '=' '<' '>' '~' '.'
|
2019-04-10 06:54:19 +03:00
|
|
|
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window lisp-.+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
hook -group lisp-highlight global WinSetOption filetype=lisp %{
|
|
|
|
add-highlighter window/lisp ref lisp
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/lisp }
|
2019-03-13 08:24:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
provide-module lisp %{
|
|
|
|
|
2014-07-21 02:53:21 +04:00
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-06-30 02:49:57 +03:00
|
|
|
add-highlighter shared/lisp regions
|
|
|
|
add-highlighter shared/lisp/code default-region group
|
2018-07-02 13:59:12 +03:00
|
|
|
add-highlighter shared/lisp/string region '"' (?<!\\)(\\\\)*" fill string
|
|
|
|
add-highlighter shared/lisp/comment region ';' '$' fill comment
|
2014-07-21 02:53:21 +04:00
|
|
|
|
2018-06-30 02:49:57 +03:00
|
|
|
add-highlighter shared/lisp/code/ regex \b(nil|true|false)\b 0:value
|
|
|
|
add-highlighter shared/lisp/code/ regex (((\Q***\E)|(///)|(\Q+++\E)){1,3})|(1[+-])|(<|>|<=|=|>=) 0:operator
|
|
|
|
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
|
2018-08-13 20:48:53 +03:00
|
|
|
add-highlighter shared/lisp/code/ regex (#?(['`:]|,@?))?\b[a-zA-Z][\w!$%&*+./:<=>?@^_~-]* 0:variable
|
|
|
|
add-highlighter shared/lisp/code/ regex \*[a-zA-Z][\w!$%&*+./:<=>?@^_~-]*\* 0:variable
|
2018-08-13 20:49:15 +03:00
|
|
|
add-highlighter shared/lisp/code/ regex (\b\d+)?\.\d+([eEsSfFdDlL]\d+)?\b 0:value
|
2014-07-21 02:53:21 +04:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-12-19 12:10:26 +03:00
|
|
|
define-command -hidden lisp-trim-indent %{
|
2015-11-04 12:48:47 +03:00
|
|
|
# remove trailing white spaces
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
|
2014-07-21 02:53:21 +04:00
|
|
|
}
|
|
|
|
|
2018-09-28 14:28:21 +03:00
|
|
|
declare-option \
|
|
|
|
-docstring 'regex matching the head of forms which have options *and* indented bodies' \
|
|
|
|
regex lisp_special_indent_forms \
|
|
|
|
'(?:def.*|if(-.*|)|let.*|lambda|with-.*|when(-.*|))'
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command -hidden lisp-indent-on-new-line %{
|
2018-09-28 14:28:21 +03:00
|
|
|
# registers: i = best align point so far; w = start of first word of form
|
|
|
|
evaluate-commands -draft -save-regs '/"|^@iw' -itersel %{
|
|
|
|
execute-keys -draft 'gk"iZ'
|
|
|
|
try %{
|
|
|
|
execute-keys -draft '[bl"i<a-Z><gt>"wZ'
|
|
|
|
|
2019-02-04 20:23:57 +03:00
|
|
|
try %{
|
|
|
|
# If a special form, indent another (indentwidth - 1) spaces
|
|
|
|
execute-keys -draft '"wze<a-k>\A' %opt{lisp_special_indent_forms} '\z<ret>'
|
|
|
|
execute-keys -draft '"wze<a-L>s.{' %sh{printf $(( kak_opt_indentwidth - 1 ))} '}\K.*<ret><a-;>;"i<a-Z><gt>'
|
|
|
|
} catch %{
|
|
|
|
# If not "special" form and parameter appears on line 1, indent to parameter
|
2020-01-03 22:56:21 +03:00
|
|
|
execute-keys -draft '"wz<a-K>[()\[\]{}]<ret>e<a-l>s\h\K[^\s].*<ret><a-;>;"i<a-Z><gt>'
|
2019-02-04 20:23:57 +03:00
|
|
|
}
|
2018-09-28 14:28:21 +03:00
|
|
|
}
|
|
|
|
try %{ execute-keys -draft '[rl"i<a-Z><gt>' }
|
|
|
|
try %{ execute-keys -draft '[Bl"i<a-Z><gt>' }
|
2018-10-29 19:16:13 +03:00
|
|
|
execute-keys -draft ';"i<a-z>a&<space>'
|
2014-07-21 02:53:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 08:24:33 +03:00
|
|
|
}
|