Wednesday, July 2, 2008

Loving aquamacs

Hi ! 8 months ago I was looking for the definitive text editor since I had just bought my new Macbook Pro... it was an intense research: I've always used Vim fluently (although not many plugins), Emacs quite a bit, and then I bought TextMate... it was nice but all my experience and pooled knowledge on Emacs would go through the sink.
But then I discovered Aquamacs Emacs... I must tell: It is excellent.

I was afraid it would be one of those marginal projects that start and only get some love once a year or so, but I was wrong: they've released two new versions (1.3 and 1.4) since I started using it, each new version Much better than the previous one.

Now I've been programming Rails, and I missed that feature of footnotes plugin that let you directly open some file that has thrown an exception by clicking on an txmt:// link on the page.

Ive been trying to create an emacsclient URL protocol handler with python and registering it to the operating system so that eny emc:// URL would be opened by EmacsCLlient (and thus AquamacsEmacs) but this way has been quite painful and at last I've found a much simpler solution:

create this AppleScript:
property eclient : "/opt/local/bin/emacsclient -n "
property eclientexec : "/opt/local/bin/emacsclient -e \"(goto-line "
property eopen : "/usr/bin/open -a /Applications/Aquamacs\\ "
(* copied from *)
to split(needle, haystack)
set oTIDs to the text item delimiters
set the text item delimiters to needle
set hay to (text items of haystack)
set the text item delimiters to oTIDs
return hay
end split
(*set t to "I really like pie"
set commentString to item 1 of split({""}, t))
returns "I really like pie" *)

on open location this_URL
set the my_URL to text 7 thru -1 of this_URL
set the my_FILE to item 1 of split({"&"}, my_URL)
set the my_LINE to item 2 of split({"="}, my_URL)
do shell script eclient & my_FILE
do shell script eclientexec & my_LINE & ")\""
(*display dialog my_FILE*)
end open location

compile it and make an application, then on firefox you just click on an emc:// link and it asks you what application to use, go and find your recently created appplescript App, and Tachan !!

I use 3, but I think it should work on 2, if it doesn't you'll need to register a protocol handler on your Mac for emc:// URLS, that is done by adding this:
(this should be XML but I've seen that blogger removes the xml tags, so indentation stands for the XML tags, quoted strings are the element contents, but when you create the XML you should *remove the quotes* !)
"EmacsClient URL"/

to the Info.plist

Then on the footnotes Rails plugin, change vendor/plugin/footnotes/init.rb

Footnotes::Filter.prefix ||= 'txmt://' if RUBY_PLATFORM.include?('darwin')

to be

Footnotes::Filter.prefix ||= 'emc://' if RUBY_PLATFORM.include?('darwin')

that should be all !

please if you've read this and found it interesting, leave a commend saying Yes ! !
so I will consider to continue posting my little mac-emacs-ruby-whatever tweaks or not..


No comments: