Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugins: autoclose: Do autoclose in case the next char is a whitespace #3134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/micro/initlua.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func luaImportMicroUtil() *lua.LTable {
ulua.L.SetField(pkg, "RuneAt", luar.New(ulua.L, util.LuaRuneAt))
ulua.L.SetField(pkg, "GetLeadingWhitespace", luar.New(ulua.L, util.LuaGetLeadingWhitespace))
ulua.L.SetField(pkg, "IsWordChar", luar.New(ulua.L, util.LuaIsWordChar))
ulua.L.SetField(pkg, "IsWhitespace", luar.New(ulua.L, util.LuaIsWhitespace))
ulua.L.SetField(pkg, "String", luar.New(ulua.L, util.String))
ulua.L.SetField(pkg, "Unzip", luar.New(ulua.L, util.Unzip))
ulua.L.SetField(pkg, "Version", luar.New(ulua.L, util.Version))
Expand Down
6 changes: 6 additions & 0 deletions internal/util/lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ func LuaIsWordChar(s string) bool {
r, _, _ := DecodeCharacterInString(s)
return IsWordChar(r)
}

// LuaIsWhitespace returns true if the first rune in a whitespace character
func LuaIsWhitespace(s string) bool {
r, _, _ := DecodeCharacterInString(s)
return IsWhitespace(r)
}
2 changes: 1 addition & 1 deletion runtime/plugins/autoclose/autoclose.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function onRune(bp, r)
if r == charAt(autoclosePairs[i], 1) then
local curLine = bp.Buf:Line(bp.Cursor.Y)

if bp.Cursor.X == uutil.CharacterCountInString(curLine) or not uutil.IsWordChar(charAt(curLine, bp.Cursor.X+1)) then
if bp.Cursor.X == uutil.CharacterCountInString(curLine) or uutil.IsWhitespace(charAt(curLine, bp.Cursor.X+1)) then
-- the '-' here is to derefence the pointer to bp.Cursor.Loc which is automatically made
-- when converting go structs to lua
-- It needs to be dereferenced because the function expects a non pointer struct
Expand Down