kakoune

Fork of kakoune, an acceptable text editor
git clone git://git.laack.co/kakoune.git
Log | Files | Refs

pug.kak (3701B)


      1 # Note: jade is changing its name to pug (https://github.com/pugjs/pug/issues/2184)
      2 # This appears to be a work in progress -- the pug-lang domain is parked, while
      3 # the jade-lang one is active. This highlighter will recognize .pug and .jade extensions,
      4 
      5 # http://jade-lang.com (will be http://pug-lang.com)
      6 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
      7 
      8 # Detection
      9 # ‾‾‾‾‾‾‾‾‾
     10 
     11 hook global BufCreate .*[.](pug|jade) %{
     12     set-option buffer filetype pug
     13 }
     14 
     15 # Initialization
     16 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
     17 
     18 hook global WinSetOption filetype=pug %{
     19     require-module pug
     20 
     21     hook window ModeChange pop:insert:.* -group pug-trim-indent pug-trim-indent
     22     hook window InsertChar \n -group pug-indent pug-indent-on-new-line
     23 
     24     hook -once -always window WinSetOption filetype=.* %{ remove-hooks window pug-.+ }
     25 }
     26 
     27 hook -group pug-highlight global WinSetOption filetype=pug %{
     28     add-highlighter window/pug ref pug
     29     hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/pug }
     30 }
     31 
     32 
     33 provide-module pug %{
     34 
     35 # Highlighters
     36 # ‾‾‾‾‾‾‾‾‾‾‾‾
     37 
     38 add-highlighter shared/pug regions
     39 add-highlighter shared/pug/code          default-region group
     40 add-highlighter shared/pug/text          region ^\h*\|\s     $                      regex   \h*(\|) 1:meta
     41 add-highlighter shared/pug/text2         region '^\h*([A-Za-z][A-Za-z0-9_-]*)?(#[A-Za-z][A-Za-z0-9_-]*)?((?:\.[A-Za-z][A-Za-z0-9_-]*)*)?(?<!\t)(?<! )(?<!\n)\h+\K.*' $ regex   \h*(\|) 1:meta
     42 add-highlighter shared/pug/javascript    region ^\h*[-=!]    $                      ref javascript
     43 add-highlighter shared/pug/double_string region '"'          (?:(?<!\\)(\\\\)*"|$)  fill string
     44 add-highlighter shared/pug/single_string region "'"          (?:(?<!\\)(\\\\)*'|$)  fill string
     45 add-highlighter shared/pug/comment       region //           $                      fill comment
     46 add-highlighter shared/pug/attribute     region -recurse \( \(            \)        group
     47 add-highlighter shared/pug/puglang       region ^\h*\b(\block|extends|include|append|prepend|if|unless|else|case|when|default|each|while|mixin)\b $ group
     48 
     49 # Filters
     50 # ‾‾‾‾‾‾‾
     51 
     52 add-highlighter shared/pug/attribute/       ref     javascript
     53 add-highlighter shared/pug/attribute/       regex   [()=]                             0:operator
     54 add-highlighter shared/pug/puglang/         ref     javascript
     55 add-highlighter shared/pug/puglang/         regex   \b(\block|extends|include|append|prepend|if|unless|else|case|when|default|each|while|mixin|of|in)\b 0:keyword
     56 add-highlighter shared/pug/code/            regex   ^\h*([A-Za-z][A-Za-z0-9_-]*)      1:type
     57 add-highlighter shared/pug/code/            regex   '(#[A-Za-z][A-Za-z0-9_-]*)'       1:variable
     58 add-highlighter shared/pug/code/            regex   ((?:\.[A-Za-z][A-Za-z0-9_-]*)*)   1:value
     59 
     60 # Commands
     61 # ‾‾‾‾‾‾‾‾
     62 
     63 define-command -hidden pug-trim-indent %{
     64     # remove trailing white spaces
     65     try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
     66 }
     67 
     68 define-command -hidden pug-indent-on-new-line %{
     69     evaluate-commands -draft -itersel %{
     70         # preserve previous line indent
     71         try %{ execute-keys -draft <semicolon> K <a-&> }
     72         # filter previous line
     73         try %{ execute-keys -draft k : pug-trim-indent <ret> }
     74         # copy '//', '|', '-' or '(!)=' prefix and following whitespace
     75         try %{ execute-keys -draft k x s ^\h*\K[/|!=-]{1,2}\h* <ret> y gh j P }
     76         # indent unless we copied something above
     77         try %{ execute-keys -draft <a-gt> , b s \S <ret> g l <a-lt> }
     78     }
     79 }
     80 
     81 }