Re: [code] Re: [textadept] Keyboard macro's

From: Mitchell <m.att.foicica.com>
Date: Mon, 9 Feb 2015 12:11:20 -0500 (EST)

Hi Richard,

On Thu, 5 Feb 2015, Richard Philips wrote:

> Hello Mitchell,
>
> thank you for your elaborate answer.
>
> I understand that implementing (traditional) keyboard macro's are not the
> way to go.
>
>
> But perhaps we can do something else.
>
> I have now a macro-like feature based on awk:
>
> - I ask for an AWK one-liner
> - I filter the region through awk and replace the region with the output of
> the program.
>
> All works flawlessly thanks to built-in Textadept features (especially the
> undo :-)
>
> This system has some drawbacks:
>
> - it is accomplished by using the shell
> - AWK is not for everyone
> - one-liners are sometimes not sufficient
> - it is not possible to use functions which reside in the module system of
> Textadept.
>
> If we (you :-) could come up with a system with:

Textadept's Lua command entry with its "abbreviated environment" might be
sufficient. It was designed for something like this too. See below.

> - easy entry of a Lua function in textadept itself, without an installation
> step

Open the command entry and put "function name()", followed by your
function, and then "end".

> - which can use some prebuilt functions and variables which can be used in
> the Lua code
> (e.g. Line contains the current line, Lineno is the linenumber, Tokens is
> a list with the tokens found on the current line , ...)

* `current_pos` is the current position
* `line_from_position(current_pos)` is current line[1]
* `get_cur_line()` gives you the currene line as a string[1]
* Any other buffer function or field can be used by name instead of with
the `buffer:` or `buffer.` prefix.

[1]: I found a bug in these just now that will be fixed soon. However,
these will work eventually.

> - a way to name the function

As mentioned earlier, "function name() ..."

> - a standard way to execute this function

In the command entry, type "name()" and press enter :)

> - a way to save this function

That's the tricky bit. I think you can use Lua's `string.dump(f)` to dump
function `f` in a string format that can be `load()`ed again. I haven't
tried it though. If that doesn't work, then you can always save the text
of the function you typed in the command entry somewhere and paste it back
in at a later date... a bit primitive I admit, but I've done this before.

Cheers,
Mitchell

-- 
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 Mon 09 Feb 2015 - 12:11:20 EST

This archive was generated by hypermail 2.2.0 : Tue 10 Feb 2015 - 06:46:05 EST