cuspymd / tramp-term.el

Provides a quick way to create an ansi-term containing an ssh session with remote directory tracking already configured.
43 stars 12 forks source link

Is it possible to have automatically opened files use the local version of Emacs? #5

Open computersarecool opened 7 years ago

computersarecool commented 7 years ago

Hi,

This may be reaching but I use Emacs a lot from my local computer to configure remote servers, and tramp-term helps a lot with that.

However, I have noticed that any time the default VISUAL or EDITOR command is invoked on my remote server, it opens whatever the default editor is on the remote machine. This leads to the undesirable (for me) situation where Emacs can be opened on the remote machine, within my local Emacs.

My key commands get confused and go to the wrong terminal. This is really a question, not an issue, as the logic makes sense but I am wondering:

Do you have a workaround for this?

randymorris commented 7 years ago

Unfortunately I do not have a solution for this. Every now and then I try to find a solution but I almost always immediately walk away once I realize again that $VISUAL and $EDITOR are expected to be binaries on the remote machine as opposed to a shell function. I really don't want to have to ship up a separate binary or rely on one already being installed and configured on the remote machine for this to work.

If you're able to come up with a solution that doesn't require a separate binary I'd love to see.

computersarecool commented 7 years ago

Yes, I am looking at with-editor but so far I have not been able to get it to work for me.

greened commented 5 years ago

It's possible to use emacsclient to connect from the remote machine to open in the local emacs. You then set VISUAL and EDITOR to emacsclient.

bdk0 commented 3 years ago

If anyone else ends up here looking for this, I was able to get this working with the following configuration:

In ~/.emacs.d/init.el add the following:

(setq server-use-tcp t
      server-port    9999)
(server-start)
(defun my-tramp-term--emacsclient-hook (host)
  (term-send-raw-string (concat "alias emacsclient='emacsclient --tramp /ssh:" host ":'" (kbd "RET")))
  (term-send-raw-string (concat "mkdir -p ~/.emacs.d/server/ ; clear" (kbd "RET")))
  (copy-file "~/.emacs.d/server/server" (concat "/ssh:" host ":.emacs.d/server/server") t)
  )

(add-hook 'tramp-term-after-initialized-hook 'my-tramp-term--emacsclient-hook)

In ~/.ssh/config Add the following for all hosts that you want to be able to use remote editing from

 RemoteForward 9999 localhost:9999

Then When you log in to one of these remote servers inside tramp-term you can use emacsclient on the remote to open a file locally.

Caveats

Inspired by This Solution, though modified to create and use an alias instead of needing a bash script on the remote and altered to work with tramp-term.