Is it possible to start emacs using a remote configuration file?
Asked Answered
D

3

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.

Dichromate answered 4/12, 2010 at 6:53 Comment(1)
Also related: load .emacs from urlSouthwesterly
A
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.

Agee answered 4/12, 2010 at 8:32 Comment(1)
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.Docile
M
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.

Merilee answered 25/10, 2012 at 1:25 Comment(0)
A
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.

Agee answered 4/12, 2010 at 8:32 Comment(1)
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.Docile
I
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.

Izanagi answered 4/12, 2010 at 17:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.