annotate runtime/indent/python.vim @ 28514:0f69ddbdde1f

Added tag v8.2.4781 for changeset 6a1e5b188374b4d58fcccbbdccd2727d0e93c3a0
author Bram Moolenaar <Bram@vim.org>
date Mon, 18 Apr 2022 15:45:03 +0200
parents 9c221ad9634a
children 67f31c24291b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim indent file
164
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 20
diff changeset
2 " Language: Python
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 20
diff changeset
3 " Maintainer: Bram Moolenaar <Bram@vim.org>
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 " Original Author: David Bustos <bustos@caltech.edu>
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 24751
diff changeset
5 " Last Change: 2021 Sep 26
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 " Only load this indent file when no other was loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 " Some preliminary settings
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 setlocal nolisp " Make sure lisp indenting doesn't supersede us
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 setlocal autoindent " indentexpr isn't much help otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 setlocal indentexpr=GetPythonIndent(v:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 setlocal indentkeys+=<:>,=elif,=except
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 24751
diff changeset
20 let b:undo_indent = "setl ai< inde< indk< lisp<"
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 24751
diff changeset
21
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 if exists("*GetPythonIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 endif
3507
8201108e9cf0 More runtime file fixes for 'compatible' mode.
Bram Moolenaar <bram@vim.org>
parents: 3496
diff changeset
26 let s:keepcpo= &cpo
8201108e9cf0 More runtime file fixes for 'compatible' mode.
Bram Moolenaar <bram@vim.org>
parents: 3496
diff changeset
27 set cpo&vim
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 164
diff changeset
29 " Come here when loading the script the first time.
8c60f65311fa updated for version 7.0052
vimboss
parents: 164
diff changeset
30
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 let s:maxoff = 50 " maximum number of lines to look backwards for ()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32
20379
7f88f6a3ed4c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15932
diff changeset
33 " See if the specified line is already user-dedented from the expected value.
7f88f6a3ed4c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15932
diff changeset
34 function s:Dedented(lnum, expected)
7f88f6a3ed4c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15932
diff changeset
35 return indent(a:lnum) <= a:expected - shiftwidth()
7f88f6a3ed4c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15932
diff changeset
36 endfunction
7f88f6a3ed4c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15932
diff changeset
37
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 function GetPythonIndent(lnum)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
39
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 " If this line is explicitly joined: If the previous line was also joined,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 " line it up with that one, otherwise add two 'shiftwidth'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 if getline(a:lnum - 1) =~ '\\$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 if a:lnum > 1 && getline(a:lnum - 2) =~ '\\$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 return indent(a:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 endif
4992
ceb5f21cda79 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3507
diff changeset
46 return indent(a:lnum - 1) + (exists("g:pyindent_continue") ? eval(g:pyindent_continue) : (shiftwidth() * 2))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 " If the start of the line is in a string don't change the indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 if has('syntax_items')
8
7edf9b6e4c36 Various changes
vimboss
parents: 7
diff changeset
51 \ && synIDattr(synID(a:lnum, 1, 1), "name") =~ "String$"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 return -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 " Search backwards for the previous non-empty line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 let plnum = prevnonblank(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 if plnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 " This is the first non-empty line, use zero indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62
15932
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
63 call cursor(plnum, 1)
14945
4ee65b4150fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 5220
diff changeset
64
15932
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
65 " Identing inside parentheses can be very slow, regardless of the searchpair()
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
66 " timeout, so let the user disable this feature if he doesn't need it
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
67 let disable_parentheses_indenting = get(g:, "pyindent_disable_parentheses_indenting", 0)
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
68
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
69 if disable_parentheses_indenting == 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 let plindent = indent(plnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 let plnumstart = plnum
15932
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
72 else
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
73 " searchpair() can be slow sometimes, limit the time to 150 msec or what is
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
74 " put in g:pyindent_searchpair_timeout
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
75 let searchpair_stopline = 0
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
76 let searchpair_timeout = get(g:, 'pyindent_searchpair_timeout', 150)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77
15932
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
78 " If the previous line is inside parenthesis, use the indent of the starting
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
79 " line.
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
80 " Trick: use the non-existing "dummy" variable to break out of the loop when
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
81 " going too far back.
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
82 let parlnum = searchpair('(\|{\|\[', '', ')\|}\|\]', 'nbW',
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
83 \ "line('.') < " . (plnum - s:maxoff) . " ? dummy :"
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
84 \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
85 \ . " =~ '\\(Comment\\|Todo\\|String\\)$'",
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
86 \ searchpair_stopline, searchpair_timeout)
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
87 if parlnum > 0
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
88 let plindent = indent(parlnum)
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
89 let plnumstart = parlnum
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
90 else
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
91 let plindent = indent(plnum)
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
92 let plnumstart = plnum
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
93 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94
15932
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
95 " When inside parenthesis: If at the first line below the parenthesis add
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
96 " two 'shiftwidth', otherwise same as previous line.
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
97 " i = (a
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
98 " + b
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
99 " + c)
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
100 call cursor(a:lnum, 1)
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
101 let p = searchpair('(\|{\|\[', '', ')\|}\|\]', 'bW',
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
102 \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :"
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
103 \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
104 \ . " =~ '\\(Comment\\|Todo\\|String\\)$'",
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
105 \ searchpair_stopline, searchpair_timeout)
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
106 if p > 0
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
107 if p == plnum
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
108 " When the start is inside parenthesis, only indent one 'shiftwidth'.
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
109 let pp = searchpair('(\|{\|\[', '', ')\|}\|\]', 'bW',
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
110 \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :"
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
111 \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
112 \ . " =~ '\\(Comment\\|Todo\\|String\\)$'",
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
113 \ searchpair_stopline, searchpair_timeout)
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
114 if pp > 0
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
115 return indent(plnum) + (exists("g:pyindent_nested_paren") ? eval(g:pyindent_nested_paren) : shiftwidth())
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
116 endif
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
117 return indent(plnum) + (exists("g:pyindent_open_paren") ? eval(g:pyindent_open_paren) : (shiftwidth() * 2))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 endif
15932
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
119 if plnumstart == p
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
120 return indent(plnum)
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
121 endif
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
122 return plindent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 endif
15932
c3c1abe7aff2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14945
diff changeset
124
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 " Get the line and remove a trailing comment.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 " Use syntax highlighting attributes when possible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 let pline = getline(plnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 let pline_len = strlen(pline)
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
132 if has('syntax_items')
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
133 " If the last character in the line is a comment, do a binary search for
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
134 " the start of the comment. synID() is slow, a linear search would take
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
135 " too long on a long line.
5220
050893d44c33 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4992
diff changeset
136 if synIDattr(synID(plnum, pline_len, 1), "name") =~ "\\(Comment\\|Todo\\)$"
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
137 let min = 1
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
138 let max = pline_len
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
139 while min < max
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
140 let col = (min + max) / 2
5220
050893d44c33 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4992
diff changeset
141 if synIDattr(synID(plnum, col, 1), "name") =~ "\\(Comment\\|Todo\\)$"
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
142 let max = col
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
143 else
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
144 let min = col + 1
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
145 endif
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
146 endwhile
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
147 let pline = strpart(pline, 0, min - 1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 endif
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
149 else
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
150 let col = 0
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
151 while col < pline_len
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
152 if pline[col] == '#'
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
153 let pline = strpart(pline, 0, col)
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
154 break
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
155 endif
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
156 let col = col + 1
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
157 endwhile
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 8
diff changeset
158 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 " If the previous line ended with a colon, indent this line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 if pline =~ ':\s*$'
4992
ceb5f21cda79 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3507
diff changeset
162 return plindent + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 " If the previous line was a stop-execution statement...
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
166 if getline(plnum) =~ '^\s*\(break\|continue\|raise\|return\|pass\)\>'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 " See if the user has already dedented
20379
7f88f6a3ed4c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15932
diff changeset
168 if s:Dedented(a:lnum, indent(plnum))
7f88f6a3ed4c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15932
diff changeset
169 " If so, trust the user
7f88f6a3ed4c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15932
diff changeset
170 return -1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 endif
20379
7f88f6a3ed4c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15932
diff changeset
172 " If not, recommend one dedent
7f88f6a3ed4c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15932
diff changeset
173 return indent(plnum) - shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 " If the current line begins with a keyword that lines up with "try"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 if getline(a:lnum) =~ '^\s*\(except\|finally\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 let lnum = a:lnum - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 while lnum >= 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 if getline(lnum) =~ '^\s*\(try\|except\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 let ind = indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 if ind >= indent(a:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 return -1 " indent is already less than this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 return ind " line up with previous try or except
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 let lnum = lnum - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 return -1 " no matching "try"!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 " If the current line begins with a header keyword, dedent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 if getline(a:lnum) =~ '^\s*\(elif\|else\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 " Unless the previous line was a one-liner
24751
e69e7133c9cf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 20379
diff changeset
196 if getline(plnumstart) =~ '^\s*\(for\|if\|elif\|try\)\>'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 return plindent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 " Or the user has already dedented
20379
7f88f6a3ed4c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15932
diff changeset
201 if s:Dedented(a:lnum, plindent)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 return -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204
4992
ceb5f21cda79 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3507
diff changeset
205 return plindent - shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 " When after a () construct we probably want to go back to the start line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 " a = (b
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 " + c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 " here
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 if parlnum > 0
20379
7f88f6a3ed4c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15932
diff changeset
213 " ...unless the user has already dedented
7f88f6a3ed4c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15932
diff changeset
214 if s:Dedented(a:lnum, plindent)
7f88f6a3ed4c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15932
diff changeset
215 return -1
7f88f6a3ed4c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15932
diff changeset
216 else
7f88f6a3ed4c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15932
diff changeset
217 return plindent
7f88f6a3ed4c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15932
diff changeset
218 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 return -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224
3496
d1e4abe8342c Fixed compatible mode in most runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
225 let &cpo = s:keepcpo
d1e4abe8342c Fixed compatible mode in most runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
226 unlet s:keepcpo
d1e4abe8342c Fixed compatible mode in most runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
227
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 " vim:sw=2