Re: [code] [textadept] Entering special characters

From: Chris Emerson <c-ta.att.mail.nosreme.org>
Date: Tue, 14 May 2013 22:25:51 +0100

Hi Robert,

On Sun, May 12, 2013 at 08:26:41AM +0200, Robert wrote:
> Hi Chris,
>
> On Sun, May 12, 2013 at 1:24 AM, Chris Emerson <c-ta.att.mail.nosreme.org> wrote:
> > One useful feature in vim is being able to enter any character literally by
> > prefixing it with Ctrl-V.
>
> Not sure if this is what you mean, but maybe something like this:
> keys['cv'] = {
> ['\n'] = function() buffer.add_text('\\n') end,
> ['\t'] = function() buffer.add_text('\\t') end
> }

Ah, thanks - that seems to be a good solution for insert mode. With a
metatable that avoids too much repetition too (though I had to add a dummy
entry to the main table for it to be recognised).

> In the find dialog you can search for tabs and newlines if you enable
> 'Lua pattern', though a shortcut like above wouldn't work in the find
> field.

I like my regular expressions. :-)

> It might be possible to use the key modes (see for example in
> textadept/keys.lua at the end) to alter 'gui.find.find_entry_text' by
> adding literal newline or tab characters, I haven't tried though.

It seems to work, actually, at a first approximation. I added this to my
search mode:

    cv = {
        ['\t'] = function()
            local text = gui_ce.entry_text
            gui_ce.enter_mode(nil)
            gui_ce.entry_text = text .. "\t"
            gui_ce.enter_mode("vi_search_command")
        end,
    },

So I take a copy of the text and restart the mode with a tab appended. It
works for the common case of adding a special character at the end, though
it's a bit clunky.

I wonder if there could be a gui.command_entry.entry_pos which returned the
current cursor position. Or a better way of programatically altering the
contents while it's running, but I don't think that would be easy with the
current CDK widget.

> Btw, in your vi-mode you aren't using the key modes introduced in the
> latest beta, are you?

Yes, I am, including the command_entry one.

Chris

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Tue 14 May 2013 - 17:25:51 EDT

This archive was generated by hypermail 2.2.0 : Wed 15 May 2013 - 06:27:49 EDT