Re: how to enclose text

From: Jay <robert.jay.go....at.gmail.com>
Date: Fri, 4 Jun 2010 06:28:43 -0700 (PDT)

I use another enclosing solution, which is nice IMHO, but requires
changing a core script (still haven't been able to figure out how to
put it into a module)

script: core/ext/keys.lua line:87+

local char_matches = {
  [40] = ')', [91] = ']', [123] = '}',
  [34] = '"', [60]='>', [39] = "'",
}

-- Handles Textadept keypresses.
-- It is called every time a key is pressed, and based on lexer and
scope,
-- executes a command. The command is looked up in the global 'keys'
key
-- command table.
-- @return whatever the executed command returns, true by default. A
true
-- return value will tell Textadept not to handle the key
afterwords.
local function keypress(code, shift, control, alt)
  local control,alt = alt,control
  local buffer = buffer
  local key
  --print(code, string.char(code))
  if char_matches[code] then --> NEW CODE STARTS HERE
        local selection = buffer:get_sel_text()
        if #selection>0 and code~=60 then
                buffer:replace_sel(string_char(code)..selection..char_matches[code])
                return true
        elseif #selection>0 and code==60 then
                --TAG
        
buffer:replace_sel(string_char(code)..selection..char_matches[code]..string_char(code)..'/'..selection..char_matches[code])
                return true
        end
  end -- ENDS HERE
  if code < 256 then

My enclose functionality simply encloses the selected text with the
correct enclosure symbol, no key chains. I think this is how Smultron
a free Mac editor did it, and it stuck with me, so I implemented it in
Textadept too.

Any ideas on how to push this further down the customization stack
instead of being up here in the core would be great too :)

-Jay

On Jun 2, 1:51 am, morchel <morc....at.hotmail.com> wrote:
Received on Fri 04 Jun 2010 - 09:28:43 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:46:40 EST