From 207bb7e389fe07f8b4efa2e3e16377e37aa1e427 Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Mon, 7 Jul 2014 22:24:09 +0200 Subject: [PATCH 1/7] string and comment do not require white space before --- rc/fish.kak | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rc/fish.kak b/rc/fish.kak index 48607b20..68aa1046 100644 --- a/rc/fish.kak +++ b/rc/fish.kak @@ -16,9 +16,9 @@ hook global BufCreate .*[.](fish) %{ # ‾‾‾‾‾‾‾‾‾‾‾‾ addhl -group / multi_region -default code fish \ - double_string (^|\h)" (? Date: Mon, 7 Jul 2014 22:34:16 +0200 Subject: [PATCH 2/7] single string is not escapable --- rc/fish.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc/fish.kak b/rc/fish.kak index 68aa1046..ac6dc3cc 100644 --- a/rc/fish.kak +++ b/rc/fish.kak @@ -17,7 +17,7 @@ hook global BufCreate .*[.](fish) %{ addhl -group / multi_region -default code fish \ double_string '"' (? Date: Mon, 7 Jul 2014 22:34:58 +0200 Subject: [PATCH 3/7] minor style fix --- rc/fish.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc/fish.kak b/rc/fish.kak index ac6dc3cc..adb72c12 100644 --- a/rc/fish.kak +++ b/rc/fish.kak @@ -18,7 +18,7 @@ hook global BufCreate .*[.](fish) %{ addhl -group / multi_region -default code fish \ double_string '"' (? Date: Mon, 7 Jul 2014 14:48:09 +0100 Subject: [PATCH 4/7] add rc/python.kak --- rc/python.kak | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 rc/python.kak diff --git a/rc/python.kak b/rc/python.kak new file mode 100644 index 00000000..a78e3b1e --- /dev/null +++ b/rc/python.kak @@ -0,0 +1,73 @@ +# http://python.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufSetOption mimetype=text/x-python %{ + set buffer filetype python +} + +hook global BufCreate .*[.](py) %{ + set buffer filetype python +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +addhl -group / multi_region -default code python \ + double_string '"""' '"""' '' \ + single_string "'''" "'''" '' \ + double_string '"' (? 0:value +addhl -group /python/code regex \<(import|from)\> 0:macro + +# Keyword list is collected using `keyword.kwlist` from `keyword` +addhl -group /python/code regex \<(and|as|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|global|if|in|is|lambda|not|or|pass|print|raise|return|try|while|with|yield)\> 0:keyword + +# Commands +# ‾‾‾‾‾‾‾‾ + +def -hidden _python_filter_around_selections %{ + eval -draft -itersel %{ + exec + # remove trailing white spaces + try %{ exec -draft s \h+$ d } + } +} + +def -hidden _python_indent_on_new_line %{ + eval -draft -itersel %{ + # preserve previous line indent + try %{ exec -draft K } + # filter previous line + try %{ exec -draft k : _python_filter_around_selections } + # copy '#' comment prefix and following white spaces + try %{ exec -draft k x s ^\h*\K#\h* y j p } + # indent after : + try %{ exec -draft k x :$ j } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=python %{ + addhl ref python + + hook window InsertEnd .* -group python-hooks _python_filter_around_selections + hook window InsertChar \n -group python-indent _python_indent_on_new_line +} + +hook global WinSetOption filetype=(?!python).* %{ + rmhl python + rmhooks window python-indent + rmhooks window python-hooks +} From fad6808d2a4b05d74c272123ba5abeb010ed1693 Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Mon, 7 Jul 2014 17:22:16 +0100 Subject: [PATCH 5/7] add rc/javascript.kak --- rc/javascript.kak | 82 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 rc/javascript.kak diff --git a/rc/javascript.kak b/rc/javascript.kak new file mode 100644 index 00000000..810da323 --- /dev/null +++ b/rc/javascript.kak @@ -0,0 +1,82 @@ +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufSetOption mimetype=text/x-javascript %{ + set buffer filetype javascript +} + +hook global BufCreate .*[.](js) %{ + set buffer filetype javascript +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +addhl -group / multi_region -default code javascript \ + double_string '"' (? 0:value +addhl -group /javascript/code regex \<(Array|Boolean|Date|Function|Number|Object|RegExp|String)\> 0:type + +# Keywords are collected at +# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords +addhl -group /javascript/code regex \<(break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|let|new|return|super|switch|throw|try|typeof|var|void|while|with|yield)\> 0:keyword + +# Commands +# ‾‾‾‾‾‾‾‾ + +def -hidden _javascript_filter_around_selections %{ + eval -draft -itersel %{ + exec + # remove trailing white spaces + try %{ exec -draft s \h+$ d } + } +} + +def -hidden _javascript_indent_on_char " + eval -draft -itersel ' + # indent closer token to its opener + try %_ exec -draft gh ^\h*[]}] m _ + ' +" + +def -hidden _javascript_indent_on_new_line " + eval -draft -itersel ' + # preserve previous line indent + try %{ exec -draft K } + # filter previous line + try %{ exec -draft k : _javascript_filter_around_selections } + # copy // comments prefix and following white spaces + try %{ exec -draft k x s ^\h*\K#\h* y j p } + # indent after lines beginning / ending with opener token + try %_ exec -draft k x ^\h*[[{]|[[{]$ j _ + ' +" + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=javascript %{ + addhl ref javascript + + hook window InsertEnd .* -group javascript-hooks _javascript_filter_around_selections + hook window InsertChar .* -group javascript-indent _javascript_indent_on_char + hook window InsertChar \n -group javascript-indent _javascript_indent_on_new_line +} + +hook global WinSetOption filetype=(?!javascript).* %{ + rmhl javascript + rmhooks window javascript-indent + rmhooks window javascript-hooks +} From 9db995c4eb345b73a4da4f248ebf689617e82bb9 Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Thu, 3 Jul 2014 15:16:59 +0200 Subject: [PATCH 6/7] add rc/ruby.kak --- rc/ruby.kak | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 rc/ruby.kak diff --git a/rc/ruby.kak b/rc/ruby.kak new file mode 100644 index 00000000..734abcc8 --- /dev/null +++ b/rc/ruby.kak @@ -0,0 +1,102 @@ +# http://ruby-lang.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufSetOption mimetype=text/x-ruby %{ + set buffer filetype ruby +} + +hook global BufCreate .*(([.](rb))|(irbrc)|(pryrc)|(Capfile|[.]cap)|(Gemfile)|(Guardfile)|(Rakefile|[.]rake)|(Thorfile|[.]thor)|(Vagrantfile)) %{ + set buffer filetype ruby +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +addhl -group / multi_region -default code ruby \ + double_string '"' (?' '' + +# Regular expression flags are: i → ignore case, m → multi-lines, o → only interpolate #{} blocks once, x → extended mode (ignore white spaces) +# Literals are: i → array of symbols, q → string, r → regular expression, s → symbol, w → array of words, x → capture shell result + +addhl -group /ruby/double_string fill string +addhl -group /ruby/double_string region interpolation \Q#{ \} \{ +addhl -group /ruby/double_string/interpolation/content fill macro +addhl -group /ruby/single_string fill string +addhl -group /ruby/backtick fill macro +addhl -group /ruby/backtick region interpolation \Q#{ \} \{ +addhl -group /ruby/backtick/interpolation/content fill macro +addhl -group /ruby/regex fill macro +addhl -group /ruby/regex region interpolation \Q#{ \} \{ +addhl -group /ruby/regex/interpolation/content fill macro +addhl -group /ruby/comment fill comment +addhl -group /ruby/literal fill macro + +addhl -group /ruby/code regex ([$@][a-z]\w+)|(\W\K:[a-z]\w+[=?!]?) 0:identifier +addhl -group /ruby/code regex \<(require|include)\>|\<([a-z]\w+:) 0:macro +addhl -group /ruby/code regex \<(attr_(reader|writer|accessor))\> 0:attribute + +# Keywords are collected searching for keyword_ at +# https://github.com/ruby/ruby/blob/trunk/parse.y +addhl -group /ruby/code regex \<(alias|and|begin|break|case|class|def|defined|do|else|elsif|end|ensure|false|for|if|in|module|next|nil|not|or|redo|rescue|retry|return|self|super|then|true|undef|unless|until|when|while|yield)\> 0:keyword + +# Commands +# ‾‾‾‾‾‾‾‾ + +def -hidden _ruby_filter_around_selections %{ + eval -draft -itersel %{ + exec + # remove trailing white spaces + try %{ exec -draft s \h+$ d } + } +} + +def -hidden _ruby_indent_on_char %{ + eval -draft -itersel %{ + # deindent on (else|elsif|end|rescue|when) keyword insertion + try %{ exec -draft w (else|elsif|end|rescue|when) } + } +} + +def -hidden _ruby_indent_on_new_line %{ + eval -draft -itersel %{ + # preserve previous line indent + try %{ exec -draft K } + # filter previous line + try %{ exec -draft k : _ruby_filter_around_selections } + # copy '#' comment prefix and following white spaces + try %{ exec -draft k x s ^\h*\K#\h* y j p } + # indent after (else|elsif|rescue|when) keywords + try %_ exec -draft k x (else|elsif|rescue|when) j _ + # indent after (begin|case|class|def|do|if|loop|module|unless|until|while) keywords and add 'end' keyword + try %{ exec -draft k x (begin|case|class|def|do|(? x y p j a end k } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=ruby %{ + addhl ref ruby + + hook window InsertEnd .* -group ruby-hooks _ruby_filter_around_selections + hook window InsertChar .* -group ruby-indent _ruby_indent_on_char + hook window InsertChar \n -group ruby-indent _ruby_indent_on_new_line +} + +hook global WinSetOption filetype=(?!ruby).* %{ + rmhl ruby + rmhooks window ruby-indent + rmhooks window ruby-hooks +} From 3730c8445ba115e4d5520e233fbf686671d118a7 Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Sat, 5 Jul 2014 18:14:27 +0200 Subject: [PATCH 7/7] add rc/yaml.kak --- rc/yaml.kak | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 rc/yaml.kak diff --git a/rc/yaml.kak b/rc/yaml.kak new file mode 100644 index 00000000..e24ad984 --- /dev/null +++ b/rc/yaml.kak @@ -0,0 +1,69 @@ +# http://yaml.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufSetOption mimetype=text/x-yaml %{ + set buffer filetype yaml +} + +hook global BufCreate .*[.](yaml) %{ + set buffer filetype yaml +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +addhl -group / multi_region -default code yaml \ + double_string '"' (? 0:value + +# Commands +# ‾‾‾‾‾‾‾‾ + +def -hidden _yaml_filter_around_selections %{ + eval -draft -itersel %{ + exec + # remove trailing white spaces + try %{ exec -draft s \h+$ d } + } +} + +def -hidden _yaml_indent_on_new_line %{ + eval -draft -itersel %{ + # preserve previous line indent + try %{ exec -draft K } + # filter previous line + try %{ exec -draft k : _yaml_filter_around_selections } + # copy '#' comment prefix and following white spaces + try %{ exec -draft k x s ^\h*\K#\h* y j p } + # indent after : + try %{ exec -draft k x :$ j } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=yaml %{ + addhl ref yaml + + hook window InsertEnd .* -group yaml-hooks _yaml_filter_around_selections + hook window InsertChar \n -group yaml-indent _yaml_indent_on_new_line +} + +hook global WinSetOption filetype=(?!yaml).* %{ + rmhl yaml + rmhooks window yaml-indent + rmhooks window yaml-hooks +}