7

I have different work-specific .emacs configuration files on servers where I do work for various companies. These are packages that, for various reasons, I don't want to store locally on my machine. Is there any way to start up emacs using one of those remote directories as if it were local?

Tramp is great for actually editing remote files as if they were local -- now I'd like to be able to start up a whole emacs editor in the same way.

Eric Nguyen
  • 40,312
  • 4
  • 25
  • 31
  • Also related: [load .emacs from url](http://stackoverflow.com/questions/9988540/load-emacs-from-url/9988910) – phils Oct 25 '12 at 02:01

3 Answers3

7

Out of curiosity I just gave this a go:

emacs -q --load "/ssh:USER@HOSTNAME:.emacs.d/init.el"

That worked, however the remote init.el is setting load paths like "~/.emacs.d/vendor/", so really an init file needs to be aware that the paths and filenames it sets need to be relative to a common base. This base could be set by a common variable, so try:

emacs -q --eval '(setq init-base "/ssh:USER@HOSTNAME:") (load (concat init-base ".emacs.d/init.el"))'

Then in the remote config, prepend init-base to any path or filename it sets that should be remote.

spacebat
  • 196
  • 3
  • 4
4

start up emacs using one of those remote directories as if it were local

If the servers are unix/linux servers and you have ssh access, then you could try SSH Filesystem. Then you can mount the servers to local directories, e.g.:

> sshfs server1: ~/remote/server1 
> sshfs server2: ~/remote/server2

Then you could start emacs with emacs --no-init-file --load ~/remote/servers2/.emacs and so on.

packages that, for various reasons, I don't want to store locally

If packages are installed in .emacs.d on the remote machines you could create scripts like the following on your local machine:

;; .emacs.server1.el
(add-to-list 'load-path (expand-file-name "~/remote/server1/.emacs.d"))
(add-to-list 'load-path (expand-file-name "~/remote/server1/.emacs.d/package1"))
(load (expand-file-name "~/remote/server1/.emacs"))

And then start emacs like this: emacs --no-init-file --load ~/.emacs.server1.el

Obvious this script depends on the mounts above.

slu
  • 1,244
  • 9
  • 14
  • You can extend this approach by just using sshfs to mount the appropriate remote .emacs.d directory at .emacs.d on the local machine, e.g. sshfs server1:.emacs.d ~/.emacs.d -- this obviates the need to pass the arguments slu mentioned above. To use local init files, unmount any sshfs filesystem from ~/.emacs.d and do ln -s ~/.emacs.d.local ~/.emacs.d. Lastly, by using .emacs.d/init.el instead of ~/.emacs you can have machine-specific init files as well. – jlf Dec 04 '10 at 16:33
2

You may find the SO question Originate edit of remote file using emacs tramp from ssh session is asking for a solution to a related problem. Perhaps the answers there might give you what you want, namely, you can attach to an emacs running on the remote machine.

Community
  • 1
  • 1
Trey Jackson
  • 73,529
  • 11
  • 197
  • 229