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

From: Mitchell <m.att.foicica.com>
Date: Thu, 11 Oct 2018 08:54:51 -0400 (EDT)

Hi Ardi,

On Thu, 11 Oct 2018, ardi wrote:

> Hi,
>
> I've been a long time NEdit user, and one of the features I used the
> most was to jump to the beginning of either the next or the previous
> C/C++ function in the current buffer (I used to assign the F4 key for
> jumping to the next function, and the F3 key for the previous one...
> as well as the F2 key for jumping to the function whose name is the
> current selection). Note that I'm not talking about ctags files, NEdit
> was able to locate the beginning of a function just from regular
> expressions rules, without the need of ctags files.
>
> I tend to believe that this functionality will already exist in
> Textadept, or that otherwise other users will have written the proper
> macros/commands for getting that functionality. Does it already exist?
> Where?

I would imagine the wiki[1] would be the place to look if it exists, but I don't see anything of the sort after a brief look. It shouldn't be too difficult to write something that would do what you need since Textadept has good Regexp support now. Take a look in Textadept's *modules/textadept/find.lua* for the `find` function (around line 114). The gist what you'd want to do is:

   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. Documentation for those functions is at https://foicica.com/textadept/api.html.

When you've written a function, you can bind it to the F3 or F4 key like so:

   keys.f3 = function() ... end
   keys.f4 = function() ... end

(You can replace `function() ... end` with a named function too, of course.)

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 Thu 11 Oct 2018 - 08:54:51 EDT

This archive was generated by hypermail 2.2.0 : Fri 12 Oct 2018 - 06:40:39 EDT