Re: [code] [textadept] Macros/add-ons for quick C/C++ function traversal?

From: Mitchell <>
Date: Sat, 13 Oct 2018 16:14:37 -0400 (EDT)

Hi ardi,

On Sat, 13 Oct 2018, ardi wrote:

> On Thu, Oct 11, 2018 at 2:55 PM Mitchell <> wrote:
> [...]
>> buffer:search_anchor()
>> local pos = buffer:search_next(buffer.FIND_REGEXP, regex)
>> if pos ~= -1 then
>> buffer:goto_pos(pos)
>> else
>> -- try another regex
>> end
>> where `regex` is your regex to match a function block. I'm pretty sure multi-line regex searches do not work,
>> but you'd have to double-check. You can also use a loop to iterate over a table of regexes to try.
> I tried to start by implementing a simple function that searches the
> '^{' regex backwards. I put it inside a "init.lua" file in
> "~/.textadept/modules/common" while performing a require("common") in
> my ~/.textadept/init.lua but however I'm making TA crash.
> The code in "~/.textadept/modules/common/init.lua" is as follows. Any
> idea on why it's making TA crash?
> local function PrevCFunction()
> buffer:search_anchor()
> local pos = buffer:search_prev(buffer.FIND_REGEXP, '^{')
> if pos ~= -1 then
> buffer:goto_pos(pos)
> end
> end
> keys.f3 = PrevCFunction
> If the regex is '^[a-zA-Z]' then it doesn't crash...
> I'm guessing I'm doing something in an obviously wrong way, perhaps
> I'm trying to do things quicker than I should.

When I open up the command entry and type `buffer:search_prev(buffer.REGEXP, '^{')`, I'm not seeing a crash. Are you on Linux? If so, and if you have gdb installed, you can fetch a nightly build, run `gdb textadept` from a terminal in the Textadept directory, type the `r` command and hit enter, trigger the crash, and then type `bt` followed by enter for a stacktrace. Post the stacktrace here.

It's also possible that you have to escape the brace in your regex: '^\\{' (remember '\\' is needed for one '\' in Lua strings).


You are subscribed to
To change subscription settings, send an e-mail to
To unsubscribe, send an e-mail to
Received on Sat 13 Oct 2018 - 16:14:37 EDT

This archive was generated by hypermail 2.2.0 : Sun 14 Oct 2018 - 06:31:36 EDT