kakoune

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

apl.kak (3425B)


      1 
      2 # Detection
      3 # ‾‾‾‾‾‾‾‾‾
      4 
      5 hook global BufCreate .*\.(apl|aplf|aplo|apln|aplc|apli|dyalog) %{
      6     set-option buffer filetype apl
      7 
      8     set-option buffer matching_pairs ( ) { } [ ]
      9 }
     10 
     11 # Initialization
     12 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
     13 
     14 hook global WinSetOption filetype=apl %|
     15     require-module apl
     16 
     17     hook window InsertChar \n -group apl-insert apl-insert-on-new-line
     18     hook window InsertChar \n -group apl-indent apl-indent-on-new-line
     19     hook window InsertChar [}⟩\]] -group apl-indent apl-indent-on-closing
     20 
     21     hook -once -always window WinSetOption filetype=.* %{ remove-hooks window apl-.+ }
     22 |
     23 
     24 hook -group apl-highlight global WinSetOption filetype=apl %{
     25     add-highlighter window/apl ref apl
     26     hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/apl }
     27 }
     28 
     29 provide-module apl %¹
     30 
     31 # Highlighters & Completion
     32 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
     33 
     34 add-highlighter shared/apl regions
     35 add-highlighter shared/apl/code default-region group
     36 add-highlighter shared/apl/comment region "⍝" "$" fill comment
     37 add-highlighter shared/apl/string  region "'" "'" fill string
     38 
     39 add-highlighter shared/apl/code/ regex "[{}]" 0:meta
     40 add-highlighter shared/apl/code/ regex "⋄" 0:meta
     41 add-highlighter shared/apl/code/ regex "[\[\]]" 0:magenta
     42 add-highlighter shared/apl/code/ regex "[()]" 0:bright-black
     43 add-highlighter shared/apl/code/ regex "[:;?]" 0:bright-black
     44 add-highlighter shared/apl/code/ regex "[←→]" 0:normal
     45 # Number
     46 add-highlighter shared/apl/code/ regex "¯?[0-9][¯0-9A-Za-z]*(?:\.[¯0-9Ee][¯0-9A-Za-z]*)*|¯?\.[0-9Ee][¯0-9A-Za-z]*" 0:value
     47 add-highlighter shared/apl/code/ regex "\." 0:normal
     48 add-highlighter shared/apl/code/ regex "[⍺⍶⍵⍹χ∇]" 0:blue # arguments
     49 # function
     50 add-highlighter shared/apl/code/ regex "[+\-×÷⌈⌊∣|⍳?*⍟○!⌹<≤=>≥≠≡≢∊⍷∪∩~∨∧⍱⍲⍴,⍪⌽⊖⍉↑↓⊂⊃⌷⍋⍒⊤⊥⍕⍎⊣⊢⍁⍂≈⌸⍯↗⊆⊇⍸√⌾…⍮]" 0:green  # function
     51 # operator
     52 add-highlighter shared/apl/code/ regex "[\.\\/⌿⍀¨⍣⍨⍠⍤∘⌸&⌶@⌺⍥⍛⍢]" 0:magenta
     53 # system
     54 add-highlighter shared/apl/code/ regex "⎕[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*" 0:yellow 
     55 add-highlighter shared/apl/code/ regex "\n^\s*\n(\n\t[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ]\n\t[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\n)\n(:)" 0:meta
     56 
     57 declare-user-mode apl
     58 # Commands
     59 # ‾‾‾‾‾‾‾‾
     60 
     61 define-command -hidden apl-insert-on-new-line %{
     62     evaluate-commands -draft -itersel %[
     63         # copy # comments prefix
     64         try %{ execute-keys -draft <semicolon><c-s>k<a-x> s ^\h*\K#+\h* <ret> y<c-o>P<esc> }
     65     ]
     66 }
     67 
     68 define-command -hidden apl-indent-on-new-line %`
     69     evaluate-commands -draft -itersel %_
     70         # preserve previous line indent
     71         try %{ execute-keys -draft <semicolon> K <a-&> }
     72         # indent after lines ending with { [
     73         try %( execute-keys -draft k<a-x> <a-k> [{\[]\h*$ <ret> j<a-gt> )
     74         # cleanup trailing white spaces on the previous line
     75         try %{ execute-keys -draft k<a-x> s \h+$ <ret>d }
     76      _
     77 `
     78 
     79 define-command -hidden apl-indent-on-closing %`
     80     evaluate-commands -draft -itersel %_
     81         # align to opening bracket
     82         try %( execute-keys -draft <a-h> <a-k> ^\h*[}\]]$ <ret> h m <a-S> 1<a-&> )
     83     _
     84 `
     85 
     86 ¹