7/8/2023 0 Comments Wanted textmate smartI pointed him toward how pdflatex and xcodebuild uses the HTML output capability of commands to present a glorified build report with potential errors shown using hyperlinks, and it didn’t take him long to create something even nicer for Python (called PyMate). Pressing ⌘↩ results in: str = """Hello world"""Īnd while on the topic of Python, Domenico Carbotta asked for a running environment for Python which would catch exceptions and show these with links to the source. Generally though, you can use ⌘↩ (command return) to go to the end of the line and insert a newline, so if you have typed this (again, with | marking the caret): str = """Hello world|""" So if the string was already triple-quoted, it probably should overwrite when at the end of the string (in front of the threee quotes). And it ends up looking like this:Īmazingly simple if you ask me :) We could make it more advanced by letting the Python grammar assign a name to various forms of empty/non-empty double/triple-quoted strings, and overload the meaning of " depending (even more) on context. What we really want is to get rid of the overwrite feature of smart-typing, and we can do that by making a snippet which is set to "$0" and have " as key equivalent ( $0 is where the caret ends, after inserting the snippet).īut since it’s only inside strings (in Python) that we want to change the behavior of the " key, we set the scope to: source.python string. One can of course disable smart-typing, disable it for Python, or exclude the quote-character from the smart-typing pairs (for Python), but we choose neither. In Python there are triple-quoted strings ( """like this""") and while there is a snippet which allows you to type tr followed by tab (to get """|""", | marking the caret) and even press tab again (after typing the string content) to skip the last 3 quotes), many will probably reach for the “ key when they want to start a string. If you type a second quote-character, it will overwrite the auto-inserted character (so that when you instinctually e.g. When you type a quote-character, TextMate will auto-insert an extra (closing) quote to the right of the caret (with a few exceptions). TextMate will pick up that the result is a diff file and show it like this: It opens the result from diff in a new window. In the GUI this looks like this (click for full size): The $TM_FILEPATH is a shell variable containing the full path of current file. I was asked on IRC today if TextMate could show the changes from last time the document was saved, and was also informed that smart-typing of quotes conflicts with Pythons triple-quoted strings.īoth things turns out to be surprisingly simple to fix for the user, and since this isn’t the first time I’ve been asked for features where the solution expose TextMate’s ease of customization, I figured it was time to start a Tips and Tricks category on this blog.Īs for showing the differences between the current document and the version on disk: OS X ships with the standard diff command, and TextMate already has syntax highlight for diff files, so what we need is to create a new command that runs diff on the current buffer and the file on disk.īy using - as filename for diff, we instruct it to use the standard input (a unix convention), so the command needs to have standard input set to “Entire document”, output to “Open as new window”, and the actual command should then be: diff -u "$TM_FILEPATH". Next post: The power of snippets Tips and tricks Previous post: Universal binary (and more)
0 Comments
Leave a Reply. |