Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

emacs

tramp

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.

like image 904
Eric Nguyen Avatar asked Dec 04 '10 06:12

Eric Nguyen


People also ask

Can you use Emacs over SSH?

The Emacs “Tramp” functionality brings the power of SSH into your text editor. You no longer need to open a separate terminal window in order to run scripts, edit files, or perform other server maintenance. Tramp lets you do it all right inside of an Emacs buffer.

How do I access Emacs config?

Emacs will look for a configuration file in each of these locations every time it starts up! This file typically does not exist by default, so you will probably have to create it! We'll use C-x C-f (Ctrl+X then Ctrl+F) to open this file for editing.

Where is the Emacs config file?

Emacs can also look in an XDG-compatible location for init. el , the default is the directory ~/. config/emacs .

What is Emacs tramp?

TRAMP is for transparently accessing remote files from within Emacs. TRAMP enables an easy, convenient, and consistent interface to remote files as if they are local files.


2 Answers

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.

like image 170
spacebat Avatar answered Nov 03 '22 22:11

spacebat


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.

like image 33
slu Avatar answered Nov 04 '22 00:11

slu