annotate runtime/indent/bst.vim @ 26151:5a1850512676 v8.2.3607

patch 8.2.3607: GTK3 screen updating is slow Commit: https://github.com/vim/vim/commit/9459b8d461d6f8345bfa3fb9b3b4297a7950b0bc Author: presuku <presuku@users.noreply.github.com> Date: Tue Nov 16 20:03:56 2021 +0000 patch 8.2.3607: GTK3 screen updating is slow Problem: GTK3 screen updating is slow. Solution: Remove some of the GTK3-specific code. (closes https://github.com/vim/vim/issues/9052)
author Bram Moolenaar <Bram@vim.org>
date Tue, 16 Nov 2021 21:15:02 +0100
parents 63b0b7b79b25
children dce918af0c00
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>
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1125
diff changeset
4 " $Id: bst.vim,v 1.1 2007/05/05 18:11:12 vimboss Exp $
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 expandtab
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
12 setlocal indentexpr=GetBstIndent(v:lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
13 "setlocal smartindent
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
14 setlocal cinkeys&
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
15 setlocal cinkeys-=0#
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
16 setlocal indentkeys&
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
17 "setlocal indentkeys+=0%
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
18
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
19 " Only define the function once.
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
20 if exists("*GetBstIndent")
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
21 finish
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
22 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
23
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
24 function! s:prevgood(lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
25 " Find a non-blank line above the current line.
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
26 " Skip over comments.
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
27 let lnum = a:lnum
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
28 while lnum > 0
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
29 let lnum = prevnonblank(lnum - 1)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
30 if getline(lnum) !~ '^\s*%.*$'
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
31 break
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
32 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
33 endwhile
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
34 return lnum
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
35 endfunction
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
36
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
37 function! s:strip(lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
38 let line = getline(a:lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
39 let line = substitute(line,'"[^"]*"','""','g')
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
40 let line = substitute(line,'%.*','','')
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
41 let line = substitute(line,'^\s\+','','')
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
42 return line
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
43 endfunction
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
44
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
45 function! s:count(string,char)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
46 let str = substitute(a:string,'[^'.a:char.']','','g')
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
47 return strlen(str)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
48 endfunction
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
49
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
50 function! GetBstIndent(lnum) abort
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
51 if a:lnum == 1
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
52 return 0
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
53 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
54 let lnum = s:prevgood(a:lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
55 if lnum <= 0
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
56 return indent(a:lnum - 1)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
57 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
58 let line = s:strip(lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
59 let cline = s:strip(a:lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
60 if cline =~ '^}' && exists("b:current_syntax")
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
61 call cursor(a:lnum,indent(a:lnum))
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
62 if searchpair('{','','}','bW',"synIDattr(synID(line('.'),col('.'),1),'name') =~? 'comment\\|string'")
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
63 if col('.')+1 == col('$')
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
64 return indent('.')
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
65 else
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
66 return virtcol('.')-1
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
67 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
68 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
69 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
70 let fakeline = substitute(line,'^}','','').matchstr(cline,'^}')
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
71 let ind = indent(lnum)
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 2034
diff changeset
72 let ind = ind + shiftwidth() * s:count(line,'{')
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 2034
diff changeset
73 let ind = ind - shiftwidth() * s:count(fakeline,'}')
1125
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
74 return ind
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
75 endfunction