annotate runtime/indent/bst.vim @ 29653:aa83cf7bef1c v9.0.0167

patch 9.0.0167: checking for text properties could be a bit more efficient Commit: https://github.com/vim/vim/commit/38ea2733b4dd8e9bfc4a5bb5c11cb661bf000c4e Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 7 22:04:56 2022 +0100 patch 9.0.0167: checking for text properties could be a bit more efficient Problem: Checking for text properties could be a bit more efficient. Solution: Return early when there are no text properties. Update TODO items.
author Bram Moolenaar <Bram@vim.org>
date Sun, 07 Aug 2022 23:15:03 +0200
parents dce918af0c00
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1125
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
1 " Vim indent file
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
2 " Language: bst
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
3 " Author: Tim Pope <vimNOSPAM@tpope.info>
28141
dce918af0c00 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
4 " Last Change: 2022 Mar 15
1125
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
5
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
6 if exists("b:did_indent")
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
7 finish
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
8 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
9 let b:did_indent = 1
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
10
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
11 setlocal indentexpr=GetBstIndent(v:lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
12 setlocal cinkeys&
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
13 setlocal cinkeys-=0#
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
14 setlocal indentkeys&
28141
dce918af0c00 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
15 let b:undo_indent = 'setlocal indentexpr< cinkeys< indentkeys<'
1125
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
16
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
17 " Only define the function once.
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
18 if exists("*GetBstIndent")
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
19 finish
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
20 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
21
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
22 function! s:prevgood(lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
23 " Find a non-blank line above the current line.
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
24 " Skip over comments.
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
25 let lnum = a:lnum
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
26 while lnum > 0
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
27 let lnum = prevnonblank(lnum - 1)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
28 if getline(lnum) !~ '^\s*%.*$'
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
29 break
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
30 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
31 endwhile
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
32 return lnum
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
33 endfunction
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
34
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
35 function! s:strip(lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
36 let line = getline(a:lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
37 let line = substitute(line,'"[^"]*"','""','g')
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
38 let line = substitute(line,'%.*','','')
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
39 let line = substitute(line,'^\s\+','','')
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
40 return line
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
41 endfunction
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
42
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
43 function! s:count(string,char)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
44 let str = substitute(a:string,'[^'.a:char.']','','g')
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
45 return strlen(str)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
46 endfunction
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
47
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
48 function! GetBstIndent(lnum) abort
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
49 if a:lnum == 1
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
50 return 0
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
51 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
52 let lnum = s:prevgood(a:lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
53 if lnum <= 0
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
54 return indent(a:lnum - 1)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
55 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
56 let line = s:strip(lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
57 let cline = s:strip(a:lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
58 if cline =~ '^}' && exists("b:current_syntax")
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
59 call cursor(a:lnum,indent(a:lnum))
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
60 if searchpair('{','','}','bW',"synIDattr(synID(line('.'),col('.'),1),'name') =~? 'comment\\|string'")
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
61 if col('.')+1 == col('$')
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
62 return indent('.')
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
63 else
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
64 return virtcol('.')-1
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
65 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
66 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
67 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
68 let fakeline = substitute(line,'^}','','').matchstr(cline,'^}')
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
69 let ind = indent(lnum)
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 2034
diff changeset
70 let ind = ind + shiftwidth() * s:count(line,'{')
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 2034
diff changeset
71 let ind = ind - shiftwidth() * s:count(fakeline,'}')
1125
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
72 return ind
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
73 endfunction