8000 Use shiftwidth() instead of &sw in indent/vim.vim by tyru · Pull Request #578 · vim/vim · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use shiftwidth() instead of &sw in indent/vim.vim #578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions runtime/indent/ada.vim
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function s:MainBlockIndent (prev_indent, prev_lnum, blockstart, stop_at)
endwhile
endwhile
" Fallback - just move back one
return a:prev_indent - &sw
return a:prev_indent - shiftwidth()
endfunction MainBlockIndent

" Section: s:EndBlockIndent {{{1
Expand Down Expand Up @@ -131,7 +131,7 @@ function s:EndBlockIndent( prev_indent, prev_lnum, blockstart, blockend )
endwhile
endwhile
" Fallback - just move back one
return a:prev_indent - &sw
return a:prev_indent - shiftwidth()
endfunction EndBlockIndent

" Section: s:StatementIndent {{{1
Expand Down Expand Up @@ -213,15 +213,15 @@ function GetAdaIndent()
endif
" Move indent in
if ! false_match
let ind = ind + &sw
let ind = ind + shiftwidth()
endif
elseif line =~ '^\s*\(case\|exception\)\>'
" Move indent in twice (next 'when' will move back)
let ind = ind + 2 * &sw
let ind = ind + 2 * shiftwidth()
elseif line =~ '^\s*end\s*record\>'
" Move indent back to tallying 'type' preceeding the 'record'.
" Allow indent to be equal to 'end record's.
let ind = s:MainBlockIndent( ind+&sw, lnum, 'type\>', '' )
let ind = s:MainBlockIndent( ind+shiftwidth(), lnum, 'type\>', '' )
elseif line =~ '\(^\s*new\>.*\)\@<!)\s*[;,]\s*$'
" Revert to indent of line that started this parenthesis pair
exe lnum
Expand All @@ -235,10 +235,10 @@ function GetAdaIndent()
exe v:lnum
elseif line =~ '[.=(]\s*$'
" A statement continuation - move in one
let ind = ind + &sw
let ind = ind + shiftwidth()
elseif line =~ '^\s*new\>'
" Multiple line generic instantiation ('package blah is\nnew thingy')
let ind = s:StatementIndent( ind - &sw, lnum )
let ind = s:StatementIndent( ind - shiftwidth(), lnum )
elseif line =~ ';\s*$'
" Statement end (but not 'end' ) - try to find current statement-start indent
let ind = s:StatementIndent( ind, lnum )
Expand All @@ -256,17 +256,17 @@ function GetAdaIndent()
elseif continuation && line =~ '^\s*('
" Don't do this if we've already indented due to the previous line
if ind == initind
let ind = ind + &sw
let ind = ind + shiftwidth()
endif
elseif line =~ '^\s*\(begin\|is\)\>'
let ind = s:MainBlockIndent( ind, lnum, '\(procedure\|function\|declare\|package\|task\)\>', 'begin\>' )
elseif line =~ '^\s*record\>'
let ind = s:MainBlockIndent( ind, lnum, 'type\>\|for\>.*\<use\>', '' ) + &sw
let ind = s:MainBlockIndent( ind, lnum, 'type\>\|for\>.*\<use\>', '' ) + shiftwidth()
elseif line =~ '^\s*\(else\|elsif\)\>'
let ind = s:MainBlockIndent( ind, lnum, 'if\>', '' )
elseif line =~ '^\s*when\>'
" Align 'when' one /in/ from matching block start
let ind = s:MainBlockIndent( ind, lnum, '\(case\|exception\)\>', '' ) + &sw
let ind = s:MainBlockIndent( ind, lnum, '\(case\|exception\)\>', '' ) + shiftwidth()
elseif line =~ '^\s*end\>\s*\<if\>'
" End of if statements
let ind = s:EndBlockIndent( ind, lnum, 'if\>', 'end\>\s*\<if\>' )
Expand Down
6 changes: 3 additions & 3 deletions runtime/indent/awk.vim
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function! GetAwkIndent()
" 'pattern { action }' (simple check match on /{/ increases the indent then)

if s:Get_brace_balance( prev_data, '{', '}' ) > 0
return ind + &sw
return ind + shiftwidth()
endif

let brace_balance = s:Get_brace_balance( prev_data, '(', ')' )
Expand Down Expand Up @@ -99,7 +99,7 @@ function! GetAwkIndent()
return s:Safe_indent( ind, s:First_word_len(prev_data), getline(v:lnum))
else
" if/for/while without '{'
return ind + &sw
return ind + shiftwidth()
endif
endif
endif
Expand Down Expand Up @@ -140,7 +140,7 @@ function! GetAwkIndent()

