view runtime/indent/nsis.vim @ 33947:f4d88db48a63 v9.0.2168

patch 9.0.2168: Moving tabpages on :drop may cause an endless loop Commit: https://github.com/vim/vim/commit/df12e39b8b9dd39056e22b452276622cb7b617fd Author: Christian Brabandt <cb@256bit.org> Date: Sat Dec 16 13:55:32 2023 +0100 patch 9.0.2168: Moving tabpages on :drop may cause an endless loop Problem: Moving tabpages on :drop may cause an endless loop Solution: Disallow moving tabpages on :drop when cleaning up the arglist first Moving tabpages during drop command may cause an endless loop When executing a :tab drop command, Vim will close all windows not in the argument list. This triggers various autocommands. If a user has created an 'au Tabenter * :tabmove -' autocommand, this can cause Vim to end up in an endless loop, when trying to iterate over all tabs (which would trigger the tabmove autocommand, which will change the tpnext pointer, etc). So instead of blocking all autocommands before we actually try to edit the given file, lets simply disallow to move tabpages around. Otherwise, we may change the expected number of events triggered during a :drop command, which users may rely on (there is actually a test, that expects various TabLeave/TabEnter autocommands) and would therefore be a backwards incompatible change. Don't make this an error, as this could trigger several times during the drop command, but silently ignore the :tabmove command in this case (and it should in fact finally trigger successfully when loading the given file in a new tab). So let's just be quiet here instead. fixes: #13676 closes: #13686 Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sat, 16 Dec 2023 14:00:05 +0100
parents d46f974fd69e
children
line wrap: on
line source

" Vim indent file
" Language:		NSIS script
" Maintainer:		Ken Takata
" URL:			https://github.com/k-takata/vim-nsis
" Last Change:		2021-10-18
" Filenames:		*.nsi
" License:		VIM License

if exists("b:did_indent")
  finish
endif
let b:did_indent = 1

setlocal nosmartindent
setlocal noautoindent
setlocal indentexpr=GetNsisIndent(v:lnum)
setlocal indentkeys=!^F,o,O
setlocal indentkeys+==~${Else,=~${EndIf,=~${EndUnless,=~${AndIf,=~${AndUnless,=~${OrIf,=~${OrUnless,=~${Case,=~${Default,=~${EndSelect,=~${EndSwitch,=~${Loop,=~${Next,=~${MementoSectionEnd,=~FunctionEnd,=~SectionEnd,=~SectionGroupEnd,=~PageExEnd,0=~!macroend,0=~!if,0=~!else,0=~!endif

let b:undo_indent = "setl ai< inde< indk< si<"

if exists("*GetNsisIndent")
  finish
endif

function! GetNsisIndent(lnum)
  " If this line is explicitly joined: If the previous line was also joined,
  " line it up with that one, otherwise add two 'shiftwidth'
  if getline(a:lnum - 1) =~ '\\$'
    if a:lnum > 1 && getline(a:lnum - 2) =~ '\\$'
      return indent(a:lnum - 1)
    endif
    return indent(a:lnum - 1) + shiftwidth() * 2
  endif

  " Grab the current line, stripping comments.
  let l:thisl = substitute(getline(a:lnum), '[;#].*$', '', '')
  " Check if this line is a conditional preprocessor line.
  let l:preproc = l:thisl =~? '^\s*!\%(if\|else\|endif\)'

  " Grab the previous line, stripping comments.
  " Skip preprocessor lines and continued lines.
  let l:prevlnum = a:lnum
  while 1
    let l:prevlnum = prevnonblank(l:prevlnum - 1)
    if l:prevlnum == 0
      " top of file
      return 0
    endif
    let l:prevl = substitute(getline(l:prevlnum), '[;#].*$', '', '')
    let l:prevpreproc = l:prevl =~? '^\s*!\%(if\|else\|endif\)'
    if l:preproc == l:prevpreproc && getline(l:prevlnum - 1) !~? '\\$'
      break
    endif
  endwhile
  let l:previ = indent(l:prevlnum)
  let l:ind = l:previ

  if l:preproc
    " conditional preprocessor
    if l:prevl =~? '^\s*!\%(if\%(\%(macro\)\?n\?def\)\?\|else\)\>'
      let l:ind += shiftwidth()
    endif
    if l:thisl =~? '^\s*!\%(else\|endif\)\?\>'
      let l:ind -= shiftwidth()
    endif
    return l:ind
  endif

  if l:prevl =~? '^\s*\%(\${\%(If\|IfNot\|Unless\|ElseIf\|ElseIfNot\|ElseUnless\|Else\|AndIf\|AndIfNot\|AndUnless\|OrIf\|OrIfNot\|OrUnless\|Select\|Case\|Case[2-5]\|CaseElse\|Default\|Switch\|Do\|DoWhile\|DoUntil\|For\|ForEach\|MementoSection\)}\|Function\>\|Section\>\|SectionGroup\|PageEx\>\|!macro\>\)'
    " previous line opened a block
    let l:ind += shiftwidth()
  endif
  if l:thisl =~? '^\s*\%(\${\%(ElseIf\|ElseIfNot\|ElseUnless\|Else\|EndIf\|EndUnless\|AndIf\|AndIfNot\|AndUnless\|OrIf\|OrIfNot\|OrUnless\|Loop\|LoopWhile\|LoopUntil\|Next\|MementoSectionEnd\)\>}\?\|FunctionEnd\>\|SectionEnd\>\|SectionGroupEnd\|PageExEnd\>\|!macroend\>\)'
    " this line closed a block
    let l:ind -= shiftwidth()
  elseif l:thisl =~? '^\s*\${\%(Case\|Case[2-5]\|CaseElse\|Default\)\>}\?'
    if l:prevl !~? '^\s*\${\%(Select\|Switch\)}'
      let l:ind -= shiftwidth()
    endif
  elseif l:thisl =~? '^\s*\${\%(EndSelect\|EndSwitch\)\>}\?'
    " this line closed a block
    if l:prevl =~? '^\s*\${\%(Select\|Switch\)}'
      let l:ind -= shiftwidth()
    else
      let l:ind -= shiftwidth() * 2
    endif
  endif

  return l:ind
endfunction

" vim: ts=8 sw=2 sts=2