changeset 35437:122598cc42ad

runtime(kdl): fix KdlIndent and kdlComment in indent script (#15019) Commit: https://github.com/vim/vim/commit/79da22de755e28bd8d4f58fc4bf34cf94f45de63 Author: Yinzuo Jiang <jiangyinzuo@foxmail.com> Date: Sun Jun 16 14:47:47 2024 +0800 runtime(kdl): fix KdlIndent and kdlComment in indent script (https://github.com/vim/vim/issues/15019) Signed-off-by: Yinzuo Jiang <jiangyinzuo@foxmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sun, 16 Jun 2024 09:00:05 +0200
parents 25d570ccb6d8
children d7d80c615656
files runtime/indent/kdl.vim runtime/syntax/kdl.vim
diffstat 2 files changed, 19 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/runtime/indent/kdl.vim
+++ b/runtime/indent/kdl.vim
@@ -2,7 +2,7 @@
 " Language:         KDL
 " Author:           Aram Drevekenin <aram@poor.dev>
 " Maintainer:       Yinzuo Jiang <jiangyinzuo@foxmail.com>
-" Last Change:      2024-06-11
+" Last Change:      2024-06-16
 
 " Only load this indent file when no other was loaded.
 if exists("b:did_indent")
@@ -14,13 +14,17 @@ setlocal indentexpr=KdlIndent()
 let b:undo_indent = "setlocal indentexpr<"
 
 function! KdlIndent(...)
-  let line = getline(v:lnum)
+  let line = substitute(getline(v:lnum), '//.*$', '', '')
   let previousNum = prevnonblank(v:lnum - 1)
-  let previous = getline(previousNum)
+  let previous = substitute(getline(previousNum), '//.*$', '', '')
 
-  if previous =~ "{" && previous !~ "}" && line !~ "}" && line !~ ":$"
-    return indent(previousNum) + shiftwidth()
-  else
-    return indent(previousNum)
+  let l:indent = indent(previousNum)
+  if previous =~ "{" && previous !~ "}"
+    let l:indent += shiftwidth()
   endif
+  if line =~ "}" && line !~ "{"
+    let l:indent -= shiftwidth()
+  endif
+  return l:indent
 endfunction
+" vim: sw=2 sts=2 et
--- a/runtime/syntax/kdl.vim
+++ b/runtime/syntax/kdl.vim
@@ -2,7 +2,7 @@
 " Language: KDL
 " Maintainer: Aram Drevekenin <aram@poor.dev>
 " Maintainer: Yinzuo Jiang <jiangyinzuo@foxmail.com>
-" Latest Revision: 2024-06-10
+" Latest Revision: 2024-06-16
 
 " quit when a syntax file was already loaded
 if exists("b:current_syntax")
@@ -13,7 +13,8 @@ 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
+syn region  kdlComment start="//"  end="$"   contains=kdlTodo,@Spell
+syn region  kdlComment start="/\*" end="\*/" contains=kdlTodo,@Spell
 
 " Regular int like number with - + or nothing in front
 syn match kdlNumber '\d\+'
@@ -22,17 +23,17 @@ 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
@@ -43,3 +44,5 @@ hi def link kdlString      String
 hi def link kdlNumber      Number
 
 let b:current_syntax = "kdl"
+
+" vim: sw=2 sts=2 et