" Decrease indent if this line contains a '}'.
if getline(v:lnum) =~ '^\s*}'
let ind = ind - &sw
let ind = ind - shiftwidth()
endif

return ind
Expand Down
4 changes: 2 additions & 2 deletions runtime/indent/bst.vim
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function! GetBstIndent(lnum) abort
endif
let fakeline = substitute(line,'^}','','').matchstr(cline,'^}')
let ind = indent(lnum)
let ind = ind + &sw * s:count(line,'{')
let ind = ind - &sw * s:count(fakeline,'}')
let ind = ind + shiftwidth() * s:count(line,'{')
let ind = ind - shiftwidth() * s:count(fakeline,'}')
return ind
endfunction
5 changes: 2 additions & 3 deletions runtime/indent/bzl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ function GetBzlIndent(lnum) abort
endif
" Vim 7.3.693 and later defines a shiftwidth() function to get the effective
" shiftwidth value. Fall back to &shiftwidth if the function doesn't exist.
let l:sw_expr = exists('*shiftwidth') ? 'shiftwidth()' : '&shiftwidth'
let g:pyindent_nested_paren = l:sw_expr . ' * 2'
let g:pyindent_open_paren = l:sw_expr . ' * 2'
let g:pyindent_nested_paren = 'shiftwidth() * 2'
let g:pyindent_open_paren = 'shiftwidth() * 2'
endif

let l:indent = -1
Expand Down
18 changes: 9 additions & 9 deletions runtime/indent/cdl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fun! CdlGetIndent(lnum)
let thisline = getline(a:lnum)
if match(thisline, '^\s*\(\k\+\|\[[^]]*]\)\s*\(,\|;\s*$\)') >= 0
" it's an attributes line
return &sw
return shiftwidth()
elseif match(thisline, '^\c\s*\([{}]\|\/[*/]\|dimension\|schedule\|group\|hierarchy\|class\)') >= 0
" it's a header or '{' or '}' or a comment
return 0
Expand All @@ -71,13 +71,13 @@ fun! CdlGetIndent(lnum)
let c = line[inicio-1]
" ')' and '=' don't change indent and are useless to set 'f'
if c == '{'
return &sw
return shiftwidth()
elseif c != ')' && c != '='
let f = 1 " all but 'elseif' are followed by a formula
if c ==? 'n' || c ==? 'e' " 'then', 'else'
let ind = ind + &sw
let ind = ind + shiftwidth()
elseif strpart(line, inicio-6, 6) ==? 'elseif' " elseif, set f to conditional
let ind = ind + &sw
let ind = ind + shiftwidth()
let f = 0
end
end
Expand All @@ -98,30 +98,30 @@ fun! CdlGetIndent(lnum)
let ind = 0
let f = 1
elseif c == ')' || c== ';' || strpart(line, inicio-5, 5) ==? 'endif'
let ind = ind - &sw
let ind = ind - shiftwidth()
elseif c == '(' || c ==? 'f' " '(' or 'if'
let ind = ind + &sw
let ind = ind + shiftwidth()
else " c == '='
" if it is an asignment increase indent
if f == -1 " we don't know yet, find out
let f = CdlAsignment(lnum, strpart(line, 0, inicio))
end
if f == 1 " formula increase it
let ind = ind + &sw
let ind = ind + shiftwidth()
end
end
endw

" CURRENT LINE, if it starts with a closing element, decrease indent
" or if it starts with '=' (asignment), increase indent
if match(thisline, '^\c\s*\(else\|then\|endif\|[);]\)') >= 0
let ind = ind - &sw
let ind = ind - shiftwidth()
elseif match(thisline, '^\s*=') >= 0
if f == -1 " we don't know yet if is an asignment, find out
let f = CdlAsignment(lnum, "")
end
if f == 1 " formula increase it
let ind = ind + &sw
let ind = ind + shiftwidth()
end
end

Expand Down
6 changes: 3 additions & 3 deletions runtime/indent/chaiscript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ function! GetChaiScriptIndent()
let flag = 0
let prevline = getline(lnum)
if prevline =~ '^.*{.*'
let ind = ind + &shiftwidth
let ind = ind + shiftwidth()
let flag = 1
endif

