Revision | f9f547dea6263078f9672bf69a813a6a1bdbf732 (tree) |
---|---|
Time | 2023-03-27 16:32:31 |
Author | badcoff33 |
Commiter | badcoff33 |
made Scope autoload-able
@@ -7,44 +7,37 @@ | ||
7 | 7 | let d = #{ pos: "topright", |
8 | 8 | \ line: "cursor", |
9 | 9 | \ col: win_screenpos(win_getid())[1] + winwidth(0), |
10 | - \ highlight: 'ErrorMsg', | |
10 | + \ highlight: 'Search', | |
11 | 11 | \ padding: [0, 1, 0, 1], |
12 | - \ time: 3500 } | |
12 | + \ time: 2000 } | |
13 | 13 | return d |
14 | 14 | endfunction |
15 | 15 | |
16 | -function! ScopePopup() | |
16 | +function! scope#PopupScope() | |
17 | 17 | let g:scope_previous = get(g:, "scope_previous", "") |
18 | 18 | let text = scope#GetScope() |
19 | 19 | if text != g:scope_previous && text != "" |
20 | - echo "<" .. text .. ">" | |
21 | 20 | call popup_create(text, g:WinoptsScope()) |
22 | 21 | endif |
23 | 22 | let g:scope_previous = text |
24 | 23 | endfunction |
25 | 24 | |
26 | -augroup GroupScope | |
27 | - au! | |
28 | - au CursorHold *.vim call ScopePopup() | |
29 | -augroup END | |
30 | - | |
31 | -" | |
32 | -" Description: If a function 'scope#Parser'..&ft exists, call it. The returned | |
25 | +" Description: If a function 'scope#GetScope'..&ft exists, call it. The returned | |
33 | 26 | " string can be used by 'statusline'. Recommended way to add new parser |
34 | -" functions is to add it in this file. Most | |
35 | -" important is that the function ScopeParser&ft exists. | |
27 | +" functions is to add it in this file. Most important is that the function | |
28 | +" ScopeParser&ft exists. | |
36 | 29 | function! scope#GetScope() |
37 | - let parser_fname = 'scope#Parser' . toupper(&ft[0]) . &ft[1:] | |
30 | + let parser_fname = 'scope#GetScope' . toupper(&ft[0]) . &ft[1:] | |
38 | 31 | try |
39 | - let Parser = function(parser_fname) | |
40 | - return Parser() | |
32 | + let FuncRef = function(parser_fname) | |
33 | + return FuncRef() | |
41 | 34 | catch |
42 | 35 | return '' |
43 | 36 | endtry |
44 | 37 | endfunction |
45 | 38 | |
46 | 39 | " Description: A scope parser for C files. |
47 | -function! scope#ParserC() abort | |
40 | +function! scope#GetScopeC() abort | |
48 | 41 | " Regular expressions to find head and bottom lines of a C function. |
49 | 42 | let regexpHead = '^[a-zA-Z_].*\(\<[0-9a-zA-Z_]\+\)\s*(.*' |
50 | 43 | let regexpTail = '^}.*$' |
@@ -63,7 +56,7 @@ | ||
63 | 56 | endfun |
64 | 57 | |
65 | 58 | " Description: A simple scope parser for Python files. |
66 | -function! scope#ParserPython() abort | |
59 | +function! scope#GetScopePython() abort | |
67 | 60 | let regexpHead = '^\s*\(class\|def\)\s\+\(\w\+\).*$' |
68 | 61 | let lineHead = search(regexpHead, 'bnWe') |
69 | 62 | if lineHead > 0 |
@@ -74,7 +67,7 @@ | ||
74 | 67 | endfun |
75 | 68 | |
76 | 69 | " Description: A simple scope parser for Markdown files. |
77 | -function! scope#ParserMarkdown() abort | |
70 | +function! scope#GetScopeMarkdown() abort | |
78 | 71 | let fNum = search('^#\{1,\}', 'bcnWez') |
79 | 72 | if fNum > 0 |
80 | 73 | let chapter_str = substitute(getline(fNum), '^\(#\{1,\}\)\s\+\(.*\)$', '\=len(submatch(1)).."|"..submatch(2)', '') |
@@ -89,7 +82,7 @@ | ||
89 | 82 | endfun |
90 | 83 | |
91 | 84 | " Description: A scope parser for Vim files. |
92 | -function! scope#ParserVim() abort | |
85 | +function! scope#GetScopeVim() abort | |
93 | 86 | " Regular expressions to find head and bottom lines of a Vim function. |
94 | 87 | let regexpHead = '^\(func\|def\|export def\).*\ \+\([A-Za-z0-9#:<>]\+\)(.*$' |
95 | 88 | let regexpTail = '^end.*$' |
@@ -0,0 +1,9 @@ | ||
1 | + | |
2 | +augroup GroupScope | |
3 | + au! | |
4 | + au CursorHold *.vim call scope#PopupScope() | |
5 | + au CursorHold *.c,*.h call scope#PopupScope() | |
6 | + au CursorHold *.py call scope#PopupScope() | |
7 | + au CursorHold *.markdown,*.md,*.txt call scope#PopupScope() | |
8 | +augroup END | |
9 | + |