From 7016ebfc57535694f0c5aac219f4a9a1054cf3e2 Mon Sep 17 00:00:00 2001 From: "Pedro A. Aranda" Date: Wed, 12 Feb 2025 08:14:15 +0100 Subject: [PATCH 1/4] Handle punctuation characters separately --- modules/textadept/editing.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index 611a9228..f38b401f 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -48,6 +48,11 @@ M.auto_indent = true -- The default value is `false`. M.auto_enclose = false +--- Whether or not to auto-enclose punctuation character, taking +-- `textadept.editing.auto_enclose` into account. +-- The default value is `false`. +M.auto_enclose_punctuation = false + --- Strip trailing whitespace before saving files. (Does not apply to binary files.) -- The default value is `false`. M.strip_trailing_spaces = false @@ -541,10 +546,12 @@ events.connect(events.CHAR_ADDED, function(code) end end) --- Enclose selected text in punctuation or auto-paired characters. +-- When `auto_enclose` is true, enclose selected text in auto-paired characters +-- or in punctuation if `auto_enclose_punctuation` is true. events.connect(events.KEYPRESS, function(key) - if not M.auto_enclose or buffer.selection_empty or not key:find('^%p$') then return end if ui.command_entry.active then return end + if not M.auto_enclose or buffer.selection_empty or not key:find('^%p$') then return end + if not M.auto_enclose_punctuation and key:find('^%p$') then return end M.enclose(key, M.auto_pairs[key] or key, true) return true -- prevent typing end, 1) From 8cfd74d10a476d9a9da1ff535b7aab0428c7a7e7 Mon Sep 17 00:00:00 2001 From: "Pedro A. Aranda" Date: Wed, 12 Feb 2025 10:57:56 +0100 Subject: [PATCH 2/4] More ellaborate selection --- modules/textadept/editing.lua | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index f38b401f..d9096421 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -48,10 +48,10 @@ M.auto_indent = true -- The default value is `false`. M.auto_enclose = false ---- Whether or not to auto-enclose punctuation character, taking +--- Whether or not to auto-enclose punctuation characters, taking -- `textadept.editing.auto_enclose` into account. --- The default value is `false`. -M.auto_enclose_punctuation = false +-- The default value is `true`. +M.auto_enclose_punctuation = true --- Strip trailing whitespace before saving files. (Does not apply to binary files.) -- The default value is `false`. @@ -546,12 +546,23 @@ events.connect(events.CHAR_ADDED, function(code) end end) --- When `auto_enclose` is true, enclose selected text in auto-paired characters +-- When `auto_enclose` is true, enclose selected text in auto-paired characters -- or in punctuation if `auto_enclose_punctuation` is true. events.connect(events.KEYPRESS, function(key) if ui.command_entry.active then return end - if not M.auto_enclose or buffer.selection_empty or not key:find('^%p$') then return end - if not M.auto_enclose_punctuation and key:find('^%p$') then return end + -- if we are not auto_enclosing or there is no region, skip + if not M.auto_enclose or buffer.selection_empty then return end + -- if the key is in auto_pairs, always consider it + if not M.auto_pairs[key] then + -- else if the is a punctuation key + if key:find('^%p$') then + -- if we are not enclosing punctuation, skip key + if not M.auto_enclose_punctuation then return end + else + -- if it is not a punctuation key, skip it + return + end + end M.enclose(key, M.auto_pairs[key] or key, true) return true -- prevent typing end, 1) From ea4b31a0730e640322817cf2b48f8094587411c6 Mon Sep 17 00:00:00 2001 From: "Pedro A. Aranda" Date: Fri, 14 Feb 2025 12:03:46 +0100 Subject: [PATCH 3/4] Auto document code --- modules/textadept/editing.lua | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index d9096421..c45895ee 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -554,14 +554,10 @@ events.connect(events.KEYPRESS, function(key) if not M.auto_enclose or buffer.selection_empty then return end -- if the key is in auto_pairs, always consider it if not M.auto_pairs[key] then - -- else if the is a punctuation key - if key:find('^%p$') then - -- if we are not enclosing punctuation, skip key - if not M.auto_enclose_punctuation then return end - else - -- if it is not a punctuation key, skip it - return - end + -- if the key is not a punctuation key, skip it + if not key:find('^%p$') then return end + -- if we do not want to autoenclose punctuation, skip it + if not M.auto_enclose_punctuation then return end end M.enclose(key, M.auto_pairs[key] or key, true) return true -- prevent typing From d8b3f89546a70ce65fd2b996e414f2d5c5265386 Mon Sep 17 00:00:00 2001 From: "Pedro A. Aranda" Date: Thu, 20 Feb 2025 10:17:41 +0100 Subject: [PATCH 4/4] Alternative w/o auto_enclose_punctuation --- modules/textadept/editing.lua | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index c45895ee..d972476f 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -48,11 +48,6 @@ M.auto_indent = true -- The default value is `false`. M.auto_enclose = false ---- Whether or not to auto-enclose punctuation characters, taking --- `textadept.editing.auto_enclose` into account. --- The default value is `true`. -M.auto_enclose_punctuation = true - --- Strip trailing whitespace before saving files. (Does not apply to binary files.) -- The default value is `false`. M.strip_trailing_spaces = false @@ -549,16 +544,14 @@ end) -- When `auto_enclose` is true, enclose selected text in auto-paired characters -- or in punctuation if `auto_enclose_punctuation` is true. events.connect(events.KEYPRESS, function(key) - if ui.command_entry.active then return end -- if we are not auto_enclosing or there is no region, skip - if not M.auto_enclose or buffer.selection_empty then return end - -- if the key is in auto_pairs, always consider it - if not M.auto_pairs[key] then - -- if the key is not a punctuation key, skip it - if not key:find('^%p$') then return end - -- if we do not want to autoenclose punctuation, skip it - if not M.auto_enclose_punctuation then return end - end + -- disable for the command entry dialog too + if not M.auto_enclose or buffer.selection_empty or ui.command_entry.active then return end + -- likely on a snippet, skip + if textadept.snippets.active then return end + -- Neither auto_pair nor punctuation + if not M.auto_pairs[key] and not key:find('^%p$') then return end + M.enclose(key, M.auto_pairs[key] or key, true) return true -- prevent typing end, 1)