Is there a way to always run the same file in TextMate, when working on a Python project? I always press ⌘+R when editing a random file, forgetting to switch back to the tab containing the main of this project. There's got to be a way to do that; clicking tabs is really a speed-bump in that scenario.
1 Answer
Yes it is possible and there are several possibilities to achieve that. An easy fix would be to write a command which invokes python on the main file, i.e.
python /path/to/project/main.py
as a command bound to Command + R. Better commands would be
python $TM_DIRECTORY/main.py
or
python $TM_PROJECT_DIRECTORY/main.py
However, you will loose the nice looking output the default command provides. Therefore you have another option: Set the instance variable $TM_PROJECT_MASTER to point to your main file. You can either set this variable absolute or relative to $TM_PROJECT_PATH. A relative path may be advisable of course. To do so, you may either set $TM_PROJECT_MASTER as a static environment variable, which can be done as follows
- Go to "Settings" > "Advanced" > "Shell Variables"
- Add the variable "$TM_PROJECT_MASTER" and type in "main.py" or whatever is appropriate for your projects
If the location of your main file changes from project to project, this setting doesn't help. However, you can set project dependent shell variables, which would be the solution in such cases:
- deselect alls files in your project drawer
- click the small info button - a window with project dependent shell variables will pop up
- again add the variable "$TM_PROJECT_MASTER" and fill in the relative position of your main file
This should help. Have fun!
PS: See https://github.com/textmate/python.tmbundle/commit/c3e38e318c5e80b8fdd78730d65f1a7dee5aa911 if you look for an explanation, why setting $TM_PROJECT_MASTER helps.
%!TEX root
for TeX files in TextMate and TeXShop.