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:

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:

HAML Broke My Textmate Footnotes

Posted by ben, Sat Jul 28 20:19:00 UTC 2007

I recently installed HAML to give it a try and noticed that on HAML pages my Texmate Footnotes weren’t showing up. If you are anything like me you are not quite sure how you made it before the Textmate Footnotes Plugin. That might be a stretch but at least you really like them and wish that they would show up on your HAML pages. I found an easy way to patch the footnotes plugin so that it runs for HAML pages as well.

open /vendor/plugins/footnotes/lib/textmate_footnotes.rb and change out the section in the add_footnotes! method that checks the file types … [“rhtml”, “rxhtml”] ... to include HAML ... [“rhtml”, “rxhtml”, “haml”]

Then restart script/server and you are in business

1 comment | Filed Under: | Tags: