From gavin@refinery.com Fri Mar 3 16:20:56 2006 From: Gavin Kistner To: textmate@lists.macromates.com Subject: [TxMt] Specifying a 'funky' file path Date: Fri, 03 Mar 2006 09:18:39 -0700 Message-ID: <1C49A74A-FCF5-46BF-88D6-1699DFA9B455@refinery.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============4943975384544679321==" --===============4943975384544679321== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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: DON'T WORK: 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: and it works. Yay! :) --===============4943975384544679321==-- From throw-away-1@macromates.com Fri Mar 3 17:01:41 2006 From: Allan Odgaard To: textmate@lists.macromates.com Subject: Re: [TxMt] Specifying a 'funky' file path Date: Fri, 03 Mar 2006 17:59:16 +0100 Message-ID: <494FD5D1-38D3-4F97-89C2-32FDA6B760DC@macromates.com> In-Reply-To: <1C49A74A-FCF5-46BF-88D6-1699DFA9B455@refinery.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2246986266107927236==" --===============2246986266107927236== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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 :) --===============2246986266107927236==-- From duane.johnson@gmail.com Fri Mar 3 20:27:23 2006 From: Duane Johnson To: textmate@lists.macromates.com Subject: [TxMt] Shared Ruby methods for TextMate module Date: Fri, 03 Mar 2006 13:23:52 -0700 Message-ID: In-Reply-To: <494FD5D1-38D3-4F97-89C2-32FDA6B760DC@macromates.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============3549304286637059288==" --===============3549304286637059288== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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/ --===============3549304286637059288==--