aboutsummaryrefslogtreecommitdiff
path: root/modules/textadept
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2013-01-31 11:16:21 -0500
committermitchell <70453897+667e-11@users.noreply.github.com>2013-01-31 11:16:21 -0500
commit210e761ac6721de0922e830deaaadfc36a74aa02 (patch)
treefd8c220b248033c90c4c38ff8e195f4f2178d67b /modules/textadept
parenta715bf63d6a62f000f6acd91e20eef9ef00a03c8 (diff)
downloadtextadept-210e761ac6721de0922e830deaaadfc36a74aa02.tar.gz
textadept-210e761ac6721de0922e830deaaadfc36a74aa02.zip
Added ability to type over characters like closing braces and quotes.
Diffstat (limited to 'modules/textadept')
-rw-r--r--modules/textadept/editing.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index b6e00290..f9beab64 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -15,6 +15,12 @@ local M = {}
-- Highlight matching brace characters like "()[]{}".
-- The default value is `true`.
-- Matching braces are defined in the [`braces`](#braces) table.
+-- @field TYPEOVER_CHARS (bool)
+-- Move over the typeover character under the caret when typing it instead of
+-- inserting it.
+-- The default value is `true`.
+-- Typeover characters are defined in the [`typeover_chars`](#typeover_chars)
+-- table.
-- @field AUTOINDENT (bool)
-- Match the indentation level of the previous line when inserting a new line.
-- The default value is `true`.
@@ -35,6 +41,7 @@ module('_M.textadept.editing')]]
M.AUTOPAIR = true
M.HIGHLIGHT_BRACES = true
+M.TYPEOVER_CHARS = true
M.AUTOINDENT = true
M.STRIP_WHITESPACE_ON_SAVE = true
M.MARK_HIGHLIGHT_BACK = buffer and buffer.caret_line_back or
@@ -78,6 +85,17 @@ M.char_matches = {[40] = ')', [91] = ']', [123] = '}', [39] = "'", [34] = '"'}
-- @see HIGHLIGHT_BRACES
M.braces = {[40] = 1, [41] = 1, [91] = 1, [93] = 1, [123] = 1, [125] = 1}
+---
+-- Table of characters to move over when typed, with language-specific typeover
+-- character tables assigned to a lexer name key.
+-- The ASCII values of characters are keys and are assigned non-`nil` values.
+-- The default characters are ')', ']', '}', '&apos;', and '&quot;'.
+-- @class table
+-- @name typeover_chars
+-- @usage _M.textadept.editing.typeover_chars.hypertext = {..., [62] = 1}
+-- @see TYPEOVER_CHARS
+M.typeover_chars = {[41] = 1, [93] = 1, [125] = 1, [39] = 1, [34] = 1}
+
-- The current call tip.
-- Used for displaying call tips.
-- @class table
@@ -122,6 +140,16 @@ events_connect(events.UPDATE_UI, function()
end
end)
+-- Moves over typeover characters when typed.
+events_connect(events.KEYPRESS, function(code)
+ if not M.TYPEOVER_CHARS then return end
+ local buffer = buffer
+ if M.typeover_chars[code] and buffer.char_at[buffer.current_pos] == code then
+ buffer:char_right()
+ return true
+ end
+end)
+
-- Auto-indent on return.
events_connect(events.CHAR_ADDED, function(char)
if not M.AUTOINDENT or char ~= 10 then return end