changeset 35903:6f6e7c2de606

runtime(lua): add/subtract a 'shiftwidth' after '('/')' in indentexpr Commit: https://github.com/vim/vim/commit/c0f7505edeb36bf3e19386f276cafad7cba717a2 Author: Yinzuo Jiang <jiangyinzuo@foxmail.com> Date: Sun Aug 4 18:47:25 2024 +0200 runtime(lua): add/subtract a 'shiftwidth' after '('/')' in indentexpr Problem: - Current lua indentexpr does not indent for '(' ')'. - Missing indent test for lua. Solution: - Match '(', ')' in `function GetLuaIndentIntern`. - Add an indent test for lua. closes: #15364 Signed-off-by: Yinzuo Jiang <jiangyinzuo@foxmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sun, 04 Aug 2024 19:00:03 +0200
parents 13394fa0ebb1
children 22115335ed40
files runtime/indent/lua.vim runtime/indent/testdir/lua.in runtime/indent/testdir/lua.ok
diffstat 3 files changed, 43 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/runtime/indent/lua.vim
+++ b/runtime/indent/lua.vim
@@ -4,6 +4,7 @@
 " First Author:	Max Ischenko <mfi 'at' ukr.net>
 " Last Change:	2017 Jun 13
 "		2022 Sep 07: b:undo_indent added by Doug Kearns
+"		2024 Jul 27: by Vim project: match '(', ')' in function GetLuaIndentIntern()
 
 " Only load this indent file when no other was loaded.
 if exists("b:did_indent")
@@ -46,12 +47,12 @@ function! GetLuaIndentIntern()
   endif
 
   " Add a 'shiftwidth' after lines that start a block:
-  " 'function', 'if', 'for', 'while', 'repeat', 'else', 'elseif', '{'
+  " 'function', 'if', 'for', 'while', 'repeat', 'else', 'elseif', '{', '('
   let ind = indent(prevlnum)
   let prevline = getline(prevlnum)
   let midx = match(prevline, '^\s*\%(if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\|then\>\)')
   if midx == -1
-    let midx = match(prevline, '{\s*\%(--\%([^[].*\)\?\)\?$')
+    let midx = match(prevline, '\%({\|(\)\s*\%(--\%([^[].*\)\?\)\?$')
     if midx == -1
       let midx = match(prevline, '\<function\>\s*\%(\k\|[.:]\)\{-}\s*(')
     endif
@@ -65,9 +66,9 @@ function! GetLuaIndentIntern()
     endif
   endif
 
-  " Subtract a 'shiftwidth' on end, else, elseif, until and '}'
+  " Subtract a 'shiftwidth' on end, else, elseif, until, '}' and ')'
   " This is the part that requires 'indentkeys'.
-  let midx = match(getline(v:lnum), '^\s*\%(end\>\|else\>\|elseif\>\|until\>\|}\)')
+  let midx = match(getline(v:lnum), '^\s*\%(end\>\|else\>\|elseif\>\|until\>\|}\|)\)')
   if midx != -1 && synIDattr(synID(v:lnum, midx + 1, 1), "name") != "luaComment"
     let ind = ind - shiftwidth()
   endif
new file mode 100644
--- /dev/null
+++ b/runtime/indent/testdir/lua.in
@@ -0,0 +1,19 @@
+-- vim: set ft=lua sw=2 noet:
+
+-- START_INDENT
+function foo(a, b, c, d)
+ return { a, b, c, d }
+end
+
+local a = foo(
+1,
+2,
+"longxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
+4
+)
+
+local b = {
+1,
+ 2,
+}
+-- END_INDENT
new file mode 100644
--- /dev/null
+++ b/runtime/indent/testdir/lua.ok
@@ -0,0 +1,19 @@
+-- vim: set ft=lua sw=2 noet:
+
+-- START_INDENT
+function foo(a, b, c, d)
+  return { a, b, c, d }
+end
+
+local a = foo(
+  1,
+  2,
+  "longxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
+  4
+)
+
+local b = {
+  1,
+  2,
+}
+-- END_INDENT