" Subtract a 'shiftwidth' after lines containing a { followed by a }
" to keep it balanced
if flag == 1 && prevline =~ '.*{.*}.*'
let ind = ind - &shiftwidth
let ind = ind - shiftwidth()
endif

" Subtract a 'shiftwidth' on lines ending with }
if getline(v:lnum) =~ '^\s*\%(}\)'
let ind = ind - &shiftwidth
let ind = ind - shiftwidth()
endif

return ind
Expand Down
8 changes: 4 additions & 4 deletions runtime/indent/clojure.vim
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ if exists("*searchpairpos")
call cursor(paren)

if s:IsMethodSpecialCase(paren)
return paren[1] + &shiftwidth - 1
return paren[1] + shiftwidth() - 1
endif

" In case we are at the last character, we use the paren position.
Expand Down Expand Up @@ -281,19 +281,19 @@ if exists("*searchpairpos")
let ww = s:StripNamespaceAndMacroChars(w)

if &lispwords =~# '\V\<' . ww . '\>'
return paren[1] + &shiftwidth - 1
return paren[1] + shiftwidth() - 1
endif

if g:clojure_fuzzy_indent
\ && !s:MatchesOne(g:clojure_fuzzy_indent_blacklist, ww)
\ && s:MatchesOne(g:clojure_fuzzy_indent_patterns, ww)
return paren[1] + &shiftwidth - 1
return paren[1] + shiftwidth() - 1
endif

call search('\v\_s', 'cW')
call search('\v\S', 'W')
if paren[0] < line(".")
return paren[1] + (g:clojure_align_subforms ? 0 : &shiftwidth - 1)
return paren[1] + (g:clojure_align_subforms ? 0 : shiftwidth() - 1)
endif

call search('\v\S', 'bW')
Expand Down
8 changes: 4 additions & 4 deletions runtime/indent/cmake.vim
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ fun! CMakeGetIndent(lnum)
let ind = ind
else
if previous_line =~? cmake_indent_begin_regex
let ind = ind + &sw
let ind = ind + shiftwidth()
endif
if previous_line =~? cmake_indent_open_regex
let ind = ind + &sw
let ind = ind + shiftwidth()
endif
endif

" Subtract
if this_line =~? cmake_indent_end_regex
let ind = ind - &sw
let ind = ind - shiftwidth()
endif
if previous_line =~? cmake_indent_close_regex
let ind = ind - &sw
let ind = ind - shiftwidth()
endif

return ind
Expand Down
24 changes: 12 additions & 12 deletions runtime/indent/cobol.vim
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ function! s:optionalblock(lnum,ind,blocks,clauses)
if getline(lastclause) =~? clauses && s:stripped(lastclause) !~? '^'.begin
let ind = indent(lastclause)
elseif lastclause > 0
let ind = indent(lastclause) + &sw
"let ind = ind + &sw
let ind = indent(lastclause) + shiftwidth()
"let ind = ind + shiftwidth()
endif
elseif line =~? clauses && cline !~? end
let ind = ind + &sw
let ind = ind + shiftwidth()
endif
return ind
endfunction
Expand Down Expand Up @@ -98,8 +98,8 @@ function! GetCobolIndent(lnum) abort
let num = matchstr(line,'^\s*\zs\d\+\>')
if 0+cnum == num
return lindent
elseif 0+cnum > num && default < lindent + &sw
let default = lindent + &sw
elseif 0+cnum > num && default < lindent + shiftwidth()
let default = lindent + shiftwidth()
endif
elseif lindent < bshft && lindent >= ashft
break
Expand Down Expand Up @@ -135,13 +135,13 @@ function! GetCobolIndent(lnum) abort
if line =~? '^PERFORM\>'
let perfline = substitute(line, '\c^PERFORM\s*', "", "")
if perfline =~? '^\%(\k\+\s\+TIMES\)\=\s*$'
let ind = ind + &sw
let ind = ind + shiftwidth()
elseif perfline =~? '^\%(WITH\s\+TEST\|VARYING\|UNTIL\)\>.*[^.]$'
let ind = ind + &sw
let ind = ind + shiftwidth()
endif
endif
if line =~? '^\%(IF\|THEN\|ELSE\|READ\|EVALUATE\|SEARCH\|SELECT\)\>'
let ind = ind + &sw
let ind = ind + shiftwidth()
endif
let ind = s:optionalblock(a:lnum,ind,'ADD\|COMPUTE\|DIVIDE\|MULTIPLY\|SUBTRACT','ON\s\+SIZE\s\+ERROR')
let ind = s:optionalblock(a:lnum,ind,'STRING\|UNSTRING\|ACCEPT\|DISPLAY\|CALL','ON\s\+OVERFLOW\|ON\s\+EXCEPTION')
Expand All @@ -157,18 +157,18 @@ function! GetCobolIndent(lnum) abort
"&& s:stripped(lastclause) !~? '^\%(SEARCH\|EVALUATE\|READ\)\>'
let ind = indent(lastclause)
elseif lastclause > 0
let ind = indent(lastclause) + &sw
let ind = indent(lastclause) + shiftwidth()
endif
elseif line =~? '^WHEN\>'
let ind = ind + &sw
let ind = ind + shiftwidth()
endif
"I'm not sure why I had this
"if line =~? '^ELSE\>-\@!' && line !~? '\.$'
"let ind = indent(s:prevgood(lnum))
"endif
if cline =~? '^\(END\)\>-\@!'
" On lines with just END, 'guess' a simple shift left
let ind = ind - &sw
let ind = ind - shiftwidth()
elseif cline =~? '^\(END-IF\|THEN\|ELSE\)\>-\@!'
call cursor(a:lnum,indent(a:lnum))
let match = searchpair('\c-\@<!\<IF\>','\c-\@<!\%(THEN\|ELSE\)\>','\c-\@<!\<END-IF\>\zs','bnW',s:skip)
Expand Down Expand Up @@ -209,7 +209,7 @@ function! GetCobolIndent(lnum) abort
if match > 0
let ind = indent(match)
elseif cline =~? '^\(END-\(READ\|EVALUATE\|SEARCH\|PERFORM\)\)\>'
let ind = ind - &sw
let ind = ind - shiftwidth()
endif
endif
return ind < bshft ? bshft : ind
Expand Down
4 changes: 2 additions & 2 deletions runtime/indent/css.vim
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ function GetCSSIndent()
return 0
endif

