I am (almost done) writing an HTML output script for my Lua bundle which (among other things) provides TextMate links for syntax error codes.
I put one of my files in a path with a space in the name, and it took me a fair amount of experimenting to figure out how TextMate and Lua independently wanted to see the URL.
The raw path as supplied in the argument list is: /Users/gavinkistner/Desktop/pork butt/bling/tmp.lua
To pass that to Lua, I needed to escape the space char: file_path = Pathname.new( ARGV[0].gsub( %r{([^\w/.])}, '\\\1' ) ) #=> /Users/gavinkistner/Desktop/pork\ butt/bling/tmp.lua
To create the parameter for the TextMate URL, I needed to NOT have that escaping. If I perform HTML escaping (for valid HTML) the space may not be represented as a '+' char, but must be a %20.
WORK: <a href='txmt://open?url=file:///Users/gavinkistner/Desktop/pork butt/ orxit.lua&line=6'> <a href='txmt://open?url=file%3A%2F%2F%2FUsers%2Fgavinkistner% 2FDesktop%2Fpork%20butt%2Forxit.lua&line=6'>
DON'T WORK: <a href='txmt://open?url=file:///Users/gavinkistner/Desktop/pork\ butt/orxit.lua&line=6'> <a href='txmt://open?url=file%3A%2F%2F%2FUsers%2Fgavinkistner% 2FDesktop%2Fpork+butt%2Forxit.lua&line=6'>
The Ruby code to create the valid URL param: htmlpath = CGI.escape( "file://" + File.expand_path( path+file, file_dir ).gsub( /\(.)/, '\1' ) ).gsub('+','%20')
As a more pathological case, I renamed the folder in Finder to "pork \ % / butt" The "/" in the name is apparently a ":" on the file system: gavinkistner$ cd pork\ \\ %\ :\ butt/ gavinkistner$ pwd /Users/gavinkistner/Desktop/pork \ % : butt
My code produces: <a href='txmt://open?url=file%3A%2F%2F%2FUsers%2Fgavinkistner% 2FDesktop%2Fpork%20%5C%20%25%20%3A%20butt%2Forxit.lua&line=6'> and it works. Yay! :)
On 3/3/2006, at 17:18, Gavin Kistner wrote:
[...] I put one of my files in a path with a space in the name, and it took me a fair amount of experimenting to figure out how TextMate and Lua independently wanted to see the URL.
I have this function in the Show TODO List command:
def TextMate.file_link (file, line = 0) return "txmt://open/?url=file://" + file.gsub(/[^a-zA-Z0-9.-/]/) { |m| sprintf("%%%02X", m[0]) } + "&line=" + line.to_s end
I will move it to the textmate ruby lib in Support/lib so that Ruby commands can just use this one.
To pass that to Lua, I needed to escape the space char: file_path = Pathname.new( ARGV[0].gsub( %r{([^\w/.])}, '\\\1' ) ) #=> /Users/gavinkistner/Desktop/pork\ butt/bling/tmp.lua
I assume that “pass that to Lua” means through the shell? There are also a few shell_escape functions in various commands, where instead I should harmonize and (again) move to the textmate ruby lib :)
On Mar 3, 2006, at 9:59 AM, Allan Odgaard wrote:
On 3/3/2006, at 17:18, Gavin Kistner wrote:
[...] I put one of my files in a path with a space in the name, and it took me a fair amount of experimenting to figure out how TextMate and Lua independently wanted to see the URL.
I have this function in the Show TODO List command:
def TextMate.file_link (file, line = 0) return "txmt://open/?url=file://" + file.gsub(/[^a-zA-Z0-9.-/]/) { |m| sprintf("%%%02X", m[0]) } + "&line=" + line.to_s end
I will move it to the textmate ruby lib in Support/lib so that Ruby commands can just use this one.
Do you mind if I add TextMate.open (currently in the Rails.tmbundle/ Support/lib/rails/text_mate.rb file) as well as TextMate.open_url to the shared TextMate module? There may be some other methods in there that you'd like moved in to the shared Support/lib also.
Duane Johnson (canadaduane) http://blog.inquirylabs.com/