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

From: ardi <ardillasdelmonte.att.gmail.com>
Date: Thu, 11 Oct 2018 15:25:38 +0200

Thanks a lot, Gabriel and Mitchell!

I located the code snippet within the NEdit start-up file, that adds
these macros. And yes, it's a regexp.

I'll look at the documentation and the advice you gave me, and I'll
try to port it to Textadept.

For reference, and since these regexps are not obvious, this is the
code that adds the feature to NEdit (first block adds "go to function"
to F2, second block adds "go to previous function" to F3, and last
block "go to next function" to F4) :

Go to Function.att.C@C++:F2::R: {\n\
c=search( "\\n[^\\(\\)]*[ :*\\t\\n]" get_selection() "[
\\t]*[\\(][^;]+[ \\t]*\\n?[ \\t]*\\\\{" ,1,"regex")\n\
if (c != -1)\n\
  {\n\
c=search(get_selection(),c)\n\
set_cursor_pos( c )\n\
}\n\
else\n\
  beep()\n\
}\n\
Go to Previous Function.att.C@C++:F3::: {\n\
c = search("^[a-zA-Z]([^;#\\"'{}=><!/]|\\n)*\\\\)[ \\t]*\\n?[
\\t]*\\\\{", $cursor-1, "regex", "backward")\n\
if (c != -1)\n\
 set_cursor_pos( c )\n\
else\n\
 beep()\n\
}\n\
Go to Next Function.att.C@C++:F4::: {\n\
start = search("^",$cursor+1,"regex")\n\
if(start==-1)\n\
{\n\
beep()\n\
return\n\
}\n\
c = search("^[a-zA-Z]([^;#\\"'{}=><!/]|\\n)*\\\\)[ \\t]*\\n?[
\\t]*\\\\{", start, "regex")\n\
if (c != -1)\n\
 set_cursor_pos( c )\n\
else\n\
 beep()\n\
}\n\

On Thu, Oct 11, 2018 at 2:56 PM Mitchell <m.att.foicica.com> wrote:
>
> And I forgot that the wiki[1] is at:
>
> [1]: https://foicica.com/wiki/textadept
>
> Sorry about that.
>
> Mitchell
>
> On Thu, 11 Oct 2018, Mitchell wrote:
>
> > 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
> >
>
> 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.
>

-- 
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 - 09:25:38 EDT

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