open-watcom / open-watcom-v2

Open Watcom V2.0 - Source code repository, Wiki, Latest Binary build, Archived builds including all installers for download.
Other
980 stars 159 forks source link

Watcom Vi changes directory to recently opened file #398

Open osen opened 6 years ago

osen commented 6 years ago

Hello,

Even though the original DOS Watcom Vi did this it is a feature that I think would be extremely useful. Perhaps a good addition to one of the options and one that I don't believe would be too difficult to implement if you know your way around the Vi codebase.

Unlike nvi and vim, when you open a new file from within Watcom Vi (i.e src\main.c) it actually changes the current directory to the opened files directory. As a workflow thing this is actually very annoying because if you then do:

:shell > wmake

It won't work because you have been frustratingly placed inside the $PROJDIR/src directory.

At the moment (and for years) I am using a terrible script that searches up directories to the one containing the Makefile and then cds to that ;).

jmalak commented 6 years ago

What behaviour you recommend?

  1. don't change current directory in OW vi editor ?
  2. use vi starting directory for shell ?
osen commented 6 years ago

I believe the first option could be better because that also means in the files list (:f) it keeps the original paths. I believe at the moment when you change directory (i.e via the inbuilt file browser), it resets all these paths to full paths rather than the original relative ones.

(Of course, it should continue changing directory if you explicitly use :cd to do so.)

Edit: I should add, only the inbuilt file browser seems to change the directory when opening files. If just opening files via ":e" then the directory remains the same.

Gavin-Holt commented 2 years ago

Hi,

I think you can control the current directory using the Buffin hook in your ed.cfg:

assign %(Buffinhook) = mod/OnBuffin.vi

My OnBuffin.vi contains:

# Change to directory of opened file
CD %D%P

This keeps the current directory in line with the file in focus, both for the file browser and tab completion at the command line.

Kind Regards Gavin Holt

osen commented 2 years ago

Thank you very much for the tip. I didn't know this was possible; hooks like this aren't really discussed in the manual. 4 years later but I am still oddly compelled to give it a shot!

My OnBuffin.vi would still need to be a bit different because I want to make absolute sure that Watcom Vi never changes directory. I suppose I could search upwards for Makefile or some environment variable. This is definitely a good place to start though :)