emacs-ess / ESS

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

C-c C-c on script opens R in new frame, but puts script in new frame's bufffer #1012

Closed kingofkung closed 3 years ago

kingofkung commented 4 years ago

Hello, When I attempt to run R, opening it by ess-eval-region-or-function-or-paragraph-and-step VIS on an R script in its own buffer and frame, it creates a second frame and opens R in that frame, as expected by my use of (setq inferior-ess-own-frame t) in .init.el file in .emacs.d However, it then proceeds to return the frame it just opened to run R to the buffer with the r script, and I've included what I saw in the ESS buffer below.

ess-request-a-process: {beginning}
 ... request-a-process:
  major mode ess-mode; current buff: ButCanItSendAnEmail.R; ess-language: S, ess-dialect: R
 ..start-process-specific: lang:dialect= S:R, current-buf=ButCanItSendAnEmail.R

(R): ess-dialect=R, buf=ButCanItSendAnEmail.R, start-arg=nil
 current-prefix-arg=nil
(inf-ess 1): lang=S, dialect=R, tmp-dialect=R, buf=ButCanItSendAnEmail.R
(inf-ess 1.1): procname=R temp-dialect=R, buf-name=*R* 
(inf-ess 2.0) Method #3 start=/Users/bjr/Desktop buf=*R*
(inf-ess 2.1): ess-language=S, ess-dialect=R buf=*R* 
(i-ess 1): buf=*R*, lang=S, comint..echo=t, comint..sender=inferior-ess-input-sender,
(i-ess end): buf=*R*, lang=S, comint..echo=t, comint..sender=inferior-ess-input-sender,
(inf-ess 3.0): prog=R, start-args=--no-readline --no-save  , echoes=t
Making Process...Buf *R*, :Proc R, :Prog R
 :Args= --no-readline --no-save  
Start File=nil
(inferior-ess: waiting for process to start (before hook)
(inferior-ess 3): waiting for process after hookload-ESSR cmd:
local({
                          source('/Applications/Emacs.app/Contents/Resources/etc/ess/ESSR/R/.load.R', local=TRUE) #define load.ESSR
                          load.ESSR('/Applications/Emacs.app/Contents/Resources/etc/ess/ESSR/R')
                      })

(R): inferior-ess-language-start=options(STERM='iESS', str.dendrogram.last="'", editor='emacsclient', show.error.locations=TRUE)
  ... request-a-process: buf=ButCanItSendAnEmail.R
jabranham commented 4 years ago

What version of ESS are you running? If it's from a recentish MELPA, inferior-ess-own-frame is obsolete, you should try something like:

(add-to-list 'display-buffer-alist
             '("*R"
  (display-buffer-reuse-window display-buffer-pop-up-frame)))
kingofkung commented 4 years ago

I am running version 18.10.2, and I replaced inferior-ess-own-frame with what you had above in my .init.el file. The result was the same; running R via C-c C-c on a line of my script buffer opened R in a new frame, but the new frame immediately returned to the buffer with the script.

kingofkung commented 4 years ago

I found this on the site below the quote, and I think it's related.

the erroneous behaviour you describe happens only the first time one types C-c C-z (ess-switch-to-inferior-or-script-buffer) in an ess-r-mode buffer, i.e. before the corresponding inferior R process buffer has been created.

This is because ess-force-buffer-current calls ess-request-a-process with a non-nil noswitch argument when an inferior process does not already exist.

ess-request-a-process, in turn, does the following as its last step:

(if noswitch
(pop-to-buffer (current-buffer)) ;; VS: this is weird, but is necessary
(pop-to-buffer (buffer-name (process-buffer (get-process proc)))))

This call to (pop-to-buffer (current-buffer)) is wrong and is what causes your ess-r-mode buffer to appear a second time in the new frame. It was added in the following commit from 2012: https://github.com/emacs-ess/ESS/commit/b29ea8f934f7c08a512c73f14e914bca7229b3c1

https://emacs.stackexchange.com/questions/55556/ess-display-buffer-alist-reusable-frames-does-not-work-as-expected

jabranham commented 4 years ago

Sounds like this is probably the same as #987 which is solved by #989

lionel- commented 3 years ago

Duplicate of #987.