Friday, August 8, 2014

Setting up Emacs Tramp on Windows and Cygwin

Working remotely using a Windows PC isn't much fun through plain ssh sessions. Therefore I finally got around setting up Emacs Tramp on Windows.

It should be simple, but I'm making notes here in case I have to do it again.

I started with instructions from David Starks-Browning:

Installation

- Extracted the tramp tar
- copy tramp*/lisp/*.el into /cygdrive/c/path/where/i/extracted/emacs/site-lisp/

Put the following in my ~/.emacs file:
    (require 'tramp)
Figuring out the location of .emacs on a Windows PC was best left to Emacs itself. Since it does expand ~ for home directory, I simply opened the file ~/.emacs in Emacs itself.

Cygwin configuration

I added the Windows emacs into my cygwin path. Simply adding in ~/.bashrc
  export PATH="$PATH:/cygdrive/c/path/where/i/extracted/emacs/bin" 
To get environment right in the Windows emacs, I started emacs from a Cygwin shell instead of the icon:
 bash$ runemacs 

Using Tramp

I always keep forgetting the Tramp path syntax, but it's just a slash and colon
C-x C-f /remotehost:

Troubleshooting

Tramp would hang on opening a file.
- Tried to verify ssh works properly from inside emacs, from M-x shell
M-x shell fails with "invalid argument" message.
- Switched to using M-x eshell
SSH would hang forever on a "pseudo terminal will not be allocated" message.
- ssh remotehost from an emacs shell would start but never enter the remote shell
- ssh -t remotehost would not work for forcing the tty allocation.
- discovered a fakecygpty tool at Emacswiki, which is a shim which makes the ssh believe it is being run interactively.
- From Emacswiki, I added this new ssh method into  ~/.emacs file

(eval-after-load "tramp"
    '(progn
       (add-to-list 'tramp-methods
                    (mapcar
                     (lambda (x)
                       (cond
                        ((equal x "sshx") "cygssh")
                        ((eq (car x) 'tramp-login-program) (list 'tramp-login-program "fakecygpty ssh"))
                        (t x)))
                     (assoc "sshx" tramp-methods)))
       (setq tramp-default-method "cygssh")))
- Set this fakecygpty-ssh method as the default for tramp in  ~/.emacs file
(setq tramp-default-method "sshx")

No comments:

Post a Comment