view runtime/indent/context.vim @ 33844:58c9f11eae5b v9.0.2134

patch 9.0.2134: ml_get error when scrolling Commit: https://github.com/vim/vim/commit/c4ffeddfe5bd1824650e9b911ed9245bf56c69e3 Author: Christian Brabandt <cb@256bit.org> Date: Mon Nov 27 23:25:03 2023 +0100 patch 9.0.2134: ml_get error when scrolling Problem: ml_get error when scrolling after delete Solution: mark topline to be validated in main_loop if it is larger than current buffers line count reset_lnums() is called after e.g. TextChanged autocommands and it may accidentally cause curwin->w_topline to become invalid, e.g. if the autocommand has deleted some lines. So verify that curwin->w_topline points to a valid line and if not, mark the window to have w_topline recalculated in main_loop() in update_topline() after reset_lnums() returns. fixes: #13568 fixes: #13578 Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Mon, 27 Nov 2023 23:30:04 +0100
parents f00c56ee8118
children d81556766132
line wrap: on
line source

vim9script

# Language:           ConTeXt typesetting engine
# Maintainer:         Nicola Vitacolonna <nvitacolonna@gmail.com>
# Former Maintainers: Nikolai Weibull <now@bitwi.se>
# Latest Revision:    2022 Aug 12

if exists("b:did_indent")
  finish
endif

# Load MetaPost indentation script (this will also set b:did_indent)
runtime! indent/mp.vim

setlocal indentexpr=ConTeXtIndent()

b:undo_indent = "setl indentexpr<"

def PrevNotComment(l: number): number
  var prevlnum = prevnonblank(l)

  while prevlnum > 0 && getline(prevlnum) =~# '^\s*%'
    prevlnum = prevnonblank(prevlnum - 1)
  endwhile

  return prevlnum
enddef

def FindPair(pstart: string, pmid: string, pend: string): number
  cursor(v:lnum, 1)
  return indent(searchpair(pstart, pmid, pend, 'bWn',
    'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"'))
enddef

def ConTeXtIndent(): number
  # Use MetaPost rules inside MetaPost graphic environments
  if len(synstack(v:lnum, 1)) > 0 &&
    synIDattr(synstack(v:lnum, 1)[0], "name") ==# 'contextMPGraphic'
    return g:MetaPostIndent()
  endif

  const prevlnum = PrevNotComment(v:lnum - 1)
  const prevind  = indent(prevlnum)
  const prevline = getline(prevlnum)
  const currline = getline(v:lnum)

  # If the current line starts with ], match indentation.
  if currline =~# '^\s*\]'
    return FindPair('\[', '', '\]')
  endif

  # If the current line starts with }, match indentation.
  if currline =~# '^\s*}'
    return FindPair('{', '', '}')
  endif

  # If the previous line ends with [ or { (possibly followed by a comment) then indent.
  if prevline =~# '[{[]\s*\%(%.*\)\=$'
    return prevind + shiftwidth()
  endif

  return -1
enddef

# vim: sw=2 fdm=marker