ctags/etags/... for editing AutoHotKey
Posted: 23 Jun 2022, 12:37
Q: is anyone using some variant of classic editor tags support when editing AutoHotKey? I.e. what are the BKMs for such tags?
Note: by "editor tags support" I mean not #tags or tagging as in this forum/board, or version control tags as in git, but tags that a program editor can use in order to take you quickly to the code, function or variable or class definitions, that you care about?
There are many tag database building tools like ctags https://man7.org/linux/man-pages/man1/ctags.1p.html, https://docs.ctags.io/en/latest/man/ctags.1.html], etags https://linux.die.net/man/1/etags.
Many programming editors, like vim and emacs support various tag formats. indeed the etags tag format and program are specifically "tags for emacs", more capable than the original C programming related tags, although both the ctags and etags tools can be configured for many different programming languages. https://linux.die.net/man/1/etags
I am mainly looking for recommendations for a particular tool and particular configuration options that work well with AutoHotKey.
---
I am currently using etags as follows:
is reasonably obvious, see the man pages
I should probably be using since I use suffix.ahk-lib to indicate an AHK library that cannot be invoked as a standalone script or program to force my ahk-mode
to recognize function names that begin in column zero and start a parameter list. this is suboptimal, because in AutoHotKey you can also have ordinary executable code starting in column zero, with function calls being matched by this regular expression. for that matter, it can match if statements as well.
matches indented function names like
because not all functions, and particularly methods in classes, start in column 0.
However, I often do not put the { on the same line as the function name or argument list, especially if there are lots of arguments.
Hence
Unfortunately all of these regular expressions can be confused by things like
the etags format is a little bit more complicated and harder to filter. But the extra features of etags are desirable.
Besides, filtering if statements out is fairly easy, but distinguishing function definitions from function calls is a bit harder. Essentially you have to look past the closing parenthesis of the argument list to see if there is { beginning a function body. AFAIK none of the ctags/etags programs support regular expressions that can cross line boundaries in this way. Perhaps somebody has already written one?
(BTW, one of my most annoying habits is to have AHK function call followed by a { quite a few blank lines later, sometimes across a #include file boundary. I like using {braces} group code blocks, often indenting them.)
Note: by "editor tags support" I mean not #tags or tagging as in this forum/board, or version control tags as in git, but tags that a program editor can use in order to take you quickly to the code, function or variable or class definitions, that you care about?
There are many tag database building tools like ctags https://man7.org/linux/man-pages/man1/ctags.1p.html, https://docs.ctags.io/en/latest/man/ctags.1.html], etags https://linux.die.net/man/1/etags.
Many programming editors, like vim and emacs support various tag formats. indeed the etags tag format and program are specifically "tags for emacs", more capable than the original C programming related tags, although both the ctags and etags tools can be configured for many different programming languages. https://linux.die.net/man/1/etags
I am mainly looking for recommendations for a particular tool and particular configuration options that work well with AutoHotKey.
---
I am currently using etags as follows:
Code: Select all
etags --append \
--langdef=ahk --language-force=ahk \
--regex-ahk='/^([a-zA-Z0-9_]+)\(/\1/' \
--regex-ahk='/^[[:blank:]]*([a-zA-Z0-9_]+)\(.*\)[[:blank:]]*$$/\1/' \
--regex-ahk='/^[[:blank:]]*([a-zA-Z0-9_]+)\(.*\)[[:blank:]]*{/\1/' \
--regex-ahk='/^class[[:blank:]]+([a-zA-Z0-9_]+)/\1/'
Code: Select all
--langdef=ahk
I should probably be using
Code: Select all
--langmap=.ahk.ahk-lib
Code: Select all
--language-force=ahk
Code: Select all
--regex-ahk='/^([a-zA-Z0-9_]+)\(/\1/'
Code: Select all
--regex-ahk='/^[[:blank:]]*([a-zA-Z0-9_]+)\(.*\)[[:blank:]]*{/\1/'
Code: Select all
name(args){
...
}
However, I often do not put the { on the same line as the function name or argument list, especially if there are lots of arguments.
Hence
Code: Select all
--regex-ahk='/^[[:blank:]]*([a-zA-Z0-9_]+)\(.*\)[[:blank:]]*$/\1/' \
and even
[code]--regex-ahk='/^[[:blank:]]*([a-zA-Z0-9_]+)\(.*/\1/'
- function calls that begin in column 0
- if(...) { ... statements,
- etc.
the etags format is a little bit more complicated and harder to filter. But the extra features of etags are desirable.
Besides, filtering if statements out is fairly easy, but distinguishing function definitions from function calls is a bit harder. Essentially you have to look past the closing parenthesis of the argument list to see if there is { beginning a function body. AFAIK none of the ctags/etags programs support regular expressions that can cross line boundaries in this way. Perhaps somebody has already written one?
(BTW, one of my most annoying habits is to have AHK function call followed by a { quite a few blank lines later, sometimes across a #include file boundary. I like using {braces} group code blocks, often indenting them.)