kakoune

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

sass.kak (3175B)


      1 # http://sass-lang.com
      2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
      3 
      4 # Detection
      5 # ‾‾‾‾‾‾‾‾‾
      6 
      7 hook global BufCreate .*[.](sass) %{
      8     set-option buffer filetype sass
      9 }
     10 
     11 # Initialization
     12 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
     13 
     14 hook global WinSetOption filetype=sass %<
     15     require-module sass
     16 
     17     hook window ModeChange pop:insert:.* -group sass-trim-indent sass-trim-indent
     18     hook window InsertChar \} -group sass-indent sass-indent-on-closing-brace
     19     hook window InsertChar \n -group sass-insert sass-insert-on-new-line
     20     hook window InsertChar \n -group sass-indent sass-indent-on-new-line
     21     set-option buffer extra_word_chars '_' '-'
     22 
     23     hook -once -always window WinSetOption filetype=.* %{ remove-hooks window sass-.+ }
     24 >
     25 
     26 hook -group sass-highlight global WinSetOption filetype=sass %{
     27     add-highlighter window/sass ref sass
     28     hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/sass }
     29 }
     30 
     31 
     32 provide-module sass %§
     33 
     34 # Highlighters
     35 # ‾‾‾‾‾‾‾‾‾‾‾‾
     36 
     37 add-highlighter shared/sass regions
     38 add-highlighter shared/sass/code default-region group
     39 add-highlighter shared/sass/single_string  region '"' (?<!\\)(\\\\)*" fill string
     40 add-highlighter shared/sass/double_string  region "'" "'"             fill string
     41 add-highlighter shared/sass/comment        region '//' '$'            fill comment
     42 add-highlighter shared/sass/css_comment    region /[*] [*]/           fill comment
     43 
     44 add-highlighter shared/sass/code/ regex [*]|[#.][A-Za-z][A-Za-z0-9_-]* 0:variable
     45 add-highlighter shared/sass/code/ regex &|@[A-Za-z][A-Za-z0-9_-]* 0:meta
     46 add-highlighter shared/sass/code/ regex (#[0-9A-Fa-f]+)|((\d*\.)?\d+(em|px)) 0:value
     47 add-highlighter shared/sass/code/ regex ([A-Za-z][A-Za-z0-9_-]*)\h*: 1:keyword
     48 add-highlighter shared/sass/code/ regex :(before|after) 0:attribute
     49 add-highlighter shared/sass/code/ regex !important 0:keyword
     50 
     51 # Commands
     52 # ‾‾‾‾‾‾‾‾
     53 
     54 define-command -hidden sass-trim-indent %{
     55     # remove trailing white spaces
     56     try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
     57 }
     58 
     59 define-command -hidden sass-indent-on-closing-brace %<
     60     evaluate-commands -draft -itersel %<
     61         # align closing brace to same indentation as the line that the opening brace resides on
     62         try %[ execute-keys -draft <a-h> <a-k> ^\h+\}$ <ret> m <a-S> 1<a-&> ]
     63     >
     64 >
     65 
     66 define-command -hidden sass-insert-on-new-line %<
     67     evaluate-commands -draft -itersel %<
     68         # copy // comment prefix and following white spaces
     69         try %{ execute-keys -draft k x s ^\h*\K/{2,}\h* <ret> y gh j P }
     70     >
     71 >
     72 
     73 define-command -hidden sass-indent-on-new-line %<
     74     evaluate-commands -draft -itersel %<
     75         # preserve previous line indent
     76         try %{ execute-keys -draft <semicolon> K <a-&> }
     77         # filter previous line
     78         try %{ execute-keys -draft k : sass-trim-indent <ret> }
     79         # avoid indent after properties and comments
     80         try %{ execute-keys -draft k x <a-K> [:/] <ret> j <a-gt> }
     81         # deindent closing brace when after cursor
     82         try %[ execute-keys -draft x <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> ]
     83     >
     84 >
     85 
     86 §