kakoune

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

just.kak (3066B)


      1 # Detection
      2 # ‾‾‾‾‾‾‾‾‾
      3 
      4 hook global BufCreate .*/?[jJ]ustfile %{
      5     set-option buffer filetype justfile
      6 }
      7 
      8 hook global WinSetOption filetype=justfile %{
      9     require-module justfile
     10 
     11     hook window ModeChange pop:insert:.* -group justfile-trim-indent justfile-trim-indent
     12     hook window InsertChar \n -group justfile-insert just-insert-on-new-line
     13     hook window InsertChar \n -group justfile-indent just-indent-on-new-line
     14     hook -once -always window WinSetOption filetype=.* %{ remove-hooks window justfile-.+ }
     15 }
     16 
     17 hook -group justfile-highlight global WinSetOption filetype=justfile %{
     18     add-highlighter window/justfile ref justfile
     19     hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/justfile }
     20 }
     21 
     22 
     23 provide-module justfile %{
     24 
     25 # Indentation
     26 # ‾‾‾‾‾‾‾‾‾‾‾
     27 
     28 define-command -hidden justfile-trim-indent %{
     29     evaluate-commands -no-hooks -draft -itersel %{
     30         execute-keys x
     31         # remove trailing white spaces
     32         try %{ execute-keys -draft s \h + $ <ret> d }
     33     }
     34 }
     35 
     36 define-command -hidden just-insert-on-new-line %{
     37     # copy '#' comment prefix and following white spaces
     38     try %{ execute-keys -draft k x s ^\h*//\h* <ret> y jgh P }
     39 }
     40 
     41 define-command -hidden just-indent-on-new-line %{
     42      evaluate-commands -draft -itersel %{
     43         # preserve previous line indent
     44         try %{ execute-keys -draft <semicolon>K<a-&> }
     45         # cleanup trailing white spaces on previous line
     46         try %{ execute-keys -draft kx s \h+$ <ret>"_d }
     47     }
     48 }
     49 
     50 # Highlighters
     51 # ‾‾‾‾‾‾‾‾‾‾‾‾
     52 
     53 add-highlighter shared/justfile regions
     54 
     55 add-highlighter shared/justfile/content default-region group
     56 add-highlighter shared/justfile/content/recipe regex '^@?([\w-]+)(\N*):(?!=)(\N*)' 1:function 2:meta 3:keyword
     57 add-highlighter shared/justfile/content/assignments regex ^([\w-]+\h*:=\h*\N*) 1:meta
     58 add-highlighter shared/justfile/content/operator regex '((^@|:=|=|\+|\(|\)))' 1:operator
     59 add-highlighter shared/justfile/content/strings regions
     60 add-highlighter shared/justfile/content/strings/double region '"' (?<!\\)(\\\\)*" fill string
     61 add-highlighter shared/justfile/content/strings/single region "'" (?<!\\)(\\\\)*' fill string
     62 
     63 add-highlighter shared/justfile/comment  region '#' '$'  fill comment
     64 
     65 add-highlighter shared/justfile/inline   region '`' '`' ref sh
     66 
     67 add-highlighter shared/justfile/body  region '^\h+' '^[^\h]' group
     68 add-highlighter shared/justfile/body/interpreters regions
     69 add-highlighter shared/justfile/body/interpreters/defaultshell default-region group
     70 add-highlighter shared/justfile/body/interpreters/defaultshell/ ref sh
     71 add-highlighter shared/justfile/body/interpreters/defaultshell/ regex '^\h+(@)' 1:operator
     72 
     73 add-highlighter shared/justfile/body/interpreters/bash region '^\h+#!\h?/usr/bin/env bash' '^[^\h]' ref sh
     74 add-highlighter shared/justfile/body/interpreters/sh region '^\h+#!\h?/usr/bin/env sh' '^[^\h]' ref sh
     75 
     76 add-highlighter shared/justfile/body/ regex '(\{{2})([\w-]+(?:\(\))?)(\}{2})' 1:operator 2:variable 3:operator
     77 
     78 
     79 }