In TextMate 2, is it possible to change the title of the open tabs? - textmate

In TextMate 2, when you have multiple documents open at once, and they appear in a row of tabs on the main window, is there a way to change the text (filename) shown in each tab?
By default, it shows the file's basename (the filename without any path information). I don't want full path information displayed on each tab, but I would love to have the file's current_directory/filename on each tab.
(In .tm_properties, I did set windowTitle = $TM_FILEPATH to show the full filepath at the top of the main window, so I at least have that.)
To illustrate what I'm asking, if I have a set of files open as such:
/Users/me/projects/code/lib/Shapes.pm
/Users/me/projects/tmp/Shapes.pm
/Users/me/projects/var/data/Shapes.pm
This is what the tabs currently look like:
Shapes.pm | Shapes.pm | Shapes.pm
What I would prefer is to see is:
lib/Shapes.pm | tmp/Shapes.pm | data/Shapes.pm
i.e., each file's current directory prepended to the filename itself. A Perl regex would make easy work of getting that. Does TextMate 2 give you the ability to modify the "tab title" per above? Thanks!

Since TextMate v2.0-rc.8 (2018-03-08, installable when enabling "nightly builds") the tab title can be configured in the same manner you would do with the window title.
For example, the following configuration would give you the filename, prefixed with the name of the immediate parent directory.
tabTitle = "${TM_DIRECTORY/^(.*[\/])//}/$TM_DISPLAYNAME"

Related

Sublime Text 3 - Change color of just one window?

