view runtime/indent/objc.vim @ 33640:c4d19e3171b7 v9.0.2060

patch 9.0.2060: *.{gn,gni} files are not recognized Commit: https://github.com/vim/vim/commit/84394f2be4a750f1e26b478e36de041663f4b5a4 Author: Amaan Qureshi <amaanq12@gmail.com> Date: Mon Oct 23 19:16:14 2023 +0200 patch 9.0.2060: *.{gn,gni} files are not recognized Problem: *.{gn,gni} files are not recognized Solution: Detect some as gn filetype (without adding an extra filetype) Those come from: https://gn.googlesource.com/gn/ closes: #13405 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Amaan Qureshi <amaanq12@gmail.com>
author Christian Brabandt <cb@256bit.org>
date Mon, 23 Oct 2023 19:30:05 +0200
parents 6dd88e45d47d
children
line wrap: on
line source

"   Vim indent file
"   Language:	    Objective-C
"   Maintainer:	    Kazunobu Kuriyama <kazunobu.kuriyama@nifty.com>
"   Last Change:    2022 Apr 06

" Only load this indent file when no other was loaded.
if exists("b:did_indent")
    finish
endif
let b:did_indent = 1
setlocal cindent

" Set the function to do the work.
setlocal indentexpr=GetObjCIndent()

" To make a colon (:) suggest an indentation other than a goto/switch label,
setlocal indentkeys-=:
setlocal indentkeys+=<:>

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

" Only define the function once.
if exists("*GetObjCIndent")
    finish
endif

function s:GetWidth(line, regexp)
    let end = matchend(a:line, a:regexp)
    let width = 0
    let i = 0
    while i < end
	if a:line[i] != "\t"
	    let width = width + 1
	else
	    let width = width + &ts - (width % &ts)
	endif
	let i = i + 1
    endwhile
    return width
endfunction

function s:LeadingWhiteSpace(line)
    let end = strlen(a:line)
    let width = 0
    let i = 0
    while i < end
	let char = a:line[i]
	if char != " " && char != "\t"
	    break
	endif
	if char != "\t"
	    let width = width + 1
	else
	    let width = width + &ts - (width % &ts)
	endif
	let i = i + 1
    endwhile
    return width
endfunction


function GetObjCIndent()
    let theIndent = cindent(v:lnum)

    let prev_line = getline(v:lnum - 1)
    let cur_line = getline(v:lnum)

    if prev_line !~# ":" || cur_line !~# ":"
	return theIndent
    endif

    if prev_line !~# ";"
	let prev_colon_pos = s:GetWidth(prev_line, ":")
	let delta = s:GetWidth(cur_line, ":") - s:LeadingWhiteSpace(cur_line)
	let theIndent = prev_colon_pos - delta
    endif

    return theIndent
endfunction