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