From c06f3dbe3ee82bd8c9e5d8625b225a937a9e5e9e Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Tue, 11 Jun 2024 08:44:44 +0200 Subject: [PATCH] vim-patch:2d88210: runtime(kdl): include syntax, indent and ftplugin files closes: vim/vim#14956 https://github.com/vim/vim/commit/2d88210b3c8516c30ed104054e5cdaef67880755 Co-authored-by: inzuo Jiang Co-authored-by: Aram Drevekenin --- runtime/ftplugin/kdl.vim | 17 +++++++++++++++ runtime/indent/kdl.vim | 26 +++++++++++++++++++++++ runtime/syntax/kdl.vim | 45 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 runtime/ftplugin/kdl.vim create mode 100644 runtime/indent/kdl.vim create mode 100644 runtime/syntax/kdl.vim diff --git a/runtime/ftplugin/kdl.vim b/runtime/ftplugin/kdl.vim new file mode 100644 index 0000000000..c9a1d8b185 --- /dev/null +++ b/runtime/ftplugin/kdl.vim @@ -0,0 +1,17 @@ +" Vim filetype plugin +" Language: KDL +" Author: Aram Drevekenin +" Maintainer: Yinzuo Jiang +" Last Change: 2024-06-10 + +if exists("b:did_ftplugin") + finish +endif + +let b:did_ftplugin = 1 + +setlocal comments=:// +setlocal commentstring=//\ %s +setlocal formatoptions-=t + +let b:undo_ftplugin = 'setlocal comments< commentstring< formatoptions<' diff --git a/runtime/indent/kdl.vim b/runtime/indent/kdl.vim new file mode 100644 index 0000000000..2d24f18dff --- /dev/null +++ b/runtime/indent/kdl.vim @@ -0,0 +1,26 @@ +" Vim indent file +" Language: KDL +" Author: Aram Drevekenin +" Maintainer: Yinzuo Jiang +" Last Change: 2024-06-10 + +" Only load this indent file when no other was loaded. +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal indentexpr=KdlIndent() +let b:undo_indent = "setlocal indentexpr<" + +function! KdlIndent(...) + let line = getline(v:lnum) + let previousNum = prevnonblank(v:lnum - 1) + let previous = getline(previousNum) + + if previous =~ "{" && previous !~ "}" && line !~ "}" && line !~ ":$" + return indent(previousNum) + &tabstop + else + return indent(previousNum) + endif +endfunction diff --git a/runtime/syntax/kdl.vim b/runtime/syntax/kdl.vim new file mode 100644 index 0000000000..a36bb9e927 --- /dev/null +++ b/runtime/syntax/kdl.vim @@ -0,0 +1,45 @@ +" Vim syntax file +" Language: KDL +" Maintainer: Aram Drevekenin +" Maintainer: Yinzuo Jiang +" Latest Revision: 2024-06-10 + +" quit when a syntax file was already loaded +if exists("b:current_syntax") + finish +endif + +syn match kdlNode '\v(\w|-|\=)' display +syn match kdlBool '\v(true|false)' display + +syn keyword kdlTodo contained TODO FIXME XXX NOTE +syn match kdlComment "//.*$" contains=kdlTodo + +" Regular int like number with - + or nothing in front +syn match kdlNumber '\d\+' +syn match kdlNumber '[-+]\d\+' + +" Floating point number with decimal no E or e (+,-) +syn match kdlNumber '\d\+\.\d*' contained display +syn match kdlNumber '[-+]\d\+\.\d*' contained display + +" Floating point like number with E and no decimal point (+,-) +syn match kdlNumber '[-+]\=\d[[:digit:]]*[eE][\-+]\=\d\+' contained display +syn match kdlNumber '\d[[:digit:]]*[eE][\-+]\=\d\+' contained display + +" Floating point like number with E and decimal point (+,-) +syn match kdlNumber '[-+]\=\d[[:digit:]]*\.\d*[eE][\-+]\=\d\+' contained display +syn match kdlNumber '\d[[:digit:]]*\.\d*[eE][\-+]\=\d\+' contained display + +syn region kdlString start='"' end='"' skip='\\\\\|\\"' display + +syn region kdlChildren start="{" end="}" contains=kdlString,kdlNumber,kdlNode,kdlBool,kdlComment + +hi def link kdlTodo Todo +hi def link kdlComment Comment +hi def link kdlNode Statement +hi def link kdlBool Boolean +hi def link kdlString String +hi def link kdlNumber Number + +let b:current_syntax = "kdl"