aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/events.lua33
-rw-r--r--modules/textadept/editing.lua17
2 files changed, 17 insertions, 33 deletions
diff --git a/core/events.lua b/core/events.lua
index 1f8b5682..946d0874 100644
--- a/core/events.lua
+++ b/core/events.lua
@@ -392,39 +392,6 @@ add_handler('uri_dropped',
end
end)
----
--- [Local table] A table of (integer) brace characters with their matches.
--- @class table
--- @name _braces
-local _braces = { -- () [] {} <>
- [40] = 1, [91] = 1, [123] = 1, [60] = 1,
- [41] = 1, [93] = 1, [125] = 1, [62] = 1,
-}
-
----
--- [Local function] Highlights matching/mismatched braces appropriately.
--- @param current_pos The position to match braces at.
-local function match_brace(current_pos)
- local buffer = buffer
- if _braces[buffer.char_at[current_pos]] and
- buffer:get_style_name(buffer.style_at[current_pos]) == 'operator' then
- local pos = buffer:brace_match(current_pos)
- if pos ~= -1 then
- buffer:brace_highlight(current_pos, pos)
- else
- buffer:brace_bad_light(current_pos)
- end
- return true
- end
- return false
-end
-
-add_handler('update_ui',
- function() -- highlights matching braces
- local buffer = buffer
- if not match_brace(buffer.current_pos) then buffer:brace_bad_light(-1) end
- end)
-
local EOLs = {
textadept.locale.STATUS_CRLF,
textadept.locale.STATUS_CR,
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index caf6daa0..e7cc684b 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -75,6 +75,23 @@ textadept.events.add_handler('char_added',
if char_matches[c] then buffer:insert_text(-1, char_matches[c]) end
end)
+textadept.events.add_handler('update_ui',
+ function() -- highlights matching braces
+ local buffer = buffer
+ local current_pos = buffer.current_pos
+ if braces[buffer.char_at[current_pos]] and
+ buffer:get_style_name(buffer.style_at[current_pos]) == 'operator' then
+ local pos = buffer:brace_match(current_pos)
+ if pos ~= -1 then
+ buffer:brace_highlight(current_pos, pos)
+ else
+ buffer:brace_bad_light(current_pos)
+ end
+ else
+ buffer:brace_bad_light(-1)
+ end
+ end)
+
textadept.events.add_handler('char_added',
function(char) -- auto-indent on return
if char ~= '\n' then return end