Re: how to enclose text

From: Robert <ro....at.web.de>
Date: Fri, 4 Jun 2010 16:16:48 +0200

Jay, I haven't tested your snippet, but it's probably like something
Brian posted a while ago:
(http://groups.google.com/group/textadept/msg/469a700ca917f9e6)

m_editing = _m.textadept.editing
keys['('] = {function() if buffer.get_sel_text() == '' then return
false else m_editing.enclose("parens") end end}

This should enclose a selection in parens otherwise paste ()

Robert

On Fri, Jun 4, 2010 at 3:28 PM, Jay <robert.jay.go....at.gmail.com> wrote:
> 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:
>> nice
>
> --
> You received this message because you are subscribed to the Google Groups "textadept" group.
> To post to this group, send email to textadept.at.googlegroups.com.
> To unsubscribe from this group, send email to textadept+unsubscribe.at.googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/textadept?hl=en.
>
>
Received on Fri 04 Jun 2010 - 10:16:48 EDT

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