TextMate News

Anything vaguely related to TextMate and macOS.

Customization Screencast

Enrico Franchi asked how to cause return (↩) to also insert an asterisk when used inside block comments such as:

/* This is a block comment
 * which spans a few lines
 */

The answer can be found on the mailing list, but I also included it in the latest screencast (61.2 MB) which is really a must see for both novice and expert users.

It does a very good job at capturing how central a role language grammars play in TextMate and just how powerful that makes it!

categories Screencasts

15 Comments

For the records, here is the (slightly updated) reflow comment command created in the screencast:

#!/usr/bin/env ruby

txt = STDIN.read.gsub(%r{\A/|\*/\z}, '')
txt = txt.gsub(/^[\t]*\*[\t]*/, '')
txt = %x{ fmt <<< '#{txt.gsub(/'/, "'\\\\''")}' }.chomp
txt = txt.gsub(/[$`\\]/, '\\\\\0')
txt = txt.sub(/(\n(?=\n))?(\n*)\z/, '\1$0\2')
print "/* " + txt.to_a.join(' * ') + " */"

Nice one!
Your keyboard sounds like a good old one, what type are you using ;)

Very nice screencast!

One observation though: When you created the comment command, you associated a key equivalent to it, and then went on to associate a tab trigger to it. But in the process, the key equivalent was not lost and will still work, even though it does not show up in the bundle editor immediately, since the tab trigger is the one visible.

In other words, the program allows for BOTH key equivalents and tab triggers to be associated to the same bundle item, though the interface makes it look like it’s a “one or the other” situation. This has bitten me a couple of times. Just something to watch out for, and also to take advantage of.

That was awesome, I’m going to try and make my own today. :-)

Martin: It’s just a regular Apple keyboard (came with my G5.)

Haris: Yes, I noticed myself that I make it sound like the two options are mutually exclusive. I do have on the list, that in the future, the activation method should be done as a list — this will also be necessary when more options are added.

I do have on the list, that in the future, the activation method should be done as a list — this will also be necessary when more options are added.

Now you’re just making me drool. :)

Slick.

That one screencast could easily have been broken up into three smaller screencasts, though.

18 April 2006

by Dan Kelley

Of course the content is great, but there is another thing that I liked particularly: the clarity of the images in the screencast. A blurry screencast is not helpful. (By the way, some of the images in the TM documentation are a bit on the small side.)

25 April 2006

by Nithin

The part on reformatting comments is exactly what I’ve been looking for. Thanks!

I do have a minor problem. When I reformat the comments and insert as snippet, the line immediately underneath the last line in the comments gets indented. How do I prevent that from happening?

Example.

this

is an example

def example

becomes this…

this is an example

def example

25 April 2006

by Nithin

Hmm…

The 2nd code snippet should be

this is an example

..def example

(with the .’s representing spaces)

Nithin: could it be, that your command inserts the indent?

26 April 2006

by Nithin

My original example is inaccurate.

It only happens when comment scope is indented. Revisiting the example (with .’s for spaces):

..# this is

an example

def example
end

becomes:
..# this is an example
..def example
end

each additional reflow indents the first line of code some more (after three reflows):
..# this is an example
……def example
end

If the comment is not indented, then the first line of code remains unchanged regardless of the number of reflows.

I don’t believe I’m inserting tabs, here’s my command:
#!/usr/bin/ruby

txt = STDIN.read
txt = txt.gsub(/^[ \t]#[ \t]/) { ‘’ }
txt = txt.gsub(/”/) { “\"” }
txt = txt.gsub(/[$\\]/) { |match| "\\#{match}" } txt = %x{ fmt -80 -l 0 &lt;&lt;&lt; "#{txt}" }.chomp txt = txt.gsub(/[$\]/) { |match| “\#{match}” }
txt = txt.sub(/\n?\z/) { |match| “$0#{match}” }
txt = “# “ + txt.to_a.join(“# “)
print txt

26 April 2006

by Nithin

I’m getting around this right now by selecting the comment section and then executing the command.

Any hints how this ruby script can be modified to keep javadoc-style tags on their own line?

  • @access public
  • @param string $file Include path to css files.
  • @param mixed $apps App name string or array of app names.
  • @return bool True on success, false on failure.

27 April 2006

by Nithin

Instead of reformatting the text as a whole, break them up into an array containing sections delimited by javadoc styles. So the array would look something like this:

[
“@access public\n”,
“@param string $file Include path to css files\n”,
“@param mixed $apps App name \n string \n or array of app names\n”,
“@return bool True \n \n on success, false on failure.\n”
]

NOTE I’ve inserted newlines in the comments to accentuate a situation where you would want to reformat it.

Then iterate through the array calling the fmt shell command.