From 2718c05c0e00dbbf5e6366169b6a6e1c665c2bd3 Mon Sep 17 00:00:00 2001 From: chris rooney Date: Fri, 1 Apr 2016 08:50:31 -0430 Subject: [PATCH 1/3] initial commit of jade/pug highlighter --- rc/extra/pug.kak | 83 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 rc/extra/pug.kak diff --git a/rc/extra/pug.kak b/rc/extra/pug.kak new file mode 100644 index 00000000..3e1adfe9 --- /dev/null +++ b/rc/extra/pug.kak @@ -0,0 +1,83 @@ +# Note: jade is changing its name to pug (https://github.com/pugjs/pug/issues/2184) +# This appears to be a work in progress -- the pug-lang domain is parked, while +# the jade-lang one is active. This highlighter will recognize .pug and .jade extensions, + +# http://jade-lang.com (will be http://pug-lang.com) +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufSetOption mimetype=text/x-pug %{ + set buffer filetype pug +} + +hook global BufCreate .*[.](pug|jade) %{ + set buffer filetype pug +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +addhl -group / regions -default code pug \ + text ^\h*\|\s $ '' \ + text ^\h*([A-Za-z][A-Za-z0-9_-]*)?(\#[A-Za-z][A-Za-z0-9_-]*)?((?:\.[A-Za-z][A-Za-z0-9_-]*)*)?(?<=\S)\h+\K.* $ '' \ + javascript ^\h*[-=!] $ '' \ + double_string '"' (?:(? $ '' \ + +# Filters +# ‾‾‾‾‾‾‾ + +addhl -group /pug/double_string fill string +addhl -group /pug/single_string fill string +addhl -group /pug/comment fill comment +addhl -group /pug/javascript ref javascript +addhl -group /pug/attribute ref javascript +addhl -group /pug/puglang ref javascript +addhl -group /pug/puglang regex \<(\block|extends|include|append|prepend|if|unless|else|case|when|default|each|while|mixin|of|in)\> 0:keyword +addhl -group /pug/attribute regex [()=] 0:operator +addhl -group /pug/text regex \h*(\|) 1:meta +addhl -group /pug/code regex ^\h*([A-Za-z][A-Za-z0-9_-]*) 1:type +addhl -group /pug/code regex (\#[A-Za-z][A-Za-z0-9_-]*) 1:identifier +addhl -group /pug/code regex ((?:\.[A-Za-z][A-Za-z0-9_-]*)*) 1:value + +# Commands +# ‾‾‾‾‾‾‾‾ + +def -hidden _pug_filter_around_selections %{ + # remove trailing white spaces + try %{ exec -draft -itersel s \h+$ d } +} + +def -hidden _pug_indent_on_new_line %{ + eval -draft -itersel %{ + # preserve previous line indent + try %{ exec -draft K } + # filter previous line + try %{ exec -draft k : _pug_filter_around_selections } + # copy '//', '|', '-' or '(!)=' prefix and following whitespace + try %{ exec -draft k x s ^\h*\K[/|!=-]{1,2}\h* y j p } + # indent unless we copied something above + try %{ exec -draft b s \S g l } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=pug %{ + addhl ref pug + + hook window InsertEnd .* -group pug-hooks _pug_filter_around_selections + hook window InsertChar \n -group pug-indent _pug_indent_on_new_line +} + +hook global WinSetOption filetype=(?!pug).* %{ + rmhl pug + rmhooks window pug-indent + rmhooks window pug-hooks +} From 27f78e241ac289640875412022d018b968e2c559 Mon Sep 17 00:00:00 2001 From: chris rooney Date: Fri, 1 Apr 2016 09:02:15 -0430 Subject: [PATCH 2/3] whitespace fix --- rc/extra/pug.kak | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rc/extra/pug.kak b/rc/extra/pug.kak index 3e1adfe9..a82845d3 100644 --- a/rc/extra/pug.kak +++ b/rc/extra/pug.kak @@ -20,13 +20,13 @@ hook global BufCreate .*[.](pug|jade) %{ # ‾‾‾‾‾‾‾‾‾‾‾‾ addhl -group / regions -default code pug \ - text ^\h*\|\s $ '' \ + text ^\h*\|\s $ '' \ text ^\h*([A-Za-z][A-Za-z0-9_-]*)?(\#[A-Za-z][A-Za-z0-9_-]*)?((?:\.[A-Za-z][A-Za-z0-9_-]*)*)?(?<=\S)\h+\K.* $ '' \ - javascript ^\h*[-=!] $ '' \ + javascript ^\h*[-=!] $ '' \ double_string '"' (?:(? $ '' \ # Filters