Users of Emacs know that it is common to open files on a remote machine to use Trampmode mode, such as the following:
C-x c-f/remotehost:filename RET (or/method:[email protected]:filename)
But, it's a little cumbersome to open, you need to enter username and machine IP, etc.
Emacs provides a client/server pattern when we open an Emacs locally and can execute it as a server
Then, in the other side of the local machine to use Emacs, such as in terminal to call Emacs, just need to use emacsclient to be able.
I hope the situation is this:
1. Consider the local machine's Emacs as a server
2. Log in to a remote machine using SSH
3. Calling the local Emacs server on a remote machine using emacsclient
4. Then we will be able to edit the files on the remote machine on the local machine.
On the internet to find a person to give the solution, link (outside the wall), now the steps to organize such as the following:
Note: Here I remote machine host name: Yoks login Username: Lisp
1. Set port Forwarding (or SSH tunneling), edit the ~/.ssh/config of the machine to add the following
Host yoksuser lispcontrolmaster autocontrolpath ~/.ssh/yoks.sockremoteforward 9999 localhost:9999
The local 9999port and remote 9999port are mapped (map)
2. Configure Emacs for the local machine and add the following code to your Emacs configuration file (. emacs or Init.el)
(setq server-use-tcp t server-port 9999) (Require ' server) (Defun server-start-and-copy () "Start Server and copy Auth Files " (When (and (FBOUNDP ' server-running-p) ; function exists. (Not (SERVER-RUNNING-P))) (Server-start) ; Emacs As Server Mode (when (file-exists-p "/[email protected]:~/.emacs.d/server/server") (delete-file "/[ Email protected]:~/.emacs.d/server/server ")) (copy-file" ~/.emacs.d/server/server ""/[email protected]:~/. Emacs.d/server/server "))) (Add-hook ' Emacs-startup-hook ' server-start-and-copy)
On the one hand, the Emacs server mode is started and its tcpport is set to 9999. Then copy the server file to the remote machine ([email protected])
Restart Emacs on the local machine at the same time
3. Edit the following script on the remote machine with the name EC and increase the operational permissions
#!/bin/bashparams= () for P in "[email protected]"; doif ["$p" = = "-N"]; thenparams+= ("$p") elif ["${p:0:1}" = = "+"]; thenparams+= ("$p") elseparams+= ("/ssh:yoks:" $ (readlink-f $p)) fidoneemacsclient "${params[@]}"
4. Using SSH to log in to the remote machine and then using EC to open a file, we found that the file content is now in the local machine Emacs, such as the following:
Local Emacs such as the following, it is convenient to edit this file on the local machine
Can see its address is:/ssh:yoks:/home/lisp This address and we use tramp mode to open the same.
Note: My machine environment is Linux
Emacs opens remote file using local Emacs server mode