2

I'd very much like to log in to a remote machine with ssh and via the $EDITOR environment variable (or something similar) be able to edit in my local Emacs. In this case, specifically for when I log in and run psql and use the \e psql command to edit queries. Being able to edit them in my local Emacs would be a huge bonus in my work flow.

I have a nagging suspicion that there is no way this can be done, but before giving up I thought I'd throw it out here.

3 Answers 3

1

You can actually do this using tramp:

TRAMP stands for `Transparent Remote (file) Access, Multiple Protocol'. This package provides remote file editing, similar to Ange-FTP. The difference is that Ange-FTP uses FTP to transfer files between the local and the remote host, whereas TRAMP uses a combination of rsh and rcp or other work-alike programs, such as ssh/scp.

Add these lines to your ~/.emacs file (source):

(require 'tramp)
(setq tramp-default-method "scp")

You should then be able to open the remote file like this:

emacs /remote.server.com:/remote/path/foo.txt

Specifically for use with the psql command you would need something different though. Don't have a way of testing this now but perhaps setting emacs as an alias to your local emacs might work. Add this line to your remote .bashrc file:

alias emacs='ssh user@local emacs'
2
  • This is true stuff, but I don't think it accomplishes quite what this guy is looking for. How would this get instantiated from the remote shell? Commented May 6, 2013 at 13:53
  • @Caleb well, ah, point, not sure how to configure this for use with \e psql. See updated answer. Commented May 6, 2013 at 14:01
1

I'm not familiarized with emacs or psql. But...

Looks like you can use sshfs to mount your remote server and execute everything locally:

sshfs user@host mount/directory/
cd mount/directory && emacs

If you need run commands in the remote machine, you can mount with sshfs, then access with ssh then use ssh escape characters to suspend the ssh session and run emacs in your machine (editing the remote files mounted with sshfs).

Another solution would be install emacs in the remote machine and copy your configuration (I chose this solution aggregated in a git repo for my vim stuff)

-1

This can't be done as you have described it. You could use SFTP (possibly through FUSE) to edit files on the remote system. It might be possible to do something really creative with scripts and piping, but it's not built-in functionality.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.