I use multiple windows of Sublime Text at once and would like to set each one to a different color theme. By default, changing the 'color preferences' changes them for all open windows.
Note it is possible to set the color scheme for a single window using a 'project settings' file (which suggests it is possible in general), but then the folder must be opened via the 'project settings' (and not just opening the folder).
How can I (programmatically or via the app) set a separate color scheme for a single SublimeText window?
You can do this with a small plugin. Create a new file with Python syntax, and the following contents:
import sublime_plugin
class ChangeWindowColorSchemeCommand(sublime_plugin.WindowCommand):
def change_scheme(self, scheme):
for view in self.window.views():
view.settings().set("color_scheme", scheme)
def run(self):
message = 'Enter path to color scheme:'
path = 'Packages/Color Scheme - Default/Monokai.tmTheme'
self.window.show_input_panel(message, path, self.change_scheme, None, None)
Save the file in your Packages/User folder (accessible via Preferences -> Browse Packages...) as change_window_color_scheme.py. You can trigger the plugin in two ways - from the console, and via a key binding. To run it via the console, open the console with Ctrl` and enter
window.run_command('change_window_color_scheme')
An input panel will open at the bottom of the window, where you can enter the path to the color scheme you want to use. The default value is Monokai, but you can change that in the plugin source if you want. Once you enter the path, hit Enter and all the files in the current window will use that color scheme.
To create a key binding, open Preferences -> Key Bindings-User and add the following:
{ "keys": ["ctrl+alt+shift+s"], "command": "change_window_color_scheme" }
If the file is empty, surround the above with square brackets [ ]. Save the file, and you can now trigger the plugin using CtrlAltShiftS, or whichever key combination works best for you.

Perform Search on Whole Directory in Sublime Text 2?

Is there any directory-wide search functionality in Sublime for the directory currently opened in the editor?
Or optionally a search all opened files? (If this exists do the files have to be opened in a tab or just visible on the sidebar?)
Yes there is.
On Windows
CTRL + SHIFT + F
On Macintosh
CMD + SHIFT + F
The Where field in the search panel determines where to search. You can define the scope of the search in several ways.
More: https://docs.sublimetext.io/guide/usage/search-and-replace.html
In Sublime Text 3
Right click on FOLDERS Navigation bar
Choose Find in Folder
*/folder_name/*
In the "Where" section of the find-all dialogue (CtrlShift+F or ⌘Shift+F ), */folder_name/* will search folders called "folder_name" that are represented in your current session. For instance, if you have a file open with a path of C:\Users\joe\folder_name\file.js, you can use the *//* pattern to search any of those folders or combinations of folders: */joe/* and */Users/joe/* will both work. However, if you have a file like this C:\Users\timmy\folder_name\file.js that's not open, it won't search that (unless you explicitly name it, like in the next example).
C:\path\to\folder
You can also put in the absolute path to the folder you want to search. This is useful if you want to search a folder that is not represented in sublime (no files within that folder are currently open in sublime), or if you have two dirs with the same name, and you only want to search one. Personally, I never use this.
C:\path\to\folder, */folder_name/*
You can also combine them.
To answer your last question, at some point Sublime started automatically searching all open files and represented folders, but if you want to be sure you can use one or all of these variables:
<project>,<current file>,<open files>,<open folders>
You can read more about searching at the unofficial sublime documentation. Or from this post, which is similar to your own.

How to set TextMate Soft Tabs to 1?

I want my tabs to be 1 space only, however, TextMate does not let me do it. Is there a way of doing it?
thanks
Click the tab size popup in the status bar, enable soft tabs, select "other..." and set it to 1.
Source- the textmate website:
4.11 Using Spaces Instead of Tabs
TextMate can use spaces instead of tab characters. This is done by clicking the “Tab Size” pop-up in the status bar and enabling Soft Tabs.
This setting will only affect the current language and all languages with a common root that do not have the option set yet. The same applies to the state of spell checking, soft wrap and the actual tab size.
When soft tabs are enabled, TextMate will for the most part act exactly as if you were using hard tabs but the document does indeed contain spaces.
set a .tm_properties file in either ~/ or your project root to with the following content:
softTabs = true
tabSize = 1
Your preference is, like comments imply, rather strange, but serviceable nonetheless.

Adding new filetypes to Windows 7's New context menu

I'm trying to add CSS, PHP, JS and HTML file types to the "New" right click menu in Windows 7. I know how to add the file types to the menu with ShellNew entries in the registry. But Windows doesn't give you any control over the display names of the new items - according to this the name's always taken from whatever application you've assigned to open the doc. I've set Notepad++ to open all of these file types, so I'm going to end up with several identical "Notepad++ document" entries in the menu, like this:
Does anybody know if there's a way out of this stupid situation without installing any tweak utilities?
Thanks all!
Fred
To rename a context menu > new's item (in Windows 7, at least):
Open regedit.
Go to HKEY_CLASSES_ROOT\.%ext% and note the (Default) value. This is the file extension's ProdID.
Go to HKEY_CLASSES_ROOT\%ProdID% (usually %ext%file) using the value obtained from step two. Set the (Default) value to whatever you would like the context menu new item to display as.
Under HKEY_CLASSES_ROOT\%ProdID%, if there is a FriendlyTypeName value, rename it to FriendlyTypeName.old, as the (Default) value "is deprecated by the FriendlyTypeName entry"
I don't believe there is even a need to log out / restart, but if the changes don't take effect, log out and/or restart.
You could change the file type description for each file class manually.
Look up the prog id under HKEY_CLASSES_ROOT\.%ext% (The default value)
Under HKEY_CLASSES_ROOT\%progid%, set the default value and/or the "FriendlyTypeName" string to the string you want.
You might have to log off for it to take effect.
You should probably stay away from the Chrome and Notepad++ file type/association dialogs so they don't overwrite your strings.
Both Chrome and Notepad++ are open source, you can create a patch for them that use better names for the file types. (What is a "Chrome HTML Document" anyway, HTML5 + extra chrome juice? =) )
I was able to derive a solution from the answers above.
I replicated the particular application (JetBrains PHPStorm in my case) registry entry.
PHPStorm2019.1 -> PHPStorm2019.1.scss, PHPStorm2019.1.js.
Now I changed the Default REG_SZ of PHPStorm2019.1.scss to SCSS File and PHPStorm2019.1.js to JavaScript file.
Mapped .scss and .js to PHPStorm2019.1.scss and PHPStorm2019.1.js respectively.

AppleScript to take text and turn it into pasteable HTML

We work with bugzilla. Whenever you need to query a ticket you just need to know the bugid (integer) and you simply prepend this to it.
http://<bugzilla_server>/bugzilla/show_bug.cgi?id=<bug_id>
Suppose I have a bug link which looks like this 777. If I select and copy this it is preserved on the pasteboard so when I paste this into mail it will correctly preserve the link and it's attributes.
What I am looking for is to simple type '777' select it and run an applescript on it and replace it with a link like the one above. Can anyone help me out??
The following AppleScript will take the contents of the clipboard and replace it with the URL prepended:
set the clipboard to "http://bugzilla_server/bugzilla/show_bug.cgi?id=" & (the clipboard)
You can compile that to an AppleScript scpt and make it available in a Scripts folder or compile it to a launchable app:
osacompile -e 'set the clipboard to "http://bugzilla_server/bugzilla/show_bug.cgi?id=" & (the clipboard)' -o replacebug.scpt # or -o replacebug.app
If your primary use case for this is in composing mail in Mail.app, this may not be the most user-friendly approach, though. If you are using Snow Leopard (10.6), a simpler solution is to take advantage of the new Text Substitution feature. Open the System Preferences -> Language & Text preference panel, select the Text tab, and click + to add a new substitution, perhaps:
Replace With
(b) http://bugzilla_server/bugzilla/show_bug.cgi?id=
Then, in Mail.app, start a New Message and, with the cursor clicked within the text body, do a Control click of the mouse to bring up the contextual menu. From it, select Substitutions -> Text Replacement. From now on, as you are typing in the text body of the email when you type:
(b)777
the (b) will automatically change to the URL text you saved:
http://bugzilla_server/bugzilla/show_bug.cgi?id=777
This will also work in other Cocoa text-enabled applications like Safari.
EDIT:
When talking about composing URL links in email, there are at least three different formats of email, each with a different solution. Since you don't say which kind you are using, I'll cover all three:
Plain text format - There's no way to "hide" the URL in the composed email although some email readers might present a clickable link for a plain-text URL.
HTML-formatted email - Apple's Mail.app does not support composing email in this format although it will display it. Using some other mail writer client or your own program, it's easy enough to compose a link using a standard HTML anchor <a href=...> tag.
Rich Text Format email - AFAIK, this is the only way to compose a URL link with Mail.app. Unfortunately, there does not appear to be an easy way to directly create an RTF hyperlink using AppleScript commands. Based on a suggestion here, this is a way to do it by creating a modifiable RTF template via the clipboard.
In TextEdit.app, create a new Document window.
Insert the text you want to appear in the email, i.e. 777.
Select the text (⌘A) then add a link (⌘K). Enter the full URL also with 777 into the "Link destination" field; click OK.
Modify the text format as desired with Format menu commands.
Save the file (⇧⌘S) as temp.rtf with File Format -> Rich Text Format.
Close the document window.
Open a document window (⌘O) selecting file temp.rtf and selecting Ignore rich text commands.
Insert the following before the first line in the file:
#!/bin/sh
sed -e "s/777/$(pbpaste -Prefer txt)/g" <<EOF | pbcopy -Prefer rtf
Append EOF as a separate line at the end of the file.
It should now look something like this:
#!/bin/sh
sed -e "s/777/$(pbpaste -Prefer txt)/g" <<EOF | pbcopy -Prefer rtf
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf250
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural
{\field{\*\fldinst{HYPERLINK "http://bugzilla_server/bugzilla/show_bug.cgi?id=777"}}{\fldrslt
\f0\fs24 \cf0 777}}}
EOF
Save this as a Plain Text file and execute directly as a shell script or call it via the AppleScript do shell script command.
This kind of solution will work with most other applications that support Rich Text format.
Not sure exactly the function you're looking for, but this will take a number from your clipboard and process it into a link and put the link on the clipboard as a standard href URL that will work in plain or rich text, like:
Bug number 777 link
Change <bugzilla_server> to your working URL.
set bug_number to the clipboard
set the_text to "Bug number " & bug_number & " link"
set the clipboard to the_text

Resources