TextMate 2

From Exterior Memory
Jump to: navigation, search

TextMate 2

TextMate is a text editor for Mac OS X, geared towards programmers (it only supports plain text, without layout). TextMate version 2 is currently in beta.

Here is a list of issues I found, and how I solved them.

Bundle Location

In TextMate 2, bundles can be installed from the preference dialog, and edited with the bundle editor (menu Bundles > Edit Bundles...).

TextMate 2 keeps a list of Bundles in ~/Library/Application Support/TextMate/Managed/Bundles. Any edits you make will be stored as a diff in ~/Library/Application Support/Avian/Bundles

(The folder has a different name to avoid interference with TextMate 1, but why this folder is called Avian instead of TextMate2 is beyond me.)

Auto-indent

TextMate 2 has a tendency to alter indentation when you start typing. For example in the Mediawiki bundle, typing " word" (with a space as the first character) results in the removal of the space if the line above doesn't have a space either. The only way to correct this is to return to the space after typing "word". Conventional auto-indentation only occurs in response to pasting or hitting return.

Since r9283 TextMate has two settings to control the indentation behaviour:

disableIndentCorrections
Enables or disable indentation upon typing text. It does not affect the regular indentation that occurs after pressing return to create a new line.
indentOnPaste
Controls how to indent when pasting text. indentOnPaste can be set to:
simple Indents the paste to the position of the caret. (this particularly works well for Python.)
disable Pasted text is inserted as-is without indenting it.
«unset» Pasted text is indented based on the current scope.

These parameters can be set by adding a new “Settings” item with the following properties:

   {   disableIndentCorrections = :true;
       indentOnPaste = 'simple';
   }

If you want to disable all indentation corrections anywhere, create a new bundle (I created a bundle called "Indentation" for this purpose) and set the scope to `*`. This even disables indentation corrections if you press enter after you open or close a code block with { or }.

Map file extensions to Bundles

If you open a file with unknown extension, TextMate 2 will ask you which bundle to use for the language rules.

If you opt to keep this preference, it is stored in the file ~/Library/Application Support/TextMate/Global.tmProperties. If you made a mistake, you can change this file manually to revert your preferences.

Font size

TextMate 2 has the ability to adjust the font and font size for each scope. While I love the colour coding and occasional bold or italic, changes in font size bother me, especially for Setext or Markdown:

Title
=====

Plain text

Subtitle
--------

More text.

In TextMate 2, only the underline is selected, which just looks weird if that gets a large font and the actual header does not.

To turn off fonts and font sizes, edit the Themes bundle, and go to settings. Here you will find the styles for different scopes. I removed all "fontName" and "fontSize" declarations.

That's it!

Shift right

It is common practise not to indent blank lines. I have personal preference that blank lines are indented. Surely this was caused by TextMate 1 where the folding did not work properly for non-indented blank lines:

▽  def myfunction(a, b):¬
       print(a)¬
△  ¬
       print(b)¬

Instead of:

▽  def myfunction(a, b):¬
       print(a)¬
       ¬
△      print(b)¬

TextMate 2 folds correctly, but my preference remains.

One little annoyance is that the shift right command increases the indent of all selected lines, except for blank lines.

To remedy this, I created a new command in a bundle, called this Shift Right with keystroke ⌘]. The other properties are default (Save: Nothing; Input: Selection, Text; Output: Replace Input, Text; Caret Placement: Heuristic.).

#!/usr/bin/env python
import os
from sys import stdout, stdin, exit

if ("TM_SOFT_TABS" in os.environ and os.environ["TM_SOFT_TABS"] == "YES"):
    try:
        indent = int(os.environ["TM_TAB_SIZE"])*" "
    except KeyError:
        indent = " "
else:
    indent = "\t"

if ("TM_SELECTED_TEXT" in os.environ and os.environ["TM_SELECTED_TEXT"] != ""):
    for line in os.environ["TM_SELECTED_TEXT"].splitlines(True):
        stdout.write(indent+line)
elif ("TM_CURRENT_LINE" in os.environ):
    stdout.write(indent+os.environ["TM_CURRENT_LINE"])

Bug fixes

Javascript Symbol List

The JavaScript Symbol list (popup menu in lower right of the window) contains a fair amount of noise. It includes objects, entities, functions and methods. I created a patch that only leaves the functions and methods.

Bugs

Caret placement: select output

Summary:

The command option "caret placement": "select output" does not work, but behaves as "caret placement": "place after output".

Steps to reproduce:
  1. Open a bundle in the editor
  2. Create a new command
  3. Retain the default code and settings:
    Code: echo "Hello world\n"
    Input: Selection - Text
    Output: Replace Input - Text
    Caret Placement - Select Output
  4. Add a key equivalent
  5. Save and open a blank text window
  6. Press the chosen key equivalent
Expected result:

The text "Hello world" placed and selected

Actual result:

The text "Hello world" placed, no selection. Caret positioned after the inserted text.

Order of items in Bundle Menus

In TextMate 1, it is possible to change the order of items in a submenu in the Bundle Editor: simply select an item and drag it to the desired location.

In TextMate 2, drag and drop does not work (test with TextMate r9325 on OS 10.7.5). I'm sure it is possible to change the order by editing the info.plist in ~/Library/Application Support/Avian/BundleName.tmbundle/info.plist, by adding the UUID of the command to the right location. Unfortunately, I was not able to find the correct format of the plist.