Merge remote-tracking branch 'in0ni/master'

This commit is contained in:
Maxime Coste 2022-04-25 19:31:16 +10:00
commit bb742eda0f
4 changed files with 316 additions and 33 deletions

View File

@ -15,9 +15,11 @@ hook global WinSetOption filetype=css %[
require-module css
hook window ModeChange pop:insert:.* -group css-trim-indent css-trim-indent
hook window InsertChar \n -group css-insert css-insert-on-new-line
hook window InsertChar \n -group css-indent css-indent-on-new-line
hook window InsertChar \} -group css-indent css-indent-on-closing-curly-brace
set-option buffer extra_word_chars '_' '-'
set-face global cssLogicalOperator +i@keyword
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window css-.+ }
]
@ -32,28 +34,78 @@ provide-module css %[
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
add-highlighter shared/css regions
add-highlighter shared/css/selector default-region group
add-highlighter shared/css/declaration region [{] [}] regions
add-highlighter shared/css/comment region /[*] [*]/ fill comment
add-highlighter shared/css/code default-region group
add-highlighter shared/css/attr_selector region \[ \] regions
add-highlighter shared/css/double_string region '"' (?<!\\)(\\\\)*" fill string
add-highlighter shared/css/single_string region "'" (?<!\\)(\\\\)*' fill string
add-highlighter shared/css/comment region /\* \*/ fill comment
add-highlighter shared/css/declaration/base default-region group
add-highlighter shared/css/declaration/double_string region '"' (?<!\\)(\\\\)*" fill string
add-highlighter shared/css/declaration/single_string region "'" "'" fill string
add-highlighter shared/css/declaration/comment region /[*] [*]/ fill comment
evaluate-commands %sh{
# html tags
# generated from the URL & <code> below
# includes elements that cannot be styled, which is fine.
#
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element
html_tags='html body address article aside footer header h1 h2 h3 h4 h5 h6 main nav section blockquote dd div dl dt figcaption figure hr li ol p pre ul a abbr b bdi bdo br cite code data dfn em i kbd mark q rp rt ruby s samp small span strong sub sup time u var wbr area audio img map track video embed iframe object param picture portal source canvas noscript script del ins caption col colgroup table tbody td tfoot th thead tr button datalist fieldset form input label legend meter optgroup option output progress select textarea details dialog menu summary slot template acronym applet basefont bgsound big blink center content dir font frame frameset hgroup image keygen marquee menuitem nobr noembed noframes plaintext rb rtc shadow spacer strike tt xmp'
# https://developer.mozilla.org/en-US/docs/Web/CSS/length
add-highlighter shared/css/declaration/base/ regex (#[0-9A-Fa-f]+)|((\d*\.)?\d+(ch|cm|em|ex|mm|pc|pt|px|rem|vh|vmax|vmin|vw)) 0:value
# Units
# ‾‾‾‾‾
# generated from the URL & <code> below
# includes #rgb, #rrggbb, #rrggbbaa as color values {3,8}
#
# https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Values_and_Units
units='% cap ch cm deg dpcm dpi dppx em ex grad Hz ic in kHz lh mm ms pc pt px Q rad rem rlh s turn vb vh vi vmax vmin vw x'
add-highlighter shared/css/declaration/base/ regex ([A-Za-z][A-Za-z0-9_-]*)\h*: 1:keyword
add-highlighter shared/css/declaration/base/ regex :(before|after) 0:attribute
add-highlighter shared/css/declaration/base/ regex !important 0:keyword
logical_ops='and not only from to'
keywords='!important auto inherit initial unset none'
media_types='all print screen speech'
# element#id element.class
# universal selector
add-highlighter shared/css/selector/ regex [A-Za-z][A-Za-z0-9_-]* 0:keyword
add-highlighter shared/css/selector/ regex [*]|[#.][A-Za-z][A-Za-z0-9_-]* 0:variable
# easing_re='linear|ease(-(in-out|in|out))?|step-(start|end)'
# combinators='+ > ~ ||'
# attribute_op='= ~= |= ^= $= *='
join() { eval set -- $1; IFS="|"; echo "$*"; }
# Selectors
# ‾‾‾‾‾‾‾‾‾
# universal: *, ns|*, *|*, |*
# class/id: .class, #id
# type: element
# attr: [attr=val]
# order below matters
printf %s "
add-highlighter shared/css/code/tag_selectors regex \b($(join "${html_tags}"))((:[a-z:])|[\h.#,]) 1:keyword
add-highlighter shared/css/code/functional_notation regex ([a-zA-Z0-9-_]+[a-zA-Z0-9])\( 1:keyword
add-highlighter shared/css/code/logical_operators regex (\b($(join "${logical_ops}"))\b|$(join "${keywords}")) 1:cssLogicalOperator
add-highlighter shared/css/code/media_types regex \b($(join "${media_types}"))\b 1:+i
# (after functional notation as they may contain paranthesis)
add-highlighter shared/css/code/pseudo regex (:{1,2})([a-z-]+) 0:attribute
add-highlighter shared/css/code/at_rules regex @[a-z-]+ 0:function
add-highlighter shared/css/code/css_property regex ([A-Za-z][A-Za-z0-9_-]*)\h*:\h 1:operator 1:+a
add-highlighter shared/css/code/selectors regex (\*|[*]?[.][A-Za-z][A-Za-z0-9_-]+) 0:type
add-highlighter shared/css/code/selectors_id regex (\*|[*]?[#][A-Za-z][A-Za-z0-9_-]+) 0:type 0:+i
add-highlighter shared/css/code/hex_values regex (#[0-9A-Fa-f]{3,8})\b 0:value 0:+a
add-highlighter shared/css/code/units regex \b(\d*\.)?\d+($(join "${units}"))?\b 0:value 0:+a
"
}
# Attribute Selectors
add-highlighter shared/css/attr_selector/base default-region group
add-highlighter shared/css/attr_selector/base/ regex ([a-zA-Z0-9-]+) 1:attribute
add-highlighter shared/css/attr_selector/base/ regex \h(i|s) 1:type
add-highlighter shared/css/attr_selector/double_string region '"' (?<!\\)(\\\\)*" fill string
add-highlighter shared/css/attr_selector/single_string region "'" (?<!\\)(\\\\)*' fill string
# Commands
# ‾‾‾‾‾‾‾‾
@ -65,10 +117,20 @@ define-command -hidden css-trim-indent %{
define-command -hidden css-indent-on-new-line %[
evaluate-commands -draft -itersel %[
# preserve previous line indent
try %[ execute-keys -draft <semicolon> K <a-&> ]
execute-keys <semicolon>
try %<
# if previous line is part of a comment, do nothing
execute-keys -draft <a-?>/\*<ret> <a-K>^\h*[^/*\h]<ret>
> catch %<
# else if previous line closed a paren (possibly followed by words and a comment),
# copy indent of the opening paren line
execute-keys -draft k<a-x> 1s(\))(\h+\w+)*\h*(\;\h*)?(?://[^\n]+)?\n\z<ret> m<a-semicolon>J <a-S> 1<a-&>
> catch %<
# else indent new lines with the same level as the previous one
execute-keys -draft K <a-&>
>
# filter previous line
try %[ execute-keys -draft k : css-trim-indent <ret> ]
try %< execute-keys -draft k <a-x> <a-k>^\h+$<ret> Hd >
# indent after lines ending with with {
try %[ execute-keys -draft k <a-x> <a-k> \{$ <ret> j <a-gt> ]
# deindent closing brace when after cursor
@ -76,6 +138,44 @@ define-command -hidden css-indent-on-new-line %[
]
]
define-command -hidden css-insert-on-new-line %[
evaluate-commands -draft -itersel %<
execute-keys <semicolon>
try %[
# if the previous line isn't within a comment scope, break
execute-keys -draft k<a-x> <a-k>^(\h*/\*|\h+\*(?!/))<ret>
# find comment opening, validate it was not closed, and check its using star prefixes
execute-keys -draft <a-?>/\*<ret><a-H> <a-K>\*/<ret> <a-k>\A\h*/\*([^\n]*\n\h*\*)*[^\n]*\n\h*.\z<ret>
try %[
# if the previous line is opening the comment, insert star preceeded by space
execute-keys -draft k<a-x><a-k>^\h*/\*<ret>
execute-keys -draft i*<space><esc>
] catch %[
try %[
# if the next line is a comment line insert a star
execute-keys -draft j<a-x><a-k>^\h+\*<ret>
execute-keys -draft i*<space><esc>
] catch %[
try %[
# if the previous line is an empty comment line, close the comment scope
execute-keys -draft k<a-x><a-k>^\h+\*\h+$<ret> <a-x>1s\*(\h*)<ret>c/<esc>
] catch %[
# if the previous line is a non-empty comment line, add a star
execute-keys -draft i*<space><esc>
]
]
]
# trim trailing whitespace on the previous line
try %[ execute-keys -draft s\h+$<ret> d ]
# align the new star with the previous one
execute-keys K<a-x>1s^[^*]*(\*)<ret>&
]
>
]
define-command -hidden css-indent-on-closing-curly-brace %[
evaluate-commands -draft -itersel %[
# align to opening curly brace when alone on a line

View File

@ -43,7 +43,7 @@ provide-module javascript %§
define-command -hidden javascript-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft <a-x> 1s^(\h+)$<ret> d }
}
define-command -hidden javascript-indent-on-char %<
@ -55,21 +55,112 @@ define-command -hidden javascript-indent-on-char %<
define-command -hidden javascript-insert-on-new-line %<
evaluate-commands -draft -itersel %<
# copy // comments prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K/{2,}\h* <ret> y gh j P }
execute-keys <semicolon>
# NOT working, copies single line comment "//"
# try %[
# evaluate-commands -draft -save-regs '/"' %[
# # copy the commenting prefix
# execute-keys -save-regs '' k <a-x>1s^\h*(//+\h*)<ret> y
# try %[
# # if the previous comment isn't empty, create a new one
# execute-keys <a-x><a-K>^\h*//+\h*$<ret> j<a-x>s^\h*<ret>P
# ] catch %[
# # if there is no text in the previous comment, remove it completely
# execute-keys d
# ]
# ]
# ]
try %[
# if the previous line isn't within a comment scope, break
execute-keys -draft k<a-x> <a-k>^(\h*/\*|\h+\*(?!/))<ret>
# find comment opening, validate it was not closed, and check its using star prefixes
execute-keys -draft <a-?>/\*<ret><a-H> <a-K>\*/<ret> <a-k>\A\h*/\*([^\n]*\n\h*\*)*[^\n]*\n\h*.\z<ret>
try %[
# if the previous line is opening the comment, insert star preceeded by space
execute-keys -draft k<a-x><a-k>^\h*/\*<ret>
execute-keys -draft i*<space><esc>
] catch %[
try %[
# if the next line is a comment line insert a star
execute-keys -draft j<a-x><a-k>^\h+\*<ret>
execute-keys -draft i*<space><esc>
] catch %[
try %[
# if the previous line is an empty comment line, close the comment scope
execute-keys -draft k<a-x><a-k>^\h+\*\h+$<ret> <a-x>1s\*(\h*)<ret>c/<esc>
] catch %[
# if the previous line is a non-empty comment line, add a star
execute-keys -draft i*<space><esc>
]
]
]
# trim trailing whitespace on the previous line
try %[ execute-keys -draft s\h+$<ret> d ]
# align the new star with the previous one
execute-keys K<a-x>1s^[^*]*(\*)<ret>&
]
# # copy // comments prefix and following white spaces
# try %{ execute-keys -draft k <a-x> s ^\h*\K/{2,}\h* <ret> y gh j P }
>
>
define-command -hidden javascript-indent-on-new-line %<
evaluate-commands -draft -itersel %<
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# filter previous line
try %{ execute-keys -draft k : javascript-trim-indent <ret> }
# indent after lines beginning / ending with opener token
try %_ execute-keys -draft k <a-x> s [[({] <ret> <space> <a-l> <a-K> [\])}] <ret> j <a-gt> _
# deindent closing token(s) when after cursor
try %_ execute-keys -draft <a-x> <a-k> ^\h*[})\]] <ret> gh / [})\]] <ret> m <a-S> 1<a-&> _
execute-keys <semicolon>
try %<
# if previous line is part of a comment, do nothing
execute-keys -draft <a-?>/\*<ret> <a-K>^\h*[^/*\h]<ret>
> catch %<
# else if previous line closed a paren (possibly followed by words and a comment),
# copy indent of the opening paren line
execute-keys -draft k<a-x> 1s(\))(\h+\w+)*\h*(\;\h*)?(?://[^\n]+)?\n\z<ret> m<a-semicolon>J <a-S> 1<a-&>
> catch %<
# else indent new lines with the same level as the previous one
execute-keys -draft K <a-&>
>
# remove previous empty lines resulting from the automatic indent
try %< execute-keys -draft k <a-x> <a-k>^\h+$<ret> Hd >
# indent after an opening brace or parenthesis at end of line
try %< execute-keys -draft k <a-x> <a-k>[{(]\h*$<ret> j <a-gt> >
# indent after a label (works for case statements)
try %< execute-keys -draft k <a-x> s[a-zA-Z0-9_-]+:\h*$<ret> j <a-gt> >
# indent after a statement not followed by an opening brace
try %< execute-keys -draft k <a-x> s\)\h*(?://[^\n]+)?\n\z<ret> \
<a-semicolon>mB <a-k>\A\b(if|for|while)\b<ret> <a-semicolon>j <a-gt> >
try %< execute-keys -draft k <a-x> s \belse\b\h*(?://[^\n]+)?\n\z<ret> \
j <a-gt> >
# deindent after a single line statement end
try %< execute-keys -draft K <a-x> <a-k>\;\h*(//[^\n]+)?$<ret> \
K <a-x> s\)(\h+\w+)*\h*(//[^\n]+)?\n([^\n]*\n){2}\z<ret> \
MB <a-k>\A\b(if|for|while)\b<ret> <a-S>1<a-&> >
try %< execute-keys -draft K <a-x> <a-k>\;\h*(//[^\n]+)?$<ret> \
K <a-x> s \belse\b\h*(?://[^\n]+)?\n([^\n]*\n){2}\z<ret> \
<a-S>1<a-&> >
# deindent closing brace(s) when after cursor
try %< execute-keys -draft <a-x> <a-k> ^\h*[})] <ret> gh / [})] <esc> m <a-S> 1<a-&> >
# align to the opening parenthesis or opening brace (whichever is first)
# on a previous line if its followed by text on the same line
try %< evaluate-commands -draft %<
# Go to opening parenthesis and opening brace, then select the most nested one
try %< execute-keys [c [({],[)}] <ret> >
# Validate selection and get first and last char
execute-keys <a-k>\A[{(](\h*\S+)+\n<ret> <a-K>"(([^"]*"){2})*<ret> <a-K>'(([^']*'){2})*<ret> <a-:><a-semicolon>L <a-S>
# Remove possibly incorrect indent from new line which was copied from previous line
try %< execute-keys -draft <space> <a-h> s\h+<ret> d >
# Now indent and align that new line with the opening parenthesis/brace
execute-keys 1<a-&> &
> >
# # preserve previous line indent
# try %{ execute-keys -draft <semicolon> K <a-&> }
# # filter previous line
# try %{ execute-keys -draft k : javascript-trim-indent <ret> }
# # indent after lines beginning / ending with opener token
# try %_ execute-keys -draft k <a-x> s [[({] <ret> <space> <a-l> <a-K> [\])}] <ret> j <a-gt> _
# # deindent closing token(s) when after cursor
# try %_ execute-keys -draft <a-x> <a-k> ^\h*[})\]] <ret> gh / [})\]] <ret> m <a-S> 1<a-&> _
>
>

View File

@ -15,6 +15,7 @@ hook global WinSetOption filetype=scss %[
require-module scss
hook window ModeChange pop:insert:.* -group scss-trim-indent scss-trim-indent
hook window InsertChar \n -group scss-indent scss-insert-on-new-line
hook window InsertChar \n -group scss-indent scss-indent-on-new-line
hook window InsertChar \} -group scss-indent scss-indent-on-closing-curly-brace
set-option buffer extra_word_chars '_' '-'
@ -37,15 +38,17 @@ require-module css
add-highlighter shared/scss regions
add-highlighter shared/scss/core default-region group
add-highlighter shared/scss/comment region // $ fill comment
add-highlighter shared/scss/comment region ^\h*// $ fill comment
add-highlighter shared/scss/core/ ref css
add-highlighter shared/scss/core/ regex @[A-Za-z][A-Za-z0-9_-]* 0:meta
add-highlighter shared/scss/core/ regex & 0:keyword
add-highlighter shared/scss/core/ regex \$[A-Za-z][A-Za-z0-9_-]* 0:variable
# Commands
# ‾‾‾‾‾‾‾‾
define-command -hidden scss-trim-indent css-trim-indent
define-command -hidden scss-insert-on-new-line css-insert-on-new-line
define-command -hidden scss-indent-on-new-line css-indent-on-new-line
define-command -hidden scss-indent-on-closing-curly-brace css-indent-on-closing-curly-brace

89
rc/filetype/twig.kak Normal file
View File

@ -0,0 +1,89 @@
# https://twig.symfony.com/doc/3.x/templates.html
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate .*[.](twig) %{
set-option buffer filetype twig
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=twig %[
require-module twig
hook window ModeChange pop:insert:.* -group twig-trim-indent twig-trim-indent
hook window InsertChar \n -group twig-insert twig-insert-on-new-line
hook window InsertChar \n -group twig-indent twig-indent-on-new-line
hook window InsertChar '>' -group twig-indent twig-indent-on-greater-than
hook window InsertChar '#' -group twig-auto-close twig-auto-close-delim
hook window InsertChar '%' -group twig-auto-close twig-auto-close-delim
set-option buffer extra_word_chars '_' '-'
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window twig-.+ }
]
hook -group twig-highlight global WinSetOption filetype=twig %{
add-highlighter window/twig ref twig
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/twig }
}
provide-module twig %[
require-module html
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
add-highlighter shared/twig regions
add-highlighter shared/twig/core default-region group
add-highlighter shared/twig/comment region \{# [#]\} fill comment
add-highlighter shared/twig/delim region \{([%]-?|\{) (-?[%]|\})\} regions
add-highlighter shared/twig/core/ ref html
add-highlighter shared/twig/delim/base default-region group
add-highlighter shared/twig/delim/double_string region '"' (?<!\\)(\\\\)*" fill string
add-highlighter shared/twig/delim/single_string region "'" (?<!\\)(\\\\)*' fill string
add-highlighter shared/twig/delim/base/ regex (\w+)\h= 1:variable
add-highlighter shared/twig/delim/base/functions regex \b(\w+)\( 1:function
add-highlighter shared/twig/delim/base/filters regex \b(abs|batch|capitalize|column|convert_encoding|country_name|currency_name|currency_symbol|data_uri|date|date_modify|default|e|escape|filter|first|format|format_currency|format_date|format_datetime|format_number|format_time|html_to_markdown|inline_css|inky_to_html|join|json_encode|keys|language_name|last|length|locale_name|lower|map|markdown_to_html|merge|nl2br|number_format|raw|reduce|replace|reverse|round|slice|slug|sort|spaceless|split|striptags|timezone_name|title|trim|u|upper|url_encode)(\()?\b 1:operator
add-highlighter shared/twig/delim/base/tags regex \b((extends|deprecated|do|flush|import|from|elseif|else|include|set|use)|(end)?(apply|autoescape|block|cache|embed|for|if|macro|sandbox|set|verbatim|with))\b 0:keyword 0:+i
add-highlighter shared/twig/delim/base/delimiter_code regex (\{[%]|[%]\}) 0:function
add-highlighter shared/twig/delim/base/delimiter_output regex (\{\{|\}\}) 0:operator
# Commands
# ‾‾‾‾‾‾‾‾
define-command -hidden twig-trim-indent html-trim-indent
define-command -hidden twig-indent-on-new-line html-indent-on-new-line
define-command -hidden twig-indent-on-greater-than html-indent-on-greater-than
define-command -hidden twig-auto-close-delim %[
evaluate-commands -itersel %[
try %[
execute-keys -draft <semicolon>hH<a-k>\h*\{<ret>lyp
execute-keys <esc>hi<space><esc>hi<space>
]
]
]
define-command -hidden twig-insert-on-new-line %[
evaluate-commands -draft -itersel %/
execute-keys <semicolon>
try %[
execute-keys -draft k<a-x><a-k>^\h*\{\[%#\{\]\h+$<ret>
execute-keys -draft jghd
]
/
]
]