Reputation: 725
My setup:
emacs -nw
) ansi-term
)Suppose I'm browsing the remote server inside the shell and find a file I want to edit. Is there a command to open it as a parallel buffer/window?
The only method I know to open a file from the shell is to do emacs -nw
again, which isn't quite convenient because a) I don't keep the shell open and b) it's really a different Emacs session, so for instance the "yank buffer" is different.
Edit: if there is a different/better way to work with a remote server with Emacs I'm just as interested; it's what I'm trying to do.
Upvotes: 3
Views: 2702
Reputation: 20342
It's best to use tramp.
I have this shortcut (I call it with smex
):
(defun connect-remote ()
(interactive)
(dired "/[email protected]:/"))
This opens a dired buffer on the remote. You just use it as any dired buffer.
I've had a function to open a term from dired for a while, but I've added an option to ssh from a tramp dired buffer just now:
(defun dired-open-term ()
"Open an `ansi-term' that corresponds to current directory."
(interactive)
(let ((current-dir (dired-current-directory)))
(term-send-string
(terminal)
(if (file-remote-p current-dir)
(let ((v (tramp-dissect-file-name current-dir t)))
(format "ssh %s@%s\n"
(aref v 1) (aref v 2)))
(format "cd '%s'\n" current-dir)))))
(defun terminal ()
"Switch to terminal. Launch if nonexistent."
(interactive)
(if (get-buffer "*terminal*")
(switch-to-buffer "*terminal*")
(term "/bin/bash")))
And this is the shortcut that I use:
(define-key dired-mode-map (kbd "`") 'dired-open-term)
Upvotes: 6
Reputation: 9380
You could use tramp from within your original emacs session to browse the remote server via ssh, using dired. Then, any remote file you open is opened in your local emacs session.
If you prefer to avoid dired and want to browse with a shell, you can prepend the remote location (/name@host:/path/from/pwd) to the file name. You can automate that with a function.
Upvotes: 2