aboutsummaryrefslogtreecommitdiff
path: root/modules/textadept/keys.lua
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2015-03-11 16:53:07 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2015-03-11 16:53:07 -0400
commit85450b9983ec16b27981572c258298e6fbf2f59d (patch)
tree3a9557314cad78bde44d9d2030110339b73669f4 /modules/textadept/keys.lua
parent920c230f140c38ec072da27e522053aed2a9af75 (diff)
downloadtextadept-85450b9983ec16b27981572c258298e6fbf2f59d.tar.gz
textadept-85450b9983ec16b27981572c258298e6fbf2f59d.zip
Updated to Lua 5.3, LPeg 0.12.2, and lfs 1.6.3.
LuaJIT uses Lua 5.3's new utf8 library. Restored documentation for Lua 5.1 symbols and added deprecation notes.
Diffstat (limited to 'modules/textadept/keys.lua')
-rw-r--r--modules/textadept/keys.lua30
1 files changed, 2 insertions, 28 deletions
diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua
index ca515d9a..09f9bab8 100644
--- a/modules/textadept/keys.lua
+++ b/modules/textadept/keys.lua
@@ -219,14 +219,6 @@ local M = {}
-- ‡: Ctrl+Enter in Win32 curses.
module('textadept.keys')]]
--- UTF-8 handling tables.
-local utf8_lengths = { -- {max code point, UTF-8 length}
- {0x80, 1}, {0x800, 2}, {0x10000, 3}, {0x200000, 4}, {0x4000000, 5}
-}
-local lead_bytes = { -- [UTF-8 length] = {UTF-8 lead bits, remaining mask}
- {0, 0x7F}, {0xC0, 0x1F}, {0xE0, 0x0F}, {0xF0, 0x7}, {0xF8, 0x3}, {0xFC, 0x1}
-}
-
-- Utility functions.
M.utils = {
delete_word = function()
@@ -253,11 +245,7 @@ M.utils = {
show_style = function()
local pos = buffer.current_pos
local char = buffer:text_range(pos, buffer:position_after(pos))
- if char == '' then char = '\0' end
- local code = bit32.band(char:byte(), lead_bytes[#char][2])
- for i = 2, #char do
- code = bit32.bor(bit32.lshift(code, 6), bit32.band(char:byte(i), 0x3F))
- end
+ local code = utf8.codepoint(char)
local bytes = string.rep(' 0x%X', #char):format(char:byte(1, #char))
local style = buffer.style_at[pos]
local text = string.format("'%s' (U+%04X:%s)\n%s %s\n%s %s (%d)", char,
@@ -660,21 +648,7 @@ end
if OSX or CURSES then
-- UTF-8 input.
keys.utf8_input = {['\n'] = {ui.command_entry.finish_mode, function(code)
- local c = tonumber(code, 16)
- -- Determine the number of bytes in UTF-8 character to insert.
- local buf, len = {}, 6
- for i = 1, #utf8_lengths do
- if c < utf8_lengths[i][1] then len = utf8_lengths[i][2] break end
- end
- -- Produce UTF-8 bytes.
- for i = len, 2, -1 do
- buf[i], c = bit32.bor(0x80, bit32.band(c, 0x3F)), bit32.rshift(c, 6)
- end
- -- Construct the lead UTF-8 byte.
- buf[1] = bit32.bor(lead_bytes[len][1], bit32.band(c, lead_bytes[len][2]))
- -- Transform bytes into strings and perform the insertion.
- for i = 1, #buf do buf[i] = string.char(buf[i]) end
- _G.buffer:add_text(table.concat(buf))
+ _G.buffer:add_text(utf8.char(tonumber(code, 16)))
end}}
keys[OSX and 'mU' or 'mu'] = {ui.command_entry.enter_mode, 'utf8_input'}
end