tramp-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tramp mosh method


From: Michael Albinus
Subject: Re: Tramp mosh method
Date: Fri, 21 Dec 2012 13:58:00 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Ted Zlatanov <address@hidden> writes:

Hi Ted,

> Unfortunately it didn't work for me, from Ubuntu to CentOS or from
> Ubuntu to localhost.  The debug buffer shows nothing is received after
> "exec mosh MACHINENAME", and the proces filter is never invoked (I
> checked in *Messages*; see the stub `tramp-mosh-process-filter').

There were some subtle errors in your code; see appended patch. I have a
running process filter.

> MA> I also needed to set "LC_ALL" to "C.UTF-8"; mosh requires that.
>
> That locale is not available on many systems, e.g. CentOS.  My patch
> explicitly adds `(setenv "LC_ALL" "en_US.UTF-8")' but I think it's
> better to set that in the method parameters because only mosh needs it.
> I hope you agree.

Yep.

> I am attaching an updated version of the mosh patch against trunk Emacs.
> Sorry I haven't converted to the Tramp Git repository yet...  If you
> think using the Tramp Git repo is essential, I'll rebase my patch and
> retry.

Nope, a patch towards Emacs trunk is sufficient.

> +;;;###tramp-autoload
> +(defconst tramp-mosh-method "mosh"
> +  "When this method name is used, forward all calls to mosh.")

[...]

> +;; It must be a `defsubst' in order to push the whole code into
> +;; tramp-loaddefs.el.  Otherwise, there would be recursive autoloading.
> +;;;###tramp-autoload
> +(defsubst tramp-mosh-file-name-p (filename)
> +  "Check if it's a filename that should be handled with mosh."
> +  (string= (tramp-file-name-method (tramp-dissect-file-name filename))
> +           tramp-mosh-method))
> +
> +;;;###tramp-autoload
> +(add-to-list 'tramp-foreign-file-name-handler-alist
> +             (cons 'tramp-mosh-file-name-p 'tramp-sh-file-name-handler))

As I have shown the other message, this is not needed.

> === modified file 'lisp/net/tramp.el'
> --- lisp/net/tramp.el 2012-12-18 13:37:06 +0000
> +++ lisp/net/tramp.el 2012-12-21 10:13:47 +0000
> @@ -3100,7 +3100,25 @@
>         (setq mode-line-process '(":%s"))
>         (shell-mode)
>         (set-process-sentinel p 'shell-command-sentinel)
> -       (set-process-filter p 'comint-output-filter))
> +
> +       ;; maybe set the process filter to tramp-process-filter
> +       ;; (wrapped in a check to ensure we don't overwrite an
> +       ;; existing output filter)
> +       (with-current-buffer output-buffer
> +         (unless (process-filter (current-buffer))
> +           (let ((filter
> +                  (tramp-get-method-parameter
> +                   (tramp-file-name-method
> +                    (tramp-dissect-file-name default-directory))
> +                   'tramp-process-filter)))
> +             (when filter
> +               (set-process-filter p filter)))))
> +
> +       ;; maybe set the process filter to comint-output-filter
> +       ;; (wrapped in a check to ensure we don't overwrite an
> +       ;; existing output filter)
> +       (unless (process-filter (current-buffer))
> +         (set-process-filter p 'comint-output-filter)))
>  
>        (prog1
>         ;; Run the process.

This is the wrong place to add the filter. See my appended patch.

> Thanks
> Ted

Best regards, Michael.

--8<---------------cut here---------------start------------->8---
~/src/emacs/lisp/net> bzr diff tramp-sh.el tramp.el
=== modified file 'lisp/net/tramp-sh.el'
--- lisp/net/tramp-sh.el        2012-12-19 13:01:16 +0000
+++ lisp/net/tramp-sh.el        2012-12-21 12:49:46 +0000
@@ -406,6 +406,21 @@
     (tramp-copy-program         "fcp")
     (tramp-copy-args            (("-p" "%k")))
     (tramp-copy-keep-date       t)))
+;;;###tramp-autoload
+(add-to-list 'tramp-methods
+  '("mosh"
+    (tramp-login-program        "mosh")
+    (tramp-login-args           (("-p" "%p") ("%h")))
+    (tramp-remote-shell         "/bin/sh")
+    (tramp-remote-shell-args    ("-c"))
+    (tramp-copy-keep-date       t)
+    (tramp-copy-recursive       t)
+    (tramp-gw-args              (("-o" "GlobalKnownHostsFile=/dev/null")
+                                 ("-o" "UserKnownHostsFile=/dev/null")
+                                 ("-o" "StrictHostKeyChecking=no")))
+    (tramp-process-precommands ("stty rows 25" "stty cols 80"))
+    (tramp-process-filter       tramp-mosh-process-filter)
+    (tramp-default-port         22)))
 
 ;;;###tramp-autoload
 (add-to-list 'tramp-default-method-alist
@@ -4392,7 +4407,8 @@
              (when (and p (processp p))
                (delete-process p))
              (setenv "TERM" tramp-terminal-type)
-             (setenv "LC_ALL" "C")
+             (setenv "LC_ALL" "C.UTF-8")
+             (setenv "LC_ALL" "en_US.UTF-8")
              (setenv "PROMPT_COMMAND")
              (setenv "PS1" tramp-initial-end-of-output)
              (let* ((target-alist (tramp-compute-multi-hops vec))
@@ -4420,6 +4436,13 @@
                      (cons (butlast (append vec nil)) (current-time))
                      tramp-current-host (system-name))
 
+               ;; Set the process filter.
+               (let ((filter
+                      (tramp-get-method-parameter
+                       (tramp-file-name-method vec) 'tramp-process-filter)))
+                 (when filter
+                   (set-process-filter p filter)))
+
                (tramp-message
                 vec 6 "%s" (mapconcat 'identity (process-command p) " "))
 
@@ -4428,6 +4451,11 @@
                 p 60
                 "Couldn't find local shell prompt %s" tramp-encoding-shell)
 
+                (dolist (command (tramp-get-method-parameter
+                                   (tramp-file-name-method vec)
+                                   'tramp-process-precommands))
+                  (tramp-send-command vec command t t))
+
                ;; Now do all the connections as specified.
                (while target-alist
                  (let* ((hop (car target-alist))
@@ -5159,6 +5187,11 @@
         (t
          (format "%s <%%s" coding)))))))
 
+(defun tramp-mosh-process-filter (proc string)
+  (with-current-buffer (process-buffer proc)
+    (tramp-message proc 10 "\n%s" string)
+    (insert string)))
+
 ;;; Integration of eshell.el:
 
 (eval-when-compile

=== modified file 'lisp/net/tramp.el'
--- lisp/net/tramp.el   2012-12-18 13:37:06 +0000
+++ lisp/net/tramp.el   2012-12-21 12:13:41 +0000
@@ -3100,7 +3100,12 @@
          (setq mode-line-process '(":%s"))
          (shell-mode)
          (set-process-sentinel p 'shell-command-sentinel)
-         (set-process-filter p 'comint-output-filter))
+
+         ;; Maybe set the process filter to `comint-output-filter'
+         ;; (wrapped in a check to ensure we don't overwrite an
+         ;; existing output filter).
+         (unless (process-filter p)
+           (set-process-filter p 'comint-output-filter)))
 
       (prog1
          ;; Run the process.

--8<---------------cut here---------------end--------------->8---



reply via email to

[Prev in Thread] Current Thread [Next in Thread]