CommonThread

Displaying articles with tag

Textmate Footnotes with vim support

Posted by ben, Wed Jun 11 01:31:00 UTC 2008

I just switched to doing rails development in vim rather than textmate but I sure did miss my textmate footnotes. I found a post about a plugin called redit that converted stacktraces over to links that would open in vim (textmate footnotes style) so I decided to take that and patch Textmate Footnotes. I had to make sure not to messup any of the developers who were going to still use Textmate so it patches it to do both based on an env variable we will talk about later.

Redit Controller

First I took the controller from the afore mentioned plugin and tweaked it to make sure we were running in development mode before executing code on the server and changed it to use MacVim as the vim app. Simply create a new controller called ReditController and paste the code below changing the system call if you use something other than MacVim.

require 'base64'
class ReditController < ApplicationController
  def open
    if ENV['RAILS_ENV'] == 'development'
      file = Base64.decode64(params[:id])
      line = params[:line].to_s

      # Run editor here
      Thread.new do
        ### MacVim
        # Open file in new tab of vim server
        system("mvim","--remote-tab","+#{line}",file)
      end 
    end
    redirect_to :back
  end
end

Textmate Footnotes Patch

Next you need to replace the lib/textmate_footnotes.rb with this one. I am working with an older version of textmate footnotes so be forewarned that my file may not work 100% with your version … I will update to the latest soon and update my file. Here is an example of how the patch changes the urls generated:

def controller_url
    if ENV['FOOTNOTE_APP'] == 'vim'
      escape(
        "/redit/open/" +
        CGI.escape(Base64.encode64(controller_filename)) +
        (index_of_method ? "&line=#{controller_line_number + 1}&column=3" : "")
      )
    else
      escape(
        textmate_prefix +
        controller_filename +
        (index_of_method ? "&line=#{controller_line_number + 1}&column=3" : "")
      )
    end
  end

Environment Variable

And lastly to make the plugin give you vim links rather than textmate links you need to set the FOOTNOTE_APP env variable. To make this happen every time you login place the following snippet in your ~/.bash_profile

export FOOTNOTE_APP=vim

0 comments | Filed Under: | Tags:

Tip: TextMate Scan

Posted by anthony crumley, Tue Jan 08 13:18:00 UTC 2008

A nice search like feature in TextMate is the scan. Press ctrl-s and a text box opens in the status bar at the bottom of the editor window. As you type into the box TextMate will automatically select the first match in the open document. Press ctrl-s again to jump to the next match. Press escape or return to exit scan mode.

0 comments | Filed Under: | Tags:

Tip: TextMate New Ruby Method

Posted by anthony crumley, Tue Dec 11 09:33:00 UTC 2007

There are two ways to quickly create a Ruby method in TextMate. The first is to type def and then press the tab key. The result will be…

def method_name

end

The method_name will be highlighted and ready for you to type the name of your method with any necessary parameters. Once the name and parameters are entered you can press tab to begin writing the method.

The second way is to type the name of the method followed by shift-return. If the method name is find then the result will be…

def find(args)

end

The args will be highlighted and ready for you to enter the parameters. If the method does not require parameters then simply press delete once to remove args and the parenthesis. When you have deleted or entered the parameters press tab to begin writing the method.

0 comments | Filed Under: | Tags:

Textmate Footnotes on Edge

Posted by ben, Wed Dec 05 22:38:00 UTC 2007

You may have experienced some issues with textmate footnotes if you are running on edge rails. There are 2 different problems that I have run into.

The first is similar to my earlier post about Haml breaking my footnotes. When you are on a page with the new html.erb extension you don’t get footnotes and that is fixed in similar fashion, by adding the “html.erb” to the list of file extentions in the add_footnotes! method of the file vendor/plugins/footnotes/lib/textmate_footnotes.rb. Mine now looks like .. [“html.erb”, “haml”, “rhtml”, “rxhtml”]

The second is that error pages no longer show a stack trace but rather just a 500 page with no explanation. The reason is that the render_file methods in the file vendor/plugins/footnotes/templates/rescues/template_error.rhtml still point to ”.rhtml” files and edge and 2.0 moved to the new file extension ”.erb” so you need to change both refences to point to ”/_trace.erb” & ”/_request_and_response.erb”

I made a pastie for your convenience with the two diffs to make it easier …

Textmate Footnotes fix for edge rails & 2.0

1 comment | Filed Under: | Tags:

Tip: TextMate Overwrite Mode

Posted by anthony crumley, Sat Nov 24 08:10:00 UTC 2007

Overwrite mode does exactly what it sounds like. It overwrites existing text as you type. When in overwrite mode the caret is an underscore. Option-apple-O toggles overwrite mode on and off.

I don’t use overwrite as much as I should. I find myself using the delete key way to much. Often I will delete a bunch of text then type something in its place when overwrite mode would have eliminated the delete step. Next time you find yourself doing this, try switching to overwrite mode and save your delete key some grief.

0 comments | Filed Under: | Tags:

Tip: TextMate bookmarks

Posted by anthony crumley, Tue Nov 20 06:47:00 UTC 2007

Bookmarking in TextMate is simple and can save a lot of time when you need to jump back and forth between two or more locations in a file. TextMate does not allow you to split an editor window and look at two parts of a file at once. The next best thing is to bookmark and jump back and forth.

To toggle a bookmark simply press apple-F2. F2 moves between bookmarks in forward order. Shift-F2 moves between bookmarks in reverse order.

0 comments | Filed Under: | Tags:

Tip: TextMate selection moving

Posted by anthony crumley, Tue Nov 13 18:52:00 UTC 2007

When text is selected the control-apple-arrow key combinations move the selection in the obvious ways. This is useful for moving one or more selected lines up or down in the file. Also moving a word or clause left or right is often useful. Most other movements have been less than useful for me so far.

0 comments | Filed Under: | Tags:

Tip: TextMate clipboard history

Posted by anthony crumley, Mon Nov 12 08:08:00 UTC 2007

Clipboard history is one of those editor features I often think about when doing complex copy and paste but just never take the time to learn. In TextMate it is pretty easy to use though. All cuts and copies are retained in the history. Of course, apple-V will paste text from the last cut or copy. Control-option-apple-V will show the clipboard history. (Yes, that is the mother of all keyboard combinations. Just press all the weird keys at once and you’ve got it.) Once the history is displayed, previous items can be selected with the arrow keys and pasted by pressing return.

0 comments | Filed Under: | Tags:

Tip: TextMate autopairing

Posted by anthony crumley, Wed Nov 07 06:25:00 UTC 2007

It doesn’t take long to realize that TextMate inserts a closing character when ever you type certain opening characters. For instance, if you type an opening parenthesis it will automatically insert the closing one. What is not obvious is that if you select some text and enter one of the opening characters TexMate will surround that selection with the character pair.

0 comments | Filed Under: | Tags: