From dc602bcbc7b88f81a971414ea2d04b81c3cf3029 Mon Sep 17 00:00:00 2001 From: Georgi Kirilov <> Date: Wed, 13 Mar 2024 18:43:15 +0800 Subject: [PATCH] migrate to 12.0 --- init.lua | 68 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/init.lua b/init.lua index 639fcc8..717c765 100644 --- a/init.lua +++ b/init.lua @@ -15,6 +15,9 @@ local keys = require"keys" local ui = ui local CURSES = CURSES +-- copied from core/keys.lua +local CTRL, ALT --[[, CMD]], SHIFT = 'ctrl+', not CURSES and 'alt+' or 'meta+' --[[, 'cmd+']], 'shift+' + -- XXX: in Lua 5.2 unpack() was moved into table local unpack = table.unpack or unpack @@ -31,7 +34,7 @@ setmetatable(M.lispwords, {__index = function(t, filetype) if supported[filetype] then local recfg = {__newindex = function(_, k, v) events.connect(events.FILE_OPENED, function() - if filetype == buffer:get_lexer() then + if filetype == buffer.lexer_language then env[buffer].fmt.lispwords[k] = v end end) @@ -504,32 +507,31 @@ function new.I(params) end end -local function gtk_mnemonics_off() +local function mnemonics_off() if CURSES then return end if not initialized then return end -- wait for the storm of events to pass - local filetype = buffer:get_lexer() + local filetype = buffer.lexer_language if not supported[filetype] then return end - local menus = textadept.menu.menubar - for _, menu in ipairs(menus) do - local mnemonic = menu.title:match"^_%a" - mnemonic = mnemonic and mnemonic:gsub("^_", ""):lower() - if mnemonic and keys[filetype] and keys[filetype]["alt+"..mnemonic] then - menu.title = menu.title:sub(2) + orig.menus = orig.menus or {} + for _, menu in ipairs(textadept.menu.menubar) do + local mnemonic = menu.title:match"&%a" + mnemonic = mnemonic and mnemonic:sub(2, 2):lower() + if mnemonic and keys[filetype] and keys[filetype][ALT..mnemonic] then + local new_title = menu.title:gsub("&", "", 1) + orig.menus[new_title] = menu.title + menu.title = new_title end end end -local function gtk_mnemonics_on() +local function mnemonics_on() if CURSES then return end if not initialized then return end -- wait for the storm of events to pass - local filetype = buffer:get_lexer() + local filetype = buffer.lexer_language if not supported[filetype] then return end - local menus = textadept.menu.menubar - for _, menu in ipairs(menus) do - local mnemonic = menu.title:match"^%a" - mnemonic = mnemonic and mnemonic:lower() - if mnemonic and keys[filetype] and keys[filetype]["alt+"..mnemonic] then - menu.title = "_" .. menu.title + for _, menu in ipairs(textadept.menu.menubar) do + if orig.menus[menu.title] then + menu.title = orig.menus[menu.title] end end end @@ -538,7 +540,7 @@ local extended_identifier_chars = "!$%&*+-./:<=>?@^_~" local function settings_backup() if not initialized then return end -- wait for the storm of events to pass - local filetype = buffer:get_lexer() + local filetype = buffer.lexer_language if not supported[filetype] then return end if not buffer.word_chars:find(extended_identifier_chars, 1, true) then buffer.word_chars = extended_identifier_chars .. buffer.word_chars @@ -546,26 +548,26 @@ local function settings_backup() orig.auto_indent = textadept.editing.auto_indent orig.strip_trailing_spaces = textadept.editing.strip_trailing_spaces orig.auto_pairs = textadept.editing.auto_pairs - orig.typeover_chars = textadept.editing.typeover_chars + orig.typeover_auto_paired = textadept.editing.typeover_auto_paired textadept.editing.auto_indent = false textadept.editing.strip_trailing_spaces = false textadept.editing.auto_pairs = nil - textadept.editing.typeover_chars = nil + textadept.editing.typeover_auto_paired = nil end local function settings_restore() if not initialized then return end -- wait for the storm of events to pass - local filetype = buffer:get_lexer() + local filetype = buffer.lexer_language if not supported[filetype] then return end textadept.editing.auto_indent = orig.auto_indent textadept.editing.strip_trailing_spaces = orig.strip_trailing_spaces textadept.editing.auto_pairs = orig.auto_pairs - textadept.editing.typeover_chars = orig.typeover_chars + textadept.editing.typeover_auto_paired = orig.typeover_auto_paired end -local function setup() gtk_mnemonics_off() settings_backup() end -local function teardown() gtk_mnemonics_on() settings_restore() end +local function setup() mnemonics_off() settings_backup() end +local function teardown() mnemonics_on() settings_restore() end events.connect(events.BUFFER_BEFORE_SWITCH, function() teardown() end) events.connect(events.BUFFER_AFTER_SWITCH, function() setup() end) @@ -612,7 +614,7 @@ events.connect(events.INITIALIZED, function() end) events.connect(events.FILE_OPENED, function() - local filetype = buffer:get_lexer() + local filetype = buffer.lexer_language if not supported[filetype] then return end local function write(pos, txt) buffer:set_target_range(pos + 1, pos + 1) @@ -656,7 +658,7 @@ events.connect(events.BUFFER_DELETED, function() end) events.connect(events.MODIFIED, function(pos, mtype) - local filetype = buffer:get_lexer() + local filetype = buffer.lexer_language if not supported[filetype] then return end local text_inserted, text_deleted = 0x01, 0x02 if 0 == (mtype & (text_inserted | text_deleted)) then return end @@ -665,21 +667,19 @@ events.connect(events.MODIFIED, function(pos, mtype) end end) -events.connect(events.KEYPRESS, function(ascii) +events.connect(events.KEYPRESS, function(key) if ui.command_entry.active then return end - local filetype = buffer:get_lexer() + local filetype = buffer.lexer_language if not supported[filetype] then return end - if (ascii ~= 13) and ascii < 32 or ascii > 255 and (ascii ~= 65293) then return end - if (ascii == 65293 or ascii == 13) then ascii = 10 end - local char = string.char(ascii) + if key:find(CTRL) or key:find(ALT) or key:find(SHIFT) then return end local ret local winput = env[buffer].input - local consumed_char = char:find(env[buffer].consumed_char) + local consumed_char = key:find(env[buffer].consumed_char) if consumed_char then buffer:begin_undo_action() end for i = buffer.selections, 1, -1 do local anchor, caret = buffer.selection_n_anchor[i] - 1, buffer.selection_n_caret[i] - 1 local range = {start = math.min(anchor, caret), finish = math.max(anchor, caret)} - if char == "\n" then + if key == "\n" then local sexp, parent = env[buffer].walker.sexp_at(range, true) if parent.is_root and (not sexp or (not sexp.is_comment and sexp.finish + 1 == range.start)) then local same_line = not not sexp @@ -698,7 +698,7 @@ events.connect(events.KEYPRESS, function(ascii) end end end - ret = winput.insert(range, seek(i), char, M.auto_square_brackets) + ret = winput.insert(range, seek(i), key, M.auto_square_brackets) end if consumed_char then buffer:end_undo_action() end return ret -- 2.11.4.GIT