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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With