Using TextMate (Mac OS X) as your IDEMonkey Programming Forums/Monkey Programming/Using TextMate (Mac OS X) as your IDE
| I've created a configuration bundle that will allow you to use the Mac OS X editor TextMate as an IDE for monkey. The bundle is based in part on the existing BlitzMax bundle so thanks to Nilium over at blitzbasic.com for that!|
Download: http://www.gingerbeardman.com/monkey/monkey.tmbundle.zip (will redirect to github)
It has the following features:
Auto Completion of Keywords
- press the Escape key to cycle through all matches after typing part of a keyword
Expand Keywords into Code
- press the tab key to expand one keyword into one or more lines of code,
subsequent presses of tab intelligently jump you through the resulting code
allowing you to fill in multiple parameters with minimal key strokes
- specify target, config and run options in the source - no need for the command line!
Quick and easy full build by pressing ⌘B, or a quicker update and run using ⌘R
Context Sensitive Help
- view the monkey module docs in a popup window
Quick Start Template
- one click skeleton template to get you started, build to see instant results!
Syntax Colouring/Highlighting, Code Folding, Configurable Shortcut Keys
- and more!
To use unzip and double click, or manually move the bundle to to: /Users/you/Library/Application Support/TextMate/Bundles/monkey.tmbundle
You'll need to set the TM_MONKEY environment variable in TextMate Preferences/Advanced/Shell Variables to the path of your monkey installation, eg. /Developer/Applications/monkey (no trailing slash). There is more about this in bundle help after installation.
Let me know if you have any suggestions.
ps: those Mac users who do not use TextMate may wish to check out some screencasts: http://macromates.com/screencasts
| Thanks for sharing. |
| This has just been updated, now featuring an even more complete set of code completion/expansion and also all input constants. |
| This is now on github|
| Just added a few things to this, the only download from now on will be github. |
| Can you now make one for Eclipse please :) |
| Sorry I don't use Eclipse, but feel free to send me some links to reference material showing how it can be extended. |
| Small update to this to cater for the latest release of monkey|
| I found this a while back but the looks like a textmate compatible text editor for windows! |
Don't no if it will work with this bundle not had chance to try yet.
| Yes, it will work in E|
(sorry I can't change the topic title to cater for both)
| First of all, thanks for sharing! :)|
Secondly, a few quirks:
1) "Class" definition/parsing confusing syntax highlighting.
2) "Function" keyword not being highlighted/ confusing syntax highlighting.
3) "Global" keyword not being highlighted.
| Thanks for the feedback.|
Those three items highlight correctly in the Template that comes with the bundle, but I'm happy to look into it.
Is your code valid and can be built and run?
Can you post (or email) some sample code that exhibits these issues?
This code highlights correctly:
| . |
| Yep, code is valid, builds and runs .. :)|
Here's a screen cap showing wrong highlighting:
Here's a screen cap showing better highlighting (NOTE: comment added on "Class" line):
Note, also Global not highlighted and Function highlighting incorrect.
I've duplicated your code above and have seen some funkiness, but only in certain themes. I'm using "Mac Classic", but maybe I should test with more?
Not all themes are created equal it seems. Some themes have more/better/different syntax colouring ability than others - you can see this by the number of definitions (or the relative size of the scroll bar) in TextMate theme preferences.
Global has a different scope than field, so may be rendered differently by your theme. Not quite sure about the other issues.
What theme are you using? I'd like to try it. And perhaps you could try a different one as a test?
| I'm seeing the same oddness no matter the theme used (i.e. those that come with TextMate as well as ones downloaded from TextMates Wiki).|
BTW, the theme from the screen shots is called "Ruby Blue" downloaded from:
| I've just installed Ruby Blue and it is missing colour definitions for a lot of syntax elements: class name and function name in particular - they get rendered in the "source base" colour of white in Ruby Blue. It's easy to add in colours for these scopes in TextMate if you want to improve Ruby Blue yourself.|
That doesn't explain why you're seeing problems with other themes. For me, in Mac Classic, there are also missing colours for some scopes. For example Class is undefined, but luckily takes on the keyword colour due to scope inheritance.
So, what to do? I could tweak some things to try to improve matters, but even then I doubt things would work across all themes. The only sure fire way is for me to create a monkey theme for TextMate, making sure all scopes are catered for.
I'll add it to my todo list. (Don't worry I'll create it in as general a way as possible, to make it easy for people like yourself to recolour.)
ps: what version of TextMate are you running? I am on 1.5.10 (1631)
| Version 1.5.10 (1631)|
.. and thanks for the efforts! :)
| No problem at all.|
I've started to look into it and a dedicated theme is pretty easy, so it just means I need to find an hour or so where I can get it done.
Typically, it has shown that there is some related clear-up work to do in the scopes the bundle provides to make the theme is simple as possible.
| I've not forgotten about this, there's an update coming soon.|
Currently redoing all the scope naming so that syntax highlighting will displayer better on a wider range of TextMate themes.
| Any chance for a TextWrangler version? |
| If you can post a link to some docs of how they let you define syntax highlighting i'll look into it. Cheers |
| This has just been updated. Syntax colouring is much improved!|
The issue talked about above has been addressed, and some.
Let me know how you find it.
ps: here's a link to my preferred syntax coloring theme:
Will definitely check it out ...
| Works kickass! Thanks :) |
| Updated for v40, added support for Sound.Discard|
Download details in post #23 above
| Just added a feature that means pressing Option+Escape will present an auto-complete menu to choose from possible completions.|
So, auto completion options now stand at:
Press the Escape key to cycle through all matches after typing part of a keyword
Shift+Escape will take cycle backwards through all matches
Option+Escape will present a list of matches for you to choose from
As well as that expansion of keywords to full syntax through use of the tab key is still present, but only works after typing lowercase.
So the two main methods of auto-completion are currently at odds with each other in terms of case. Any thoughts as to whether this matters?
Download the latest version of monkey.tmbundle from github: https://github.com/gingerbeardman/monkey.tmbundle
| Thanks, works here :D|
Maybe the tab triggers need an upper case version too. I made a Print Snippet in the Bundle Editor (TM doesn't seem to care about 2 same snippet names) which triggers on Print (uppercase) and it works as expected.
btw: Can i still use the alpha version of Sublime Text 2 after a final version is out? For free i mean.
| I'll look into the best way to do uppercase snippets – I'd rather not duplicate all the snippets.|
(In answer to your question, I think Sublime Text will timeout at some point in the future.)
| I've just rolled out a "massive" update to this.|
What do these changes mean to the user? Faster and more accurate syntax highlighting. There was an issue with wrong syntax colouring if you used If...Then statements with no EndIf. This is now fixed.
- Added else/elseif snippet
- Reduced number of foldable elements
- Added keyEquivalent ^⌥⇧+M to activate bundle
- Renamed bundle from monkey to Monkey
- Removed preprocessor grammar
- Removed framework grammar
- Removed module grammar
- Added better if/then/elseif/else/endif handling
- Added bitwise complement operator
- Removed superstrict reference
- Tidied block comment grammar
- Replaced instances of (?:(?:^|;)\s*) with neater \b (regexp boundary)
- Removed references to integer number symbol %
- Corrected PI constants regexp
- Removed pointerops grammar
- Removed unused types from types grammar
| A few recent updates for this - some small fixes and a cool new jump to error feature:|
- Added jump to error capability
- Added LANG const
- Removed extraneous JOY constants
- Added missing JoyX/Y/Z keywords
- Added TARGET const
- Removed binary integer grammar which was resulting in incorrect display of numerical values
| No idea what I'm doing with this.|
To use unzip and double click...and double-click what?
or manually move the bundle to to: /Users/you/Library/Application Support/TextMate/Bundles/monkey.tmbundle
I don't have that path. There is no Library folder after the "you" bit. I have a Users/Library folder, with an Application Support folder in it, but nothing pertaining to TextMate.
Edit: Never mind - the file I downloaded was called gingerbeardman-monkey.tmbundle-eabd3c9 - had to rename the extracted folder to monkey.tmbundle, and double click that.
| Thanks for the rename tip, i'll be sure to put that in the readme. |
I want to do a screen cast of this as to get the most out of it requires knowledge of a few TextMate shortcuts and/or experienced user tricks.
Let me know how you get on with it.
| I've created a table of features so people can more easily see what each of my packages do:|
It's at my website: http://www.gingerbeardman.com/monkey/
| I've discovered a bug. With your new "Jump to error" feature. To describe exactly, when I'm working with multiple tabs, i.e. a project, it will jump to the proper line but it won't switch tabs to the proper window. Also, it won't even open the proper window. So if you do a update/run, you'll have no idea where the bug is and you'll have to do a build to have that tell you the class.|
Edit: Some additions to my description. Also, I love the new changes. They're pretty awesome even with this bug I've mentioned.
| Ah, right. As it is I ask TextMate to open the current file and jump to the error line number. I definitely do not cater for the situation you describe, actually I'd not even considered it. :)|
I'll reproduce it myself. Pretty sure I can fix the issue.
Glad you like the changes!
| This is now fixed.|
| Lots of changes in the latest version:|
The bundle can also check for updates, which is cool given that it is often updated.
- Added "Check for bundle update" and "Open bundle page on github" commands
- Added FirstNode, LastNode, NextNode, PrevNode, Exp (v45c)
- Added DisableKeyboard, EnableKeyboard (v45)
- Added ACosr, ASinr, ATan2r, ATanr, Cosr, Sinr, Tanr (v44)
- Added DrawPoly (v43)
- Added App: UpdateRate
- Added Audio: music commands (v35), Discard
- Added Graphics: DeviceHeight, DeviceWidth, Frames, HandleX, HandleY, Height, Width
- Added Lang: Print, Length, Resize, Compare, ToLower, ToUpper, Trim
- Added List: Backwards, Clear, Count, First, IsEmpty, Last, LastNode, ObjectEnumerator, RemoveFirst, RemoveLast, Value, ToArray
- Added Map: Set, Values, Key
- Added Random: Seed
- Added Set: Insert
- Added Stack: Insert, Pop, Push, Top
- Added all of the above to completions list
| Thanks matt, I really appreciate your efforts you are putting into this. Without this package, monkey would be nearly unusable on a mac. |
| I agree! Though that might be stating the obvious. ;)|
Whilst it looks like lots was missing and has been added in the update above, the majority of keywords are functions/methods that take no arguments. When I originally created the bundle I decided to only add support for those needing arguments, whose syntax you might need help remembering. But now, with time on my hands, I'm going for completeness.
Feel free to make a donation through my website http://www.gingerbeardman.com/monkey/
Hi Matt, great work.
I'm new to TextMate and noticed that when I set build options it actually inserts comments into my Monkey Code to drive it. Is this the only way it works? The reason being for clean builds. It inserted the buildopt, builds clean, but then it leaves it there.
Additionally, is there a way to stop that annoying empty editor window popping up after every build. :)
Yes, build options are meant to be put as a sort of set of build configuration comments at the start of your file. They're comments so they have no detrimental effect.
I'll look into the odd editor window thing, that is something I'd not noticed myself. How odd.
| The blank window thing has been fixed. Thanks for reporting the issue.|
| TM has the ability to use CTags (http://ctags.sourceforge.net) and view that in the Code-browser(Window->Code Browser).|
I am not really into c but it doesn't seem that hard. If you download the source there is a basic.c file which already includes bb-support it seems.
| Interesting. Do you have a link? |
I had briefly looked into ctags for the BBEdit bundle, but will do so again when I have time.
If you download the source distribution you will find lots of languages already in there including basic.
Also show the code-browser (Window->Show Code Browser), click on config button from the code-browser and click on manual which will bring up an introduction of the topic.
| Thanks, I will do so |
| If I have a class (e.g Rob) which has 2 method (A1 and A2) when I type the instance of Rob (orob.a) and press Option Escape, I get every command (ATan2 etc) but not the 2 methods??? |
| The bundle doesn't yet add arguments to the autocompletion. CTAGS are needed for this, and I've not had time to add them so far, I may never find time...|
The best you can do is type part of your method name, eg "Ro" (making sure to get the case correct) and press Escape once. This will complete the method name for you.
| Just so you know: this seems to import and work in Textastic on the iPad.|
| Super! I use Textastic, but was not aware it handled TextMate bundles. Thanks for letting me know.|
| Matt, I remember you trying to get integration with XCOde for Monkey. How did that end up? |
| It's still on my todo list I'm afraid. |
| Hi, i suspect you haven't done a syntax highlighting for Sublime Text 2 as well? |
| I have, actually. It has way more than just syntax highlighting.|
There's a separate thread for it: http://www.monkeycoder.co.nz/Community/posts.php?topic=593
Read more: http://www.gingerbeardman.com/monkey/
| I haven't seen this thread, thanks!|
I just stumbled over Sublime Text 2 via the Mojang Jam recenly and instantly loved it.
| Hey, just wanted to mention that the keyword sensitive help (pressing F13) doesn't work anymore due to the new docs. |
| Thanks for the headsup, I'm still using the old docs but I will update this eventually...|
FYI the new docs system does not have as good a search facility as the old docs system (disclaimer: I wrote the old docs system specifically to have great offline search). I've asked Mark in the v54 thread if they plan to add search (online or offline) to the docs wiki.
For now you should be able to use the TextMate Bundle Editor to change the two documentation commands in the Monkey Bundle to something that works for you. They basically just open generated URLs.
| I made a little tool so that competition of words also works for your own functions/methods/etc.|
In fact it's just analyses the monkey files you drag/drop on it and gives you the ability to export the keywords into an external file (called competitions.txt).
Open TM, go to menu Bundles -> Bundle Editor -> Show Bundle Editor and select monkey. Search for the 'competitions' entry (has a grey icon). Paste the files contents into here: Don't replace everything if you want to keep monkey commands. Just copy out the portion that's needed.
| Is this a sort of homebrew alternative to ctags? |
| I wrote it in blitzmax.|
It just outputs all functions, etc. you feed in. You have to manually copy this output into the text mate bundle editor under monkey/completitions.
Unfortunately you will have to this every time you write new functions, etc.
PS: Matt, you added the ability to press Alt+ESC and up pops a competition dialog. From what I understand this is done via
Textmate:UI:complete (competitions, options)
Is there a way to open this dialog while typing. That way we could have something that is nearly identical to auto-completition.
| TextMate 1.5 only allows the popup on shortcut key, not whilst typing. That's just their way of doing it, I'm afraid.|
You should look into CTAGS as you have just reinvented the wheel. :)
TextMate can be setup to regenerate CTAGS on each save of the document. If you want to work on proper CTAGS support, I would love to add it to the bundle.
As an aside, you could probably setup an OS X folder action to run files through your app on each save, but there'd be no easy way of getting the output into the bundle. CTAGS solves this issue.
| And CTags can alter the competition list?|
Also, in your latest bundle I can't fold a block if I don't do it the old BlitzMax way (e.g.: End Function instead of End).
| Yes, Ctags can do that as far as I know. |
The BlitzMax TM bundle does something similar to your solution using ruby. You might want to look at that, also.
My bundle only supports the verbose/old end statements. If you figure out the changes to get it to support shorter end statements then I will incorporate the changes.
| I have only managed to get the 'new' way done:|
foldingStopMarker = '(?xi) ^\s*( # end <keyword> end | wend | until | forever | next )\b';
Now you can write 'End Function' but it won't highlight Function.
I have never used regular expressions before so there may be an error in the above code.
monkey="$TM_MONKEY"; preWord="blitz-wiki.appspot.com"; postWord="4d8a.html"; if [[ -n "$TM_SELECTED_TEXT" ]] ; then keyword="$TM_SELECTED_TEXT"; else keyword="$TM_CURRENT_WORD"; fi echo "<meta http-equiv=\"refresh\" content=\"0;url=file://$monkey/docs/$preWord/$keyword$postWord\">";
This should fix the docs for current keyword not shown anymore issue.
| Does anyone know if it's possible with this to get a Method List or something similar?|
On the bottom of Textmate i think its called status bar? on the right, there i can choose classes, but it would be great if i can get a list of methods or functions too.
| @Shinkiro1 the end function syntax highlighting is tricky. I will happily accept and pull requests with improvements.|
@gekkonier the bundle language definition needs improving to get it to find methods and functions. Currently it only finds top level Classes and Functions. The blitzmax bundle does it, so it's possible. It just needs time to add the relevant regexps to the monkey bundle. It's on my list.
| new version|
- Added Set, FloatSet, IntSet, StringSet (v54c)
- Added DrawPoint (v50)
- Improved DrawPoly support
- Included Shinkiro1's new View Documentation for current keyword (v53 and newer)
- Added new View Documentation (v53 and newer)
| @gekkonier I have methods showing in the symbol list, but it has messed up syntax highlighting. I'll take another look when i have time |
| OK, I spent a few hours wrecking my head and have managed to do it. :)|
Methods are now showing in the symbol list, plus even more correct syntax highlighting. Adding the Symbol List support actually showed up a few things in the bundle that shouldn't have been the way they were so this is definitely for the best.
I'll package up and release it after I have checked it all over thoroughly.
| Thank you matt for your dedication! (and sorry if I choose wrong words - english is not my native language ;) ) |
| Hey matt.|
Currently when running the glfw target it opens up new empty Textmate file with a header like **BUILD SUCCEDED**
It's really annoying because it steals the focus of the game. So you always have to close this file and then click on the game window manually ...
Any way to prevent this from happening?
| Yes, this would need special casing in the Build and Update & Run commands. Should be an easy change to not do this line: |
If the output is the glfw success message. You'd also have to test it worked for a bad glfw build...
I am low on time right now so am still working on repairing syntax colour and code folding after changes to incorporate adding methods and classes to "show symbols". When I can...
| Yes that works. Thanks. |
| If you could put that change on GitHub I'd appreciate it. |
| Works the monkey.tmbundle also with TextMate 2? I have tried but i don't know where to copy the tmbundle file? |
| Make sure the file has the 'tmBundle' extension and you should be able to double click it (it copies itself in the right directory). |
| Oh no, thanks ;o) That was really simple.|
Great! The monkey.tmbundle works also with Textmate 2! I think it is not mentioned anywhere...
| Wow, this one was driving me crazy! I had installed an older version of the monkey.tmbundle.|
After that i wants to install the newer version from 2012-05-04. And it won't overwrite the older version automatically, grml!
I deleted TextMate 1 and everything i can find in the "Application Support" folder....
With a search at the terminal.....
sudo find / -type d -name monkey.tmbundle
... i found that TextMate 2 saves/finds some(!) of the Bundles under:
/Users/username/Library/Application Support/Avian/Pristine Copy/Bundles/monkey.tmbundle
What the hell is that ???
I deleted this crap and copied the bundle file by hand to the new TextMate 2 folder:
and this is different as described in the README.md:
More infos about here: http://blog.macromates.com/2011/locating-bundles/
| Btw, in the current version the 'Highlight current keyword' is broken again.|
Here is quick fix:
Go to Bundles -> Bundle Editor -> Show Bundle Editor, select Monkey and find the 'View documentation for current keyword' entry. Then copy the above in there.
Now you can view the documentation for most of the keywords again.
EDIT: How can I do a pull request? Do I have to fork the official branch for that?
If I'm honest, I've not got time to fix any of this stuff myself. But if you file pull requests on github I will merge them in and everybody will benefit.
| Hey, somebody knows if it's possible to update snippets without using textmate?|
I know it's just a simple xml file but it requires a property called UUID which looks like some hash generated id.
Also, I have updated my MonkeMate app.
It allows you to drop in monkey files and after you hit export it will output a completitions.txt file.
This file will have all Globals, Const, Fields, Methods and Functions (only public ones) so when you hit Escape you can get completition even if you haven't opened the file.
For now you have to manually copy the contents of the output file into completitions (which can be found inside Textmate->Bundle Editor).
Still a lot better than having just suggestions from the current file.
Edit: Don't replace everything if you want to keep monkey commands. Just copy out the portion that's needed.
| The UUID is just so TextMate can differentiate one menu item from another. It gives every item a unique ID for reference purposes. That's why if you copy a menu command from one bundle to another things can get a bit confused. At least in TM 1.5 (I'm now using 2.0 and have not looked at bundles just yet).|
Thanks for your updated monkeymate, it's a cool app.
I think using this website: http://www.famkruithof.net/uuid/uuidgen
will give me enough unique ids.
When I have more time on my hands I might write a script that automatically creates snippets from the docs.
| Thanks to @tluyben on github for a handful of changes. Much appreciated!|
They prompted me to release a new version – the first in a year – which addresses all outstanding issues on github, as well fixing as a few things I'd spotted myself.
Ready for v70