CommonThread

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

Filed Under: | Tags:

Comments

Have your say

A name is required. You may use HTML in your comments.




Categories