emacs-ess / ESS

Emacs Speaks Statistics: ESS
https://ess.r-project.org/
GNU General Public License v3.0
622 stars 162 forks source link

all commands are double-printed #1273

Closed r2evans closed 9 months ago

r2evans commented 9 months ago

Recent update to R-4.3.2 and updating emacs and R packages, now my ESS buffer double-prints everything.

Assuming a simple .R file with a single line 1+1,

### ess-eval-line-visibly-and-step,
> 1+1
1+1
[1] 2

### ess-eval-region,
>
1+1
[1] 2

### Ctrl-U ess-eval-region
> 1+1
1+1
[1] 2

Even just "enter" on the console echoes another line:

### <enter>
>
                                    # <--- empty line
>

Any idea how to figure out what's doing this?

Here's my ESS-related elisp:

~/.emacs.d/init.el ``` '(ess-developer-code-injection-in-packages nil) '(ess-eval-visibly nil) '(ess-history-directory "~/") '(ess-history-file "~/.Rhistory") '(ess-indent-level 2 t) '(ess-indent-offset 2 t) '(ess-indent-with-fancy-comments nil) '(ess-plain-first-buffername nil) '(ess-roxy-str "#'") '(ess-roxy-template-alist '(("description" . ".. content for \\description{} (no empty lines) ..") ("details" . ".. content for \\details{} ..") ("param" . "") ("return" . ""))) '(ess-style 'RStudio) '(ess-swv-processor 'knitr) '(ess-toolbar-global nil) '(inferior-ess-exit-command "q(\"no\") " t) '(inferior-ess-r-program "/opt/R/4.3.2/bin/R") ```
~/.emacs.d/lisp/my-ess.el ``` (defun my-ess-hook () "more stuff to load with ess" (setq ess-indent-level 2 comment-add 0 ess-save-silently t ;; https://github.com/emacs-ess/ESS/pull/1019, https://github.com/emacs-ess/ESS/issues/759 inferior-ess-fix-misaligned-output t) (setq eldoc-idle-delay 2 ; or something >> 1? ess-use-eldoc nil) (local-set-key (kbd "M--") 'ess-cycle-assign) ;; keep me from accidentally KILLING R (again) (define-key ess-extra-map "r" nil) (define-key ess-extra-map "\C-r" nil) (define-key ess-mode-map "\C-c\C-n" 'ess-eval-line-invisibly-and-step) (require 'company) (push (list 'company-R-args 'company-R-objects 'company-R-library :separate) company-backends) (company-mode) ) (defun my-postinit-ess () "my ess init code run after package-initialize" (require 'ess) (require 'ess-site) (setq-default ess-dialect "R" ;; ess-default-style 'RStudio inferior-R-args "--no-save " ;; mostly for Rmd files, since "trailing double spaces" is relevant ess-nuke-trailing-whitespace-p nil ess-ask-for-ess-directory nil) (add-hook 'ess-mode-hook 'my-ess-hook) (add-hook 'inferior-ess-mode-hook 'my-ess-hook) (setq comint-scroll-to-bottom-on-input t comint-scroll-to-bottom-on-output t comint-move-point-for-output nil ;; https://github.com/emacs-ess/ESS/issues/316 ;; ess-r-package-auto-activate nil ) ) (add-hook 'after-init-hook 'my-postinit-ess) ```

ubuntu 22.04.3 (headless, using ssh/tmux)
GNU Emacs 28.1 (build 1, x86_64-pc-linux-gnu) of 2022-05-31
ess-version: 24.01.0 [elpa: 20240122.1720] (loaded from /home/r2/.emacs.d/elpa/ess-20240122.1720/)

On my laptop, this does not happen, .el files

ubuntu 23.10 (Wayland)
GNU Emacs 29.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.38, cairo version 1.17.8) of 2023-09-02, modified by Debian
ess-version: 24.01.0 [elpa: 20240122.1720] (loaded from /home/r2/.emacs.d/elpa/ess-20240122.1720/)
lionel- commented 9 months ago

Does running this in your R session fixes it?

system("stty -echo")

If so that's a deeper system issue.

Edit: Also what does system("stty") return in a fresh ESS/R session?

rsparapa commented 9 months ago

Not happening in my testing. Please try it without ~/.emacs, etc. by emacs --no-init-file and manually load ESS to isolate the issue. Thanks

r2evans commented 9 months ago

Good recommendations. For some reason, system("stty -echo") (after the expression below) was the initial resolution, and I can't find where the change was introduced.

 > system("stty")
 system("stty")
 speed 38400 baud; line = 0;
 erase = <undef>; kill = <undef>;
 -brkint -imaxbel
 -onlcr

It may be something in the tmux/terminal side outside of emacs, because I had restarted emacs (before submitting this issue) and found the same behavior, but now that I've been playing with stty a bunch, the symptom has gone away on restarts.

Thanks all!

r2evans commented 4 months ago

I finally nailed down the culprit: keyring::key_get has a backend_file for storing secrets, and that uses askpass::askpass(..) to retrieve the passphrase used to encrypt the filestore. This function explicitly calls system('stty echo') at the end of the first time a password-protected file-store is accessed.

https://github.com/r-lib/askpass/blob/main/R/askpass.R#L71

It is not emacs/ESS, and I don't know of any awesome way in ESS to try to protect against this happening. I've reached out to those authors in https://github.com/r-lib/askpass/issues/12.

Thanks @lionel- and @rsparapa