return indent(pnum) + s:count_braces(pnum, 1) * &sw
\ - s:count_braces(v:lnum, 0) * &sw
return indent(pnum) + s:count_braces(pnum, 1) * shiftwidth()
\ - s:count_braces(v:lnum, 0) * shiftwidth()
endfunction

let &cpo = s:keepcpo
Expand Down
18 changes: 9 additions & 9 deletions runtime/indent/cucumber.vim
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,38 @@ function! GetCucumberIndent()
return 0
elseif csyn ==# 'cucumberExamples' || cline =~# '^\s*\%(Examples\|Scenarios\):'
" examples heading
return 2 * &sw
return 2 * shiftwidth()
elseif csyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || cline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
" background, scenario or outline heading
return &sw
return shiftwidth()
elseif syn ==# 'cucumberFeature' || line =~# '^\s*Feature:'
" line after feature heading
return &sw
return shiftwidth()
elseif syn ==# 'cucumberExamples' || line =~# '^\s*\%(Examples\|Scenarios\):'
" line after examples heading
return 3 * &sw
return 3 * shiftwidth()
elseif syn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || line =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
" line after background, scenario or outline heading
return 2 * &sw
return 2 * shiftwidth()
elseif cline =~# '^\s*[@#]' && (nsyn == 'cucumberFeature' || nline =~# '^\s*Feature:' || indent(prevnonblank(v:lnum-1)) <= 0)
" tag or comment before a feature heading
return 0
elseif cline =~# '^\s*@'
" other tags
return &sw
return shiftwidth()
elseif cline =~# '^\s*[#|]' && line =~# '^\s*|'
" mid-table
" preserve indent
return indent(prevnonblank(v:lnum-1))
elseif cline =~# '^\s*|' && line =~# '^\s*[^|]'
" first line of a table, relative indent
return indent(prevnonblank(v:lnum-1)) + &sw
return indent(prevnonblank(v:lnum-1)) + shiftwidth()
elseif cline =~# '^\s*[^|]' && line =~# '^\s*|'
" line after a table, relative unindent
return indent(prevnonblank(v:lnum-1)) - &sw
return indent(prevnonblank(v:lnum-1)) - shiftwidth()
elseif cline =~# '^\s*#' && getline(v:lnum-1) =~ '^\s*$' && (nsyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || nline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):')
" comments on scenarios
return &sw
return shiftwidth()
endif
return indent(prevnonblank(v:lnum-1))
endfunction
Expand Down
Loading
0