I finally got done testing the regular expressions to have autohotkey support in ctags. (see the post that started it
here).
There are some things that you get with a ctags-based function list that you don't get in other editors with function lists, described in 'features'.
Features
- you can have multiple function lists from multiple files opened simultaneously.
- Hoover over a function to see a popup with its definition.
- The editor can list Variables , not only labels and functions.
- When you add a function in your code, it automatically gets added to the function list. Same with variables
- Vim highlights the function where the cursor is; good for navigating large files without the need of folding (btw, vim supports folding too).
- Teleporting to a function definition that is in a different file (#includes) is possible.
Known bugs and limitationsCtags uses posix regex. To my knowledge, there's no way of doing multiline matchings (but I'm not a regex wizard, I may be wrong). As a consequence,
the regular expressions I have here will work with One true brace (OTB) style code ONLY.
This means that in the following code, the first function will be matched, but not the second. It's pretty easy to fix your code so all your functions are OTB-style though.
Code:
foo(){
}
faa()
{
}
Install and runThe list is Editor-independent. Let's create a tags file to use. We will use the command line, but this is just for you to see the process. Normally your editor will do all this for you.
- First, you need to Download exhuberant ctags and uncompress the binaries to a folder. You will have ctags.exe and maybe tags.cnf.
- Add the directory where ctags lives to the path. Go to my computer > properties > advanced > environment variables > all users > double click "PATH" and add ;/path/to/where/ctags/is/. Click Ok.
- create a file ctags.cnf and paste the following in it:
Code:
--langdef=autohotkey
--langmap=autohotkey:.ahk
--regex-autohotkey=/^[ \t]*([a-zA-Z0-9_]+)\:\s*$/\1/l,label/
--regex-autohotkey=/^[ \t]*([a-zA-Z0-9_]+)[ |\t]*:?=/\1/v,variable/
--regex-autohotkey=/^[ \t]*(NOTE|note|Note)[ \t]*\:[ \t]*(.*)/\2/n,note/
--regex-autohotkey=/^[ \t]*(TODO|todo|Todo)[ \t]*\:[ \t]*(.*)/\2/t,todo/
--regex-autohotkey=/^([a-zA-Z0-9_@]+)[ \t]*\(.*\)[ \t]*{/\1/f,function/
Quote:
The locations checked for a ctags.cnf file are as follows:
/ctags.cnf (i.e. on current drive)
$HOME/ctags.cnf
$HOMEDRIVE$HOMEPATH/ctags.cnf
./ctags.cnf
Made sure that you drop your config file in the $HOME folder (if you don't have a HOME variable when looking at the environment variables, add it). This way ctags supports ahk anywhere in the filesystem.
edit: it seems that bbcode gets confused/doesn't allow brakets inside the code sections? formatting looks good when using preview with bbCodeEditor, but not when I submit it to the forum. Sorry about the large fonts.
- To make sure ctags works even before opening an editor, open a command line and type ctags yourAhkScript.ahk. This will prodice a 'tags' file in the same directory the script is. Look at the 'tags' file. You should have a list of your functions, together with a regular expression that tells the program how to find it in the code.
If you don't want to touch a command line, just fire your editor and make it show the function list. In vim, you just open the file ahd type :TlistToggle.
That's all you need. Your editor will take it from there.
I'll assume that you got your ctags working. I use vim for this example. If you get your editor to work, please post what you did here.
Here are the steps for working with Vim and Ctags to get results similar to the above screenshot.
- install vim. You can also use [url=cream.sourceforge.ne]cream[/url] if you don't want to learn the modal way (esc goes to normal mode, where what you type does not insert stuff; some people are scared by it.). Cream is a wrapper for vim that makes it work like a 'normal' editor. It takes plugins etc exactly like vim. I've never used it though, as once you learn to use vim you feel like you have superpowers moving around in text and you never look back.
- Do all the steps in the previous list. Make sure there's a tags file in the folder where your script is.
- Install taglist.vim. Follow instructions in that webste.
- Edit /vimfiles/plugins/taglist.vim, and add autohotkey support by pasting this:
Code:
" autohotkey language
let s:tlist_def_autohotkey_settings = 'autohotkey;l:label;f:function;v:variable;n:note;t:todo;h:hotkey'
Save and close. - Open your ahk file with vim. Pres esc to enter normal mode. Type colon. You will be in the command line. Type:
Code:
TlistToggle
You should see the function list.
I'll keep working on the regular expressions. If anyone knows how to make it work with non-OTB functions, let me know.
Also, I want to know why ctags doesn't follow the links in the #includes.
Happy testing.