 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
urlwolf
Joined: 16 Mar 2006 Posts: 100
|
Posted: Wed Jan 02, 2008 9:37 pm Post subject: Ahk support in ctags. Teleport around in your code (done) |
|
|
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 limitations
Ctags 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.
Install and run
The 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:
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.
Last edited by urlwolf on Tue Feb 12, 2008 2:39 am; edited 8 times in total |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6349 Location: Pacific Northwest, US
|
Posted: Wed Jan 02, 2008 10:53 pm Post subject: |
|
|
| Quote: |
As a consequence, the regular expressions I have here will work with One true brace (OTB) style code.
|
Perhaps you should add the word "Only"
Otherwise pretty cool looking. I don't want to use vim or emacs, though. _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
urlwolf
Joined: 16 Mar 2006 Posts: 100
|
Posted: Wed Jan 02, 2008 11:50 pm Post subject: |
|
|
Thanks engunneer. Fixed that.
You don't have to use vim or emacs. You can use:
Jedit, slickEdit, multiEdit2006, Notepad++,Crimson Editor, EditPlus or UltraEdit:
http://openctags.sourceforge.net/
... and who knows which other editors.
Details here:
http://www.autohotkey.com/forum/viewtopic.php?t=27134&highlight=ctags.
The actionscript post linked there explains how to configure Jedit. the openctags link does the same for all the other editors.
Bummer about PSPad, as it seems to be a favorite here. |
|
| Back to top |
|
 |
Mustang
Joined: 17 May 2007 Posts: 368 Location: England
|
Posted: Thu Jan 03, 2008 12:04 am Post subject: |
|
|
| Im still using trusty old Notepad atm |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6349 Location: Pacific Northwest, US
|
Posted: Thu Jan 03, 2008 1:57 am Post subject: |
|
|
I used to use UltraEdit, until I decided that I didn't want to "borrow" software anymore (And I couldn't afford it back then). I will have to see if ctags works with PSPad, or I could just buy UE, but I would need 4 copies minimum  _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
urlwolf
Joined: 16 Mar 2006 Posts: 100
|
Posted: Thu Jan 03, 2008 2:12 am Post subject: |
|
|
UPDATE:
function regex now matches functions with default vaules in arguments. Example
| Code: | ISENSE_Init( lastGUI=0, subMenu="", bStandalone=true ){
|
variable regex changed to match only := (it gets lots of variables this way, and skips the false alarms in ifs.
Also, testing #includes, I realize that you just have to call ctags with the -R flag. It works.
Now I only have to figure out how to tweak taglist.vim (1000s of lines of code!) to make all calls recursive.
Slow but steady progress.
A future compiled version will remove the pain of having to use a .cnf file.
Teleporting gives a whole new way of looking at code.
I'm stopping now for a rest and then do some actual work
I'm looking forward to ctags working with some other editor (just to see how easy it is; I love vim so I won't move). Also, if you are agnostic -i.e. don't hate vim, just the modal interface-, try to use cream too. |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1091 Location: USA
|
Posted: Thu Jan 03, 2008 2:19 am Post subject: |
|
|
| engunneer wrote: | I used to use UltraEdit, until I decided that I didn't want to "borrow" software anymore (And I couldn't afford it back then). I will have to see if ctags works with PSPad, or I could just buy UE, but I would need 4 copies minimum  |
You should check out SciTE. If this supports Notepad++ (which I think is Scintilla based) it should work with SciTE, too. _________________
 |
|
| Back to top |
|
 |
urlwolf
Joined: 16 Mar 2006 Posts: 100
|
Posted: Thu Jan 03, 2008 2:25 am Post subject: |
|
|
I think notepad++ offers support through a plugin.
Not sure if SciTE has the same plugin.
What makes you take SciTE over notepad++? |
|
| Back to top |
|
 |
urlwolf
Joined: 16 Mar 2006 Posts: 100
|
Posted: Thu Jan 03, 2008 2:36 am Post subject: |
|
|
Something cool I just found.
In vim, if you press gd (go to definition) in any occurrence of a function in your code, it will highlight where it is in the function list.
It works for variables too. do gd, and it takes you to where the variable was first initialized. How cool is that? Once you know what you wanted to know, you can get back to where you were by pressing ctrl + o (old position). |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1091 Location: USA
|
Posted: Thu Jan 03, 2008 3:48 am Post subject: |
|
|
| urlwolf wrote: | I think notepad++ offers support through a plugin.
Not sure if SciTE has the same plugin.
What makes you take SciTE over notepad++? |
I have both, but prefer SciTE.
I do not normally need all of the fluff that notpad++ has. _________________
 |
