These days, I've been used to a very specific $EDITOR usage. I use my (Xfce) workspaces as context switch. Basically, each time I need to start a new “activity” I open a new workspace, open some terminals, maybe a browser, an editor (gvim) window etc. Then when I'm done, I delete that workspace.
I can have multiple activities at once, and switch from one to another depending on various stuff. On those workspaces, I'd like to be able to have only one editor window, even when I open new files using “gvim foo.c”. But I'd like to have one editor window per workspace, not one global editor, since I'd like the editor to be context-specific too.
I recently heard about the gvim remote stuff, and I've came with the following gvim function (zsh syntax):
function gvim() {
desktop=$(xprop -root -notype -f _NET_CURRENT_DESKTOP 0c '$0+\n'
_NET_CURRENT_DESKTOP)
if [ "$#" -ge "1" ];
then
gvimargs="--remote-tab-silent"
fi
=gvim --servername $desktop $gvimargs $*
}
The xprop trick is a hackish way to stick one gvim window per workspace, it might need to be adjusted if one has a two monitors setup and want to be able to have one editor per monitor per workspace.
Basically, that snippet checks if a gvim server already exists with the current workspace name. If yes, it opens the file(s) in it, if not it run a new gvim server and opens the file there.
It works more or less fine, but it has one problem: it fails badly when one needs to give args to the gvim call. Those args are usually placed *before* filenames, so in my case it won't work. One way to fix this would be to loop on all the args, check if the arg is an existing file, in case add it to $files. If not, add it to $args, then call gvim with the correct order. Works, except when you want to edit a new file, where you're back to point one.
All in all, it'd work, but it's not really a nice way to do it, imho. So I'm calling for help, in case anyone has an idea about that. Basically, is there a way to say to gvim “always open files in a remote server, run it if it's not already running” using the config file and not an argument (so I don't mess with the command line). I do need the servername to be desktop specific though, so it's still a difficulty.
NOTE: I know that emacs has some kind of remote server habilities too, but I'm not sure how it works and if it'd be possible to do that in emacs, and I'm not really an emacs user and don't really intend to switch.
If you have any idea, feel free to comment (by mail), I might do a later post when I have an enhanced solution.