Created
May 21, 2023 03:20
-
-
Save xebecnan/d4cbf9f5e3aa0101c7db7cda7d8f7d75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 清理 Lua 文件头多余的 local 赋值语句 TidyLuaHeadStatements { | |
fun! IsLuaLocalAssignStatement() | |
return getline(".") =~ '^local\s\+\S\+\s*=' | |
endfun | |
fun! IsNecessaryLuaAssignment() | |
let v1 = line('.') | |
silent! exe "norm! #" | |
let v2 = line('.') | |
silent! exe "norm! N" | |
return v1 != v2 | |
endfun | |
fun! TidyLuaHeadStatements() | |
if getline('.') !~ '^\s*$' | |
if !IsLuaLocalAssignStatement() | |
echo "not lua local assignment statement" | |
return | |
endif | |
exec "norm! 0w" | |
if !IsNecessaryLuaAssignment() | |
exec "norm! dd" | |
endif | |
endif | |
if line('.') <= 1 | |
echo "first line reached" | |
return | |
endif | |
exec "norm! k" | |
call TidyLuaHeadStatements() | |
endfun | |
command! TidyLuaHeadStatements call TidyLuaHeadStatements() | |
" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment