]> git.lizzy.rs Git - micro.git/blobdiff - runtime/plugins/autoclose/autoclose.lua
Add ` to autoclose
[micro.git] / runtime / plugins / autoclose / autoclose.lua
index 11f202d708e1bd80723ca798e85718d582806411..aed2ec6346af78bd9fe218c27fbd216db5a67a14 100644 (file)
@@ -6,15 +6,14 @@ if GetOption("autoclose") == nil then
     AddOption("autoclose", true)
 end
 
-local autoclosePairs = {"\"\"", "''", "()", "{}", "[]"}
+local autoclosePairs = {"\"\"", "''", "``", "()", "{}", "[]"}
 local autoNewlinePairs = {"()", "{}", "[]"}
 
-function onRune(r)
+function onRune(r, v)
     if not GetOption("autoclose") then
         return
     end
 
-    local v = CurView()
     for i = 1, #autoclosePairs do
         if r == charAt(autoclosePairs[i], 2) then
             local curLine = v.Buf:Line(v.Cursor.Y)
@@ -43,12 +42,11 @@ function onRune(r)
     end
 end
 
-function preInsertNewline()
+function preInsertNewline(v)
     if not GetOption("autoclose") then
         return
     end
 
-    local v = CurView()
     local curLine = v.Buf:Line(v.Cursor.Y)
     local curRune = charAt(curLine, v.Cursor.X)
     local nextRune = charAt(curLine, v.Cursor.X+1)
@@ -68,13 +66,11 @@ function preInsertNewline()
     return true
 end
 
-function preBackspace()
+function preBackspace(v)
     if not GetOption("autoclose") then
         return
     end
 
-    local v = CurView()
-
     for i = 1, #autoclosePairs do
         local curLine = v.Buf:Line(v.Cursor.Y)
         if charAt(curLine, v.Cursor.X+1) == charAt(autoclosePairs[i], 2) and charAt(curLine, v.Cursor.X) == charAt(autoclosePairs[i], 1) then