view runtime/indent/treetop.vim @ 32017:b4e5d28b788c v9.0.1340

patch 9.0.1340: Coverity warns for using NULL pointer Commit: https://github.com/vim/vim/commit/666cb9c5303753fef7039e9a9e5fbe9a44299607 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Feb 22 12:35:17 2023 +0000 patch 9.0.1340: Coverity warns for using NULL pointer Problem: Coverity warns for using NULL pointer. Solution: Check that lhs_type is not NULL.
author Bram Moolenaar <Bram@vim.org>
date Wed, 22 Feb 2023 13:45:04 +0100
parents 4d76b3e07c07
children
line wrap: on
line source

" Vim indent file
" Language:		Treetop
" Maintainer:		Doug Kearns <dougkearns@gmail.com>
" Previous Maintainer:	Nikolai Weibull <now@bitwi.se>
" Last Change:		2022 April 25

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

setlocal indentexpr=GetTreetopIndent()
setlocal indentkeys=0{,0},!^F,o,O,=end
setlocal nosmartindent

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

if exists("*GetTreetopIndent")
  finish
endif

function GetTreetopIndent()
  let pnum = prevnonblank(v:lnum - 1)
  if pnum == 0
    return 0
  endif

  let ind = indent(pnum)
  let line = getline(pnum)

  if line =~ '^\s*\%(grammar\|module\|rule\)\>'
    let ind += shiftwidth()
  endif

  let line = getline(v:lnum)
  if line =~ '^\s*end\>'
    let ind -= shiftwidth()
  end

  return ind
endfunction