aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/06_AdeptEditing.md5
-rw-r--r--doc/08_Preferences.md6
-rw-r--r--modules/textadept/editing.lua28
3 files changed, 35 insertions, 4 deletions
diff --git a/doc/06_AdeptEditing.md b/doc/06_AdeptEditing.md
index e28daf7c..3704e208 100644
--- a/doc/06_AdeptEditing.md
+++ b/doc/06_AdeptEditing.md
@@ -14,8 +14,9 @@ below.
Usually, quote (''', '"') and brace ('(', '[', '{') characters go
together in pairs. By default, Textadept automatically inserts the complement
character when the first is typed. Similarly, the complement is deleted when you
-press `Bksp` (`⌫` on Mac OSX | `Bksp` in ncurses) over the first. See the
-[preferences][] page if you would like to disable this.
+press `Bksp` (`⌫` on Mac OSX | `Bksp` in ncurses) over the first. Typing over
+complement characters is also supported. See the [preferences][] page if you
+would like to disable these features.
[preferences]: 08_Preferences.html#Generic
diff --git a/doc/08_Preferences.md b/doc/08_Preferences.md
index a8b4c15d..ad089fb5 100644
--- a/doc/08_Preferences.md
+++ b/doc/08_Preferences.md
@@ -35,12 +35,14 @@ below.
Many of Textadept's generic modules have settings you can change from
*~/.textadept/init.lua* after the module is loaded. These settings are viewed
-from module's [LuaDoc][]. For example, to disable character autopairing and
-stripping whitespace on save, your *~/.textadept/init.lua* might look like:
+from module's [LuaDoc][]. For example, to disable character autopairing with
+typeover and stripping whitespace on save, your *~/.textadept/init.lua* might
+look like:
_M.textadept = require 'textadept'
_M.textadept.editing.AUTOPAIR = false
+ _M.textadept.editing.TYPEOVER_CHARS = false
_M.textadept.editing.STRIP_WHITESPACE_ON_SAVE = false
Now suppose you wanted to load all of Textadept's default modules except for the
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 ')', ']', '}', ''', and '"'.
+-- @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