|
| Back to top |
|
 |
urlwolf
Joined: 16 Mar 2006 Posts: 100
|
Posted: Thu Jan 03, 2008 7:34 pm Post subject: |
|
|
Update.
First, I have found a solution for the config file having to be in the same dir as the script.
This is no longer needed.
I got an answer from Darren, the author of ctags:
| 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
|
So I just made sure that I drop my config file in the $HOME folder (if you don't have a HOME variable when looking at the environment variables as described in the original post, add it). This way ctags supports ahk anywhere in the filesystem.
I have updated the original post.
The regular expression for functions is improved too. Before it Skipped some functions. Now, there's the danger of detecting IFs as functions ( false alarms). I have been struggling for a while to exclude strings that start with IF, but negation is not easy with one single regular expression.
A last resort is to change the code for taglist and make it exclude the IFs.
So, right now, beware that you'll find lots of IFs in the function list.
I only wish Autohotkey were easier to parse. Having something to mark function definitions would save all this trouble.
People who have done syntax highlighting for ahk might have faced the same problems. |
|
| Back to top |
|
 |
urlwolf
Joined: 16 Mar 2006 Posts: 100
|
Posted: Fri Jan 04, 2008 3:35 am Post subject: |
|
|
UPDATE:
problem with false alarms and IFs solved.
added support for TODOs (it will list them on the side bar).
The only problem that remains is OTB support only. |
|
| Back to top |
|
 |
Guest
|
Posted: Sat Jan 05, 2008 2:19 am Post subject: |
|
|
| urlwolf wrote: | | The only problem that remains is OTB support only. |
...OTB-only support is not a "problem"...everyone should use OTB (also no one should use vim, but that's a-whole-nother issue...I can't even explain the pains I went thru trying to edit text via SSH on a Linux box {with vi or vim}, until I found out about pico...pico = normal, vim = headache {you can't even Exit if you accidentally run vi/vim}...don't get me wrong, I'm open to someone explaining to me exactly how to use vim {& why?} {no don't tell me to read the man page, it hasn't helped yet} but I don't understand "learning how to use vim" when using a normal editor/pico (Linux)/Notepad2 (Windows) is already intuitive)...but your OTB example should be...
...not...
...it needs a space there...also (I didn't check) but if putting a space there breaks your regex, then that does need fixed...
Also...do I even need to mention not posting big-ass screenshots (horiz scrolling!)?...can't people make a small version & link to the big?... |
|
| Back to top |
|
 |
urlwolf
Joined: 16 Mar 2006 Posts: 100
|
Posted: Sat Jan 05, 2008 3:22 am Post subject: |
|
|
the regex works with any amount of space anywhere.
I'm not sure OTB is the norm for ahk code. I have seen all kind of indentation. For example Auto-Syntax-Tidy 'corrects' indentation for ahk. It offers 3 types of indentation, none of them is OTB.
The limitation of ctags is that the regex is applied line by line. Then when the curly brace is in a different line, it doesn't match. One could compile ctags with a different regex engine, but that's too much trouble. I write OTB code anyway, and it's easier to fix the one I download from here.
As I said before you can use ctags with a plethora of editors, the ones you call 'normal'. I invested a week of my life learning vim and it's probably one of the most profitable time investments I've done. It's true that you need to learn 'vim-fu', and it's easier if there's someone around that already use it.
Saying things like "everyone should use OTB" also "no one should use vim" is not going to convince anyone either way. |
|
| Back to top |
|
 |
canta
Joined: 30 May 2006 Posts: 49
|
Posted: Mon Feb 11, 2008 9:46 pm Post subject: |
|
|
urlwolf: I get the list up with TlistToggle on any other file than ahk. I get this message on ahk files: | Code: |
"E:\MyAhkFile.ahk" 0L, 0C
Taglist: Failed to generate tags for E:\MyAhkFile.ahk
Press ENTER or type command to continue
^@E:\>E:\programfiler\ctags57\ctags.exe -f - --format=2 --excmd=pattern --fields=nks --sort=no --language-force=a
utohotkey --autohotkey-types=lfvnth "E:\MyAhkFile.ahk" ^@ctags.exe: Unknown language "autohotkey" in "language-fo
rce" option^@ |
Do you know if there is something i have missed when installing? |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|