Mercurial > vim
annotate runtime/import/dist/vimhighlight.vim @ 33460:3b95a248ddb0
Added tag v9.0.1983 for changeset 0eda094f9b7ed60965f6dc4f9a8b5d153b1368f0
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 04 Oct 2023 22:00:04 +0200 |
parents | 50e447c67247 |
children |
rev | line source |
---|---|
32136
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 vim9script |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 # Maintainer: github user lacygoill |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 # Last Change: 2023 Mar 08 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 # Init {{{1 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 const LINK: string = '->' |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 # Interface {{{1 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 export def HighlightTest() # {{{2 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 # Open a new window if the current one isn't empty |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 if line('$') != 1 || getline(1) != '' |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 new |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 endif |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 edit Highlight\ test |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 # `:help scratch-buffer` |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 &l:bufhidden = 'hide' |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 &l:buftype = 'nofile' |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 &l:swapfile = false |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 var report: list<string> =<< trim END |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 Highlighting groups for various occasions |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 ----------------------------------------- |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 END |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 var various_groups: list<string> = GetVariousGroups() |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 ->filter((_, group: string): bool => group->hlexists() && !group->IsCleared()) |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 ->sort() |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 ->uniq() |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 report->extend(various_groups->FollowChains()) |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 var language_section: list<string> =<< trim END |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 Highlighting groups for language syntaxes |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 ----------------------------------------- |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 END |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 report->extend(language_section) |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 var syntax_groups: list<string> = getcompletion('', 'highlight') |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 ->filter((_, group: string): bool => |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 various_groups->index(group) == -1 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 && !group->IsCleared() |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 && group !~ '^HighlightTest') |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 # put the report |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 report |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 ->extend(syntax_groups->FollowChains()) |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 ->setline(1) |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 # highlight the group names |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 execute $'silent! global /^\w\+\%(\%(\s*{LINK}\s*\)\w\+\)*$/ Highlight({bufnr('%')})' |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 cursor(1, 1) |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 enddef |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 # }}}1 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 # Core {{{1 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 def Highlight(buf: number) # {{{2 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 var lnum: number = line('.') |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 for group: string in getline('.')->split($'\s*{LINK}\s*') |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 silent! prop_type_add($'highlight-test-{group}', { |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 bufnr: buf, |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 highlight: group, |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 combine: false, |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 }) |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 prop_add(lnum, col('.'), { |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 length: group->strlen(), |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 type: $'highlight-test-{group}' |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 }) |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 search('\<\w\+\>', '', lnum) |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 endfor |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 enddef |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 # }}}1 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 # Util {{{1 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 def IsCleared(name: string): bool # {{{2 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 return name |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 ->hlget() |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 ->get(0, {}) |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 ->get('cleared') |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 enddef |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 def FollowChains(groups: list<string>): list<string> # {{{2 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 # A group might be linked to another, which itself might be linked... |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 # We want the whole chain, for every group. |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 var chains: list<string> |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 for group: string in groups |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 var target: string = group->LinksTo() |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 var chain: string = group |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 while !target->empty() |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 chain ..= $' {LINK} {target}' |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 target = target->LinksTo() |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 endwhile |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 var a_link_is_cleared: bool = chain |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 ->split($'\s*{LINK}\s*') |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 ->indexof((_, g: string): bool => g->IsCleared()) >= 0 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 if a_link_is_cleared |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 continue |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 endif |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 chains->add(chain) |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 endfor |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 return chains |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 enddef |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 def LinksTo(group: string): string # {{{2 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 return group |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 ->hlget() |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
110 ->get(0, {}) |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 ->get('linksto', '') |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 enddef |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 def GetVariousGroups(): list<string> # {{{2 |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 return getcompletion('hl-', 'help') |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 ->filter((_, helptag: string): bool => helptag =~ '^hl-\w\+$') |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 ->map((_, helptag: string) => helptag->substitute('^hl-', '', '')) |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 ->extend(range(1, 9)->map((_, n: number) => $'User{n}')) |
50e447c67247
patch 9.0.1399: highlight test script has a few problems
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 enddef |