I'm attempting to use TM for my most common development tasks, but haven't got my head around it yet. Can someone point me at the right place to find documentation about the following:
Task 1: I work on a code base of about 50,000 lines of ordinary C code, spread over about 30 files. Most of what I do is cut, paste, search, make. I want to add some functions to the context menu. First, I want a function that would take me to the definition of the item under the cursor. E.g., if it's a function, open a window containing the prototype, or otherwise show me the prototype. If it's a constant, take me to the header file where it's defined. Second, I want a function that will find references to the symbol under the cursor. I don't want it to find definitions or comments, just any chunk of code that actually uses the symbol. This would be some variant of the 'Use Selection For find', but as a context menu item.
Task 2: I want to add an item to the context menu that will do the following: save any dirty files, then run the makefile of the project. If there are any errors, take me to the place in the source file that contains the first error. This would be something like the Command-B, but as a context menu item. Also, when I tried using Command-B, it attempted to build the code using Xcode. I just want it to run the makefile in a shell and show me the errors. I would also want to
On 28/09/2007, at 20:18, pixpop wrote:
[...] Task 1: I work on a code base of about 50,000 lines of ordinary C code, spread over about 30 files. Most of what I do is cut, paste, search, make. I want to add some functions to the context menu. First, I want a function that would take me to the definition [...]
Perhaps the CTags bundle will be of use to you: http://macromates.com/svn/Bundles/trunk/Bundles/CTags.tmbundle/
For install instructions see http://macromates.com/textmate/manual/bundles#getting_more_bundles
Task 2: I want to add an item to the context menu that will do the following: save any dirty files, then run the makefile of the project. If there are any errors, take me to the place in the source file that contains the first error.
There is a Makefile bundle, it does this, but it is *very* rudimentary (I wrote the build command, but I rarely ever work with Makefiles, so I didn’t spend much time prettying up the output).
See above for how to get it.
This would be something like the Command-B, but as a context menu item.
You can’t add stuff to the context menu, but it is on ⌘B, though only for Makefiles. If you go to the build command you can change the scope selector to be more broad (i.e. be all your C files by specifying source.c).
Allan Odgaard-2 wrote:
You can’t add stuff to the context menu...
Oh. That's disappointing. Is there any chance this will become possible in the future?
On 01/10/2007, at 16:46, Neil Baylis wrote:
You can’t add stuff to the context menu...
Oh. That's disappointing. Is there any chance this will become possible in the future?
You prefer having your build command in a context menu for text? It doesn’t actually belong there.
A context menu is for actions related to the current context, I can see people wanting file type specific (custom) actions in the project drawer’s context menu, or various text manipulation actions in the current context menu (in some configurable way), and I am considering ways to support that. But I don’t really get your workflow, so maybe you want to elaborate on that, and why it is disappointing only being offered ⌘B and a global menu to build your project.
Allan Odgaard-2 wrote:
But I don’t really get your workflow, so maybe you want to elaborate on that, and why it is disappointing only being offered ⌘B and a global menu to build your project.
My disappointment was not about the build command per se, but rather about the fact that one cannot add _anything_ to the context menu. The items I would most want in the context menu would be looking up definitions and references when the cursor is over some symbol. I use the mouse a lot, because I suck at remembering keyboard shortcuts.
You asked about my workflow...
Currently, I use vslick running on a linux box at the office. All my colleagues simply use ssh and vi. My company changed their WAN, and now using vslick remotely (using X on the Mac) is untenable. That's why I'm looking for a new editor, and how I got to TextMate. After using TM for a few days, I purchased a license as I discovered all kinds of good things to use it for (E.g. building code for PIC microcontrollers, maintaining my website, etc).
To work remotely, I used to run an X session on my Mac, and project the vslick session onto it from the linux box at work. Since the change to the WAN, that's simply too slow. Now I remotely mount the filesystem of the linux box using sshfs (MacFuse) and edit the files with vi. I've tried this with TM, and it works, but is a bit slow. Strange things happen, for example if I have a few files open in TM, and then cover the TM window with another App. When TM gets focus again, there is sometimes a long delay before it responds. During this time, I see the network lights blinking madly, so I guess TM is checking the files or something.
On 03/10/2007, at 04:38, Neil Baylis wrote:
[...] My disappointment was not about the build command per se, but rather about the fact that one cannot add _anything_ to the context menu. The items I would most want in the context menu would be looking up definitions and references when the cursor is over some symbol.
I just did an interview http://blog.johnjosephbachir.org/2007/10/01/interview-with-allan-odgaard-cre...
If you search for ‘toolbar’ and read my concerns here about adding these, you’ll find that the same applies to context menus. I.e. TM is meant to work with lots of different kinds of text and mixing different formats in the same file.
In that light, adding a command to “lookup references” does not make sense, because there will be 10+ different ways to do that, based on context. The problem is solved for key bindings in the form of scope selectors and the disambiguation menu, but it is not yet solved for creating a context aware visual UI (such as a palette, toolbar, or context menu actions), at least not solved to my satisfaction.
[...] Now I remotely mount the filesystem of the linux box using sshfs (MacFuse) [...] When TM gets focus again, there is sometimes a long delay before it responds
This is a problem with folder references in 1.x: http://macromates.com/wiki/Troubleshooting/Beachball
Allan Odgaard-2 wrote:
In that light, adding a command to “lookup references” does not make sense, because there will be 10+ different ways to do that, based on context.
Yes, I agree with you. I'm thinking of something much simpler. Just allow a bundle to add an arbitrary item to the context menu. When the user selects the item, it would trigger a command. If it's possible to trigger a command from a keystroke, then it's possible to trigger the same command by selecting a menu item. In the bundle editor, there's an 'Action:' dropdown that has two choices: 'Key Equivalent' or 'Tab Trigger'. I'm just suggesting that you put a third option in there: 'Context Menu Item'.
Of course, this is mainly of value to those of us who use a mouse with more than one button. I have no idea what proportion of Textmate users that amounts to, so maybe it's a moot point. (If I had to hit the keyboard to get the context menu, I could just as well bind the action to a keystroke).
On 03.10.2007, at 08:20, Neil Baylis wrote:
Allan Odgaard-2 wrote:
In that light, adding a command to “lookup references” does not make sense, because there will be 10+ different ways to do that, based on context. Yes, I agree with you. I'm thinking of something much simpler. Just allow a
bundle to add an arbitrary item to the context menu. When the user selects the item, it would trigger a command. If it's possible to trigger a command from a keystroke, then it's possible to trigger the same command by selecting a menu item. In the bundle editor, there's an 'Action:' dropdown that has two choices: 'Key Equivalent' or 'Tab Trigger'. I'm just suggesting that you put a third option in there: 'Context Menu Item'.
Of course, this is mainly of value to those of us who use a mouse with more than one button. I have no idea what proportion of Textmate users that amounts to, so maybe it's a moot point. (If I had to hit the keyboard to get the context menu, I could just as well bind the action to a keystroke).
I went this way by using a NSOtherMouseDown command, meaning the middle mouse button (scroll wheel). I wrote a small plugin which adds a eventhandle for NSOtherMouseDown. If one click the middle button it will call as default a tmCommand 'OTHERMOUSEDOWNCOMMAND'. In that script you can put any commands in (e.g. as "$DIALOG" -u inline pulldown menu) as you like. For me, I wrote a command which asks for the current language (Plain Text, Ruby, ...). Depending on that language I have different menus - meaning different 'context sensitive menus'. Furthermore I always ask whether the cursor is in an OakTextView, if yes the OTHERMOUSEDOWNCOMMAND will be executed otherwise not in order to avoid unstableness. To switch this behaviour on/off I created a new key in the com.macromates.plist. And you can rebind the executed script on runtime.
I also tried this with NSRightMouseDown event. In principal it works, but sometimes I have a problem with NSRunLoop(?).
I'll also put this in the soon coming TMTOOLS plugin.
Hans