[TxMt] Open command

Chuck Esterbrook chuck.esterbrook at gmail.com
Sat Jun 16 19:58:39 UTC 2007


Cliff,

I appreciate the thorough response, but I don't think it's on the
mark. See below:

On 6/12/07, Cliff Pruitt <lists.cpruitt at cliffpruitt.com> wrote:
...
> As I understand it, the mate command line tool is not at all the same
> as the TextMate application (its just a little helper utility), so it
> would not (and really should not) have any bearing on the stored path
> for opening new folders. ...

Oh, I don't think it should. This was just one particular way to get
in that situation. I'm simply asking that ⌘O start in the directory of
the current file (if there is one and it has a valid directory).

I can't see any harm caused by this and I can see a lot of good.

Consider this other case: I'm in a project and when I open I see that
project directory. Then I hit ⌘` to switch to another TextMate window.
Now I hit ⌘O and I'm still seeing the completely unrelated file system
directory from that other project! How can that be useful/good?

> In its current incarnation text mate expects that you're doing things
> in a somewhat standard way.  If you're in the terminal dinking around
> then you've probably cd'd to the directory you're working in.  If
> you've opened foo & bar & realize you need baz, just cmd+tab back to
> terminal & 'mate baz'.  If you're the kind of person that uses the
> open command a lot, TM assumes you're probably still working on
> whatever you last opened from the open dialog.

Hey now, nothing non-standard about Terminal. It's been around since
'89 NeXTstep! "Terminal for life."  :-)

Btw I actually consider opening from the current file's directory to
be the norm. And also the norm: Home going to the beginning of the
text instead of column 1 where all my uninteresting whitespace is. But
then "standard behavior" is a funny thing because it really varies
based on who you ask and what apps you use.

> What is TM going to show me if I'm working on a new document that
> hasn't been saved yet?  What about something I'm editing using the
> "Edit in Text Mate" command?  What will it show me if nothing is
> opened?  Why would it think I've changed what I'm working on just

That answer is *easy*: If there is no current file or the current file
has no valid path, then ⌘O would not change the directory. Isn't this
like two lines of code?

    if ([self curDoc]!=null && [[self curDoc] hasValidDirectory])
        [openDialog setDirectory:[[self curDoc] directory]];

(Hope my Obj-C is not *too* rusty; been awhile.) Okay, so a few more
lines for -hasValidDirectory and anything I might have forgotten.

> because I've un-minimized some 30 minute old readme file from the
> dock that I've since moved into the trash but its still open in TM?

It wouldn't kill you if ⌘O put you in the directory with the README
(or did nothing if the whole directory was gone). You were probably
about to open INSTALL or LICENSE anyway. If not, you probably hit ⌘W
or ⌘` first. The current file's directory is simply a better guess
than "last directory".

> The point is, I can see where you're coming from but I think TM's
> behavior is correct for most people, most of the time.

I don't see how it could be. If you ⌘` to another window, work for 45
minutes and then hit ⌘O, are you really thinking this: "I want to be
in the directory of that last window I was working on 45 minutes ago."
 Very slim chance.

> There are
> always exceptions and sometimes some people tend to be more of an
> exception that a rule, but it's not a problem with the app's command
> itself, its just that it doesn't match your workflow.

I agree that type of situation comes up, but I don't think that's the
case here (due to my reasons above).

> But honestly, if you want a solution, why not just do this:
> Create a new bundle command and give it whatever tab trigger/shortcut/
> scope you want and put this into it:
>
> #------------------------------
> osascript <<-APPLESCRIPT
>         set TMVar to "${TM_FILEPATH}"
>         tell application "System Events"
>                 set openLocation to alias TMVar
>                 set filePath to POSIX path of ((choose file default location
> openLocation) as alias)
>                 do shell script "mate " & quoted form of filePath
>         end tell
> APPLESCRIPT
> #------------------------------
>
> That command will open a standard open dialog that defaults to your
> current file's path.  It could probably be streamilned & shortened
> even but I kind of slapped it together.  Anyway, it should give you
> what you need.

Hey, that's pretty cool and pretty thoughtful. I'll check it out.

-Chuck


More information about the textmate mailing list