mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	vim-patch:c0f7505: 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: vim/vim#15364
c0f7505ede
Co-authored-by: Yinzuo Jiang <jiangyinzuo@foxmail.com>
			
			
This commit is contained in:
		| @@ -4,6 +4,7 @@ | |||||||
| " First Author:	Max Ischenko <mfi 'at' ukr.net> | " First Author:	Max Ischenko <mfi 'at' ukr.net> | ||||||
| " Last Change:	2017 Jun 13 | " Last Change:	2017 Jun 13 | ||||||
| "		2022 Sep 07: b:undo_indent added by Doug Kearns | "		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. | " Only load this indent file when no other was loaded. | ||||||
| if exists("b:did_indent") | if exists("b:did_indent") | ||||||
| @@ -46,12 +47,12 @@ function! GetLuaIndentIntern() | |||||||
|   endif |   endif | ||||||
|  |  | ||||||
|   " Add a 'shiftwidth' after lines that start a block: |   " 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 ind = indent(prevlnum) | ||||||
|   let prevline = getline(prevlnum) |   let prevline = getline(prevlnum) | ||||||
|   let midx = match(prevline, '^\s*\%(if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\|then\>\)') |   let midx = match(prevline, '^\s*\%(if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\|then\>\)') | ||||||
|   if midx == -1 |   if midx == -1 | ||||||
|     let midx = match(prevline, '{\s*\%(--\%([^[].*\)\?\)\?$') |     let midx = match(prevline, '\%({\|(\)\s*\%(--\%([^[].*\)\?\)\?$') | ||||||
|     if midx == -1 |     if midx == -1 | ||||||
|       let midx = match(prevline, '\<function\>\s*\%(\k\|[.:]\)\{-}\s*(') |       let midx = match(prevline, '\<function\>\s*\%(\k\|[.:]\)\{-}\s*(') | ||||||
|     endif |     endif | ||||||
| @@ -65,9 +66,9 @@ function! GetLuaIndentIntern() | |||||||
|     endif |     endif | ||||||
|   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'. |   " 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" |   if midx != -1 && synIDattr(synID(v:lnum, midx + 1, 1), "name") != "luaComment" | ||||||
|     let ind = ind - shiftwidth() |     let ind = ind - shiftwidth() | ||||||
|   endif |   endif | ||||||
|   | |||||||
							
								
								
									
										19
									
								
								runtime/indent/testdir/lua.in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								runtime/indent/testdir/lua.in
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||||
							
								
								
									
										19
									
								
								runtime/indent/testdir/lua.ok
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								runtime/indent/testdir/lua.ok
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||||
		Reference in New Issue
	
	Block a user
	 Christian Clason
					Christian Clason