[ESS] Double prompt using ess-remote through ssh on Windows

Erik Iverson eriki at ccbr.umn.edu
Mon Apr 18 21:08:03 CEST 2011

Hello -

I am just coming into this thread, and I only really saw the keyword 
"double prompt".  I seem to recall I had some success of fixing this by 
issuing an stty command of some type upon logging into the Linux machine.

Something like

% stty -nl

rings a bell?

The ESS manual has:

% stty -echo nl

You might try variations of the above to see if it helps you avoid the 
double prompt without any emacs hacking.

Keith Ponting wrote:
> Vincent Goulet <vincent.goulet <at> act.ulaval.ca> writes:
>> Hi all,
>> Charles C. Berry brought this issue to my attention. Using
>> 1. my GNU Emacs 22.2-modified-1 for Windows distribution (but  
>> presumably earlier versions also);
> ... 
>> Any idea how to fix this?
> I cannot find any more recent update to this and was still getting the double
> prompts. These occur both in the started shell and in R. A bit of hunting showed
> that the ssh link somehow appears to be sending _two_ new lines for every
> command issued. One irritating side effect is that using devAskNewPage is also
> disturbed - you tend to see every other plot! 
> For my setup (Windows Vista, Vincent's very useful modified Emacs 23.2.1, ESS
> version 5.10 remote host running Linux and R 2.8.1) I think I may have found a
> fix, with the following in my .emacs. The key is replacing \n with \r in the
> comint-simple-send function (just deleting \n does not work):
> (load "~/.emacs.d/ssh")
> (setq ssh-program "plink")
> ;; ssh-explicit-args also set to -X (via customize) to enable X forwarding to 
> ;; Xming, which I start with:
> ;; "C:\Program Files (x86)\Xming\Xming.exe" :0 -clipboard -multiwindow
> (defun my-comint-init ()
>            (setq comint-process-echoes t) ; suppresses extra echo of R commands
>            ;; following does not fix double prompt but might be useful
>            (setq comint-prompt-regexp "^[^#$%>\n]*[#$%>] *") 
>            (setq comint-use-prompt-regexp t)
>            (setq comint-input-sender (function my-comint-simple-send))
>            ;; (setq comint-input-sender-no-newline t) ; seems to have no effect
>            )
> (add-hook 'comint-mode-hook 'my-comint-init)
> (defun my-comint-simple-send (proc string)
>   "Default function for sending to PROC input STRING.
> This just sends STRING plus a newline.  To override this,
> set the hook `comint-input-sender'."
>   (let ((send-string
>          (if comint-input-sender-no-newline
>              string
>            ;; Sending as two separate strings does not work
>            ;; on Windows, so concat the \n before sending.
>            (concat string "\r")))) ; KMP - was \n
>     ;;(message (concat "Sending /" string "/ send-string /" send-string "/" ))
>     (comint-send-string proc send-string))
>   (if (and comint-input-sender-no-newline
> 	   (not (string-equal string "")))
>       (process-send-eof)))
> That fixes direct interactions in the *ssh... buffer, but it does not help when
> using ESS to send commands from an R buffer. In order to fix that, I had to
> modify ess-eval-linewise, replacing:
>               (setq com (concat (substring text 0 pos) "\n"))
> with the following:
>               ;; horrible kludge for windows-to-linux ssh operation
>               ;; using \r instead of \n suppresses double prompts,
>               ;; but also have to force invisibly to stop something in ESS
>               ;; echoing commands.
>               (if (string-match-p "^\*ssh-" (process-name sprocess))
>                   (progn (setq com (concat (substring text 0 pos) "\r"))
>                          (setq invisibly t))
>                   (setq com (concat (substring text 0 pos) "\n")))
> So far, that has appeared to work for whichever combination and ordering of
> remote and local R sessions I have tried.
> There is one exception - when sending a region invisibly, the double carriage
> return behaviour re-appears, with an extra line doubled for luck (i.e. sending a
> region of two lines gives six empty prompts!). Examining the code, that case
> feeds almost directly into process-send-region, which is a 'C' level Emacs
> function and beyond what I can currently tackle.
> HTH,
> Keith Ponting
> Aurix Ltd. Malvern, Worcestershire, UK
> ______________________________________________
> ESS-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help

More information about the ESS-help mailing list