annotate runtime/indent/bst.vim @ 5899:60cdaa05a6ad v7.4.292

updated for version 7.4.292 Problem: Searching for "a" does not match accented "a" with new regexp engine, does match with old engine. (David B?rgin) "ca" does not match "ca" with accented "a" with either engine. Solution: Change the old engine, check for following composing character also for single-byte patterns.
author Bram Moolenaar <bram@vim.org>
date Tue, 13 May 2014 18:04:00 +0200
parents 7bc41231fbc7
children 63b0b7b79b25
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)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
72 let ind = ind + &sw * s:count(line,'{')
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
73 let ind = ind - &sw * s:count(fakeline,'}')
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