Skip to content

Commit 3fa923b

Browse files
authored
Return inferior buffer from runners (#884)
* Return inferior buffer from runners * Set buffer explicitly in roxy test
1 parent d73f51d commit 3fa923b

File tree

10 files changed

+130
-120
lines changed

10 files changed

+130
-120
lines changed

doc/newfeat.texi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
Changes and New Features in 19.04 (unreleased):
55
@itemize @bullet
66

7+
@item iESS: Process runners now return the inferior buffer.
8+
Note that callers of inferior runners should not assume that the current
9+
buffer has been set to the inferior buffer. Instead, use
10+
@code{with-current-buffer} with the return value of the inferior.
11+
12+
@item iESS[SAS]: The SAS keymap was only set in iESS buffers
13+
called `*SAS*`. This is now fixed.
14+
715
@item ESS[R]: Fixed longstanding indentation issues involving
816
@code{::} and @code{:::} operators.
917

lisp/ess-gretl.el

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,18 +553,18 @@ to gretl, put them in the variable `inferior-gretl-args'."
553553
(concat "Starting Args [other than `"
554554
inferior-gretl-args
555555
"'] ? "))
556-
nil))))
557-
(inferior-ess r-start-args)
556+
nil)))
557+
(inf-buf (inferior-ess r-start-args)))
558558
(set (make-local-variable 'indent-line-function) 'gretl-indent-line)
559559
(set (make-local-variable 'gretl-basic-offset) 4)
560560
(setq indent-tabs-mode nil)
561561
(goto-char (point-max))
562562
;; (if inferior-ess-language-start
563563
;; (ess-eval-linewise inferior-ess-language-start
564564
;; nil nil nil 'wait-prompt)))
565-
(with-ess-process-buffer nil
565+
(with-current-buffer inf-buf
566566
(run-mode-hooks 'ess-gretl-post-run-hook))
567-
))
567+
inf-buf))
568568

569569

570570
;;;; IMENU

lisp/ess-inf.el

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -175,38 +175,38 @@ This may be useful for debugging."
175175
(proc-name (with-current-buffer inf-buf ess-local-process-name))
176176
(cur-dir (inferior-ess--maybe-prompt-startup-directory proc-name temp-dialect))
177177
(default-directory cur-dir))
178-
(set-buffer inf-buf)
179-
(setq-local default-directory cur-dir)
180-
;; TODO: Get rid of this, we should rely on modes to set the
181-
;; variables they need.
182-
(ess-setq-vars-local ess-customize-alist)
183-
(let ((inf-args (or ess-start-args
184-
inferior-ess-start-args)))
185-
(inferior-ess--set-major-mode ess-dialect)
186-
;; Show the buffer
187-
;; TODO: Remove inferior-ess-own-frame after ESS 19.04, then just have:
188-
;; (pop-to-buffer inf-buf)
189-
(pop-to-buffer inf-buf (with-no-warnings
190-
(when inferior-ess-own-frame
191-
'(display-buffer-pop-up-frame))))
192-
(let ((proc (inferior-ess--start-process inf-buf proc-name inf-args)))
193-
(ess-make-buffer-current)
194-
(goto-char (point-max))
195-
(unless no-wait
196-
(ess-write-to-dribble-buffer "(inferior-ess: waiting for process to start (before hook)\n")
197-
(ess-wait-for-process proc nil 0.01 t))
198-
(unless (and proc (eq (process-status proc) 'run))
199-
(error "Process %s failed to start" proc-name))
200-
(when ess-setwd-command
201-
(ess-set-working-directory cur-dir))
202-
(setq-local font-lock-fontify-region-function #'inferior-ess-fontify-region)
203-
(setq-local ess-sl-modtime-alist nil)
204-
(run-hooks 'ess-post-run-hook)
205-
;; User initialization can take some time ...
206-
(unless no-wait
207-
(ess-write-to-dribble-buffer "(inferior-ess 3): waiting for process after hook")
208-
(ess-wait-for-process proc)))
209-
inf-buf))))
178+
(with-current-buffer inf-buf
179+
(setq-local default-directory cur-dir)
180+
;; TODO: Get rid of this, we should rely on modes to set the
181+
;; variables they need.
182+
(ess-setq-vars-local ess-customize-alist)
183+
(let ((inf-args (or ess-start-args
184+
inferior-ess-start-args)))
185+
(inferior-ess--set-major-mode ess-dialect)
186+
;; Show the buffer
187+
;; TODO: Remove inferior-ess-own-frame after ESS 19.04, then just have:
188+
;; (pop-to-buffer inf-buf)
189+
(pop-to-buffer inf-buf (with-no-warnings
190+
(when inferior-ess-own-frame
191+
'(display-buffer-pop-up-frame))))
192+
(let ((proc (inferior-ess--start-process inf-buf proc-name inf-args)))
193+
(ess-make-buffer-current)
194+
(goto-char (point-max))
195+
(unless no-wait
196+
(ess-write-to-dribble-buffer "(inferior-ess: waiting for process to start (before hook)\n")
197+
(ess-wait-for-process proc nil 0.01 t))
198+
(unless (and proc (eq (process-status proc) 'run))
199+
(error "Process %s failed to start" proc-name))
200+
(when ess-setwd-command
201+
(ess-set-working-directory cur-dir))
202+
(setq-local font-lock-fontify-region-function #'inferior-ess-fontify-region)
203+
(setq-local ess-sl-modtime-alist nil)
204+
(run-hooks 'ess-post-run-hook)
205+
;; User initialization can take some time ...
206+
(unless no-wait
207+
(ess-write-to-dribble-buffer "(inferior-ess 3): waiting for process after hook")
208+
(ess-wait-for-process proc)))
209+
inf-buf)))))
210210

211211
(defun inferior-ess--get-proc-buffer-create (name)
212212
"Get a process buffer, creating a new one if needed.

lisp/ess-julia.el

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -434,23 +434,23 @@ always be passed to julia, put them in the variable
434434
(concat " [other than '" inferior-julia-args "']"))
435435
" ? "))
436436
nil))))
437-
(inferior-ess jl-start-args)
438-
439-
(ess--tb-start)
440-
;; remove ` from julia's logo
441-
(goto-char (point-min))
442-
(while (re-search-forward "`" nil t)
443-
(replace-match "'"))
444-
;; remove an offending unmatched parenthesis
445-
(goto-char (point-min))
446-
(forward-line 4)
447-
(when (re-search-forward "(" nil t)
448-
(replace-match "|"))
449-
(goto-char (point-max))
450-
;; --> julia helpers from ../etc/ess-julia.jl :
451-
(ess--inject-code-from-file (format "%sess-julia.jl" ess-etc-directory))
452-
(with-ess-process-buffer nil
453-
(run-mode-hooks 'ess-julia-post-run-hook)))))
437+
(let ((inf-buf (inferior-ess jl-start-args)))
438+
(ess--tb-start)
439+
;; Remove ` from julia's logo
440+
(goto-char (point-min))
441+
(while (re-search-forward "`" nil t)
442+
(replace-match "'"))
443+
;; Remove an offending unmatched parenthesis
444+
(goto-char (point-min))
445+
(forward-line 4)
446+
(when (re-search-forward "(" nil t)
447+
(replace-match "|"))
448+
(goto-char (point-max))
449+
;; --> julia helpers from ../etc/ess-julia.jl :
450+
(ess--inject-code-from-file (format "%sess-julia.jl" ess-etc-directory))
451+
(with-current-buffer inf-buf
452+
(run-mode-hooks 'ess-julia-post-run-hook))
453+
inf-buf))))
454454

455455
(cl-defmethod ess--help-major-mode (&context ((string= ess-dialect "julia") (eql t)))
456456
(ess-julia-help-mode))

lisp/ess-r-mode.el

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -523,29 +523,27 @@ will be prompted to enter arguments interactively."
523523
(setq default-process-coding-system '(undecided-dos . undecided-dos))))
524524

525525
(let ((inf-buf (inferior-ess r-start-args cust-alist gdbp)))
526-
527-
(ess-process-put 'funargs-pre-cache ess-r--funargs-pre-cache)
528-
529-
(remove-hook 'completion-at-point-functions 'ess-filename-completion 'local) ;; should be first
530-
(add-hook 'completion-at-point-functions 'ess-r-object-completion nil 'local)
531-
(add-hook 'completion-at-point-functions 'ess-filename-completion nil 'local)
532-
(add-hook 'xref-backend-functions #'ess-r-xref-backend nil 'local)
533-
(setq comint-input-sender 'inferior-ess-r-input-sender)
534-
535-
(if gdbp
536-
(progn
537-
;; We need to use callback, because R might start with a gdb process
538-
(ess-process-put 'callbacks '(R-initialize-on-start))
539-
;; trigger the callback
540-
(process-send-string (get-process ess-local-process-name) "\n"))
541-
(ess-wait-for-process)
542-
(R-initialize-on-start)
543-
(comint-goto-process-mark))
544-
545-
(ess-write-to-dribble-buffer
546-
(format "(R): inferior-ess-language-start=%s\n"
547-
inferior-ess-language-start))
548-
inf-buf)))
526+
(with-current-buffer inf-buf
527+
(ess-process-put 'funargs-pre-cache ess-r--funargs-pre-cache)
528+
(remove-hook 'completion-at-point-functions 'ess-filename-completion 'local) ;; should be first
529+
(add-hook 'completion-at-point-functions 'ess-r-object-completion nil 'local)
530+
(add-hook 'completion-at-point-functions 'ess-filename-completion nil 'local)
531+
(add-hook 'xref-backend-functions #'ess-r-xref-backend nil 'local)
532+
(setq comint-input-sender 'inferior-ess-r-input-sender)
533+
(if gdbp
534+
(progn
535+
;; We need to use callback, because R might start with a gdb process
536+
(ess-process-put 'callbacks '(R-initialize-on-start))
537+
;; Trigger the callback
538+
(process-send-string (get-process ess-local-process-name) "\n"))
539+
(ess-wait-for-process)
540+
(R-initialize-on-start)
541+
(comint-goto-process-mark))
542+
(ess-write-to-dribble-buffer
543+
(format "(R): inferior-ess-language-start=%s\n"
544+
inferior-ess-language-start)))
545+
;; FIXME: Current ob-R expects current buffer set to process buffer
546+
(set-buffer inf-buf))))
549547

550548
;;;###autoload
551549
(defalias 'R #'run-ess-r)

lisp/ess-sas-d.el

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ Better logic needed! (see 2 uses, in this file).")
307307
temp-dialect))
308308
(ess-SAS-pre-run-hook temp-dialect)
309309
(setq ess-eval-visibly-p nil)
310-
(inferior-ess)
311-
(with-current-buffer "*SAS*"
312-
(use-local-map sas-mode-local-map))))
313-
310+
(let ((inf-buf (inferior-ess)))
311+
(with-current-buffer inf-buf
312+
(use-local-map sas-mode-local-map))
313+
inf-buf)))
314314

315315
(defun ess-multi-frame-SAS ()
316316
"Put running SAS buffers into separate frames.

lisp/ess-sp6-d.el

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,13 @@ New way to do it."
116116
(setq ess-customize-alist S+-customize-alist)
117117
(ess-write-to-dribble-buffer
118118
(format "\n(S+): ess-dialect=%s, buf=%s\n" ess-dialect (current-buffer)))
119-
(inferior-ess)
120-
(ess-command ess-S+--injected-code)
121-
(if inferior-ess-language-start
119+
(let ((inf-buf (inferior-ess)))
120+
(ess-command ess-S+--injected-code)
121+
(when inferior-ess-language-start
122122
(ess-eval-linewise inferior-ess-language-start))
123-
(with-ess-process-buffer nil
124-
(run-mode-hooks 'ess-S+-post-run-hook)))
123+
(with-current-buffer inf-buf
124+
(run-mode-hooks 'ess-S+-post-run-hook))
125+
inf-buf))
125126

126127

127128
(defalias 'S+6-mode 'S+-mode)

lisp/ess-stata-mode.el

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,21 @@ This function is placed in `ess-presend-filter-functions'.
150150
(format "(STA): ess-dialect=%s , buf=%s \n"
151151
ess-dialect
152152
(current-buffer)))
153-
(let ((sta-start-args
154-
(concat inferior-STA-start-args
155-
(when start-args (read-string "Starting Args [possibly -k####] ? ")))))
156-
(inferior-ess sta-start-args)
157-
(let ((proc (get-process ess-local-process-name)))
158-
(while (process-get proc 'sec-prompt)
159-
;; get read of all --more-- if stata.msg is too long.
160-
(ess-send-string proc "q")
161-
(ess-wait-for-process proc t))
162-
(ess-send-string proc "set more off")
163-
(goto-char (point-max))
164-
(with-current-buffer (process-buffer proc)
165-
(add-hook 'ess-presend-filter-functions 'ess-sta-remove-comments nil 'local)
166-
(run-mode-hooks 'ess-stata-post-run-hook)))))
153+
(let* ((sta-start-args
154+
(concat inferior-STA-start-args
155+
(when start-args (read-string "Starting Args [possibly -k####] ? "))))
156+
(inf-buf (inferior-ess sta-start-args))
157+
(inf-proc (get-buffer-process inf-buf)))
158+
(while (process-get inf-proc 'sec-prompt)
159+
;; get read of all --more-- if stata.msg is too long.
160+
(ess-send-string inf-proc "q")
161+
(ess-wait-for-process inf-proc t))
162+
(ess-send-string inf-proc "set more off")
163+
(goto-char (point-max))
164+
(with-current-buffer inf-buf
165+
(add-hook 'ess-presend-filter-functions 'ess-sta-remove-comments nil 'local)
166+
(run-mode-hooks 'ess-stata-post-run-hook))
167+
inf-buf))
167168

168169
(defvar inferior-ess-stata-mode-syntax-table
169170
(let ((tab (copy-syntax-table ess-stata-mode-syntax-table)))

lisp/essd-els.el

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ The default value is nil."
7171
(ess-write-to-dribble-buffer
7272
(format "\n(S+elsewhere): ess-dialect=%s, buf=%s\n" ess-dialect
7373
(current-buffer)))
74-
(inferior-ess)
75-
(if inferior-ess-language-start
76-
(ess-eval-linewise inferior-ess-language-start)))
74+
(let ((inf-buf (inferior-ess)))
75+
(when inferior-ess-language-start
76+
(ess-eval-linewise inferior-ess-language-start))
77+
inf-buf))
7778

7879
(defun S+elsewhere-mode (&optional _proc-name)
7980
"Major mode for editing S+3 source. See `ess-mode' for more help."

test/ess-test-r.el

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,11 @@
286286

287287
;; roxy
288288
(ert-deftest ess-roxy-preview-Rd-test ()
289-
(with-r-running nil
290-
(if (member "roxygen2" (ess-installed-packages))
291-
(should
292-
(string= "% Generated by roxygen2: do not edit by hand
289+
(let ((buf (generate-new-buffer " *temp*")))
290+
(with-r-running buf
291+
(if (member "roxygen2" (ess-installed-packages))
292+
(should
293+
(string= "% Generated by roxygen2: do not edit by hand
293294
\\name{add}
294295
\\alias{add}
295296
\\title{Add together two numbers.
@@ -301,24 +302,24 @@ add(x, y)
301302
Add together two numbers. add(10, 1)
302303
}
303304
"
304-
(with-temp-buffer
305-
(R-mode)
306-
(ess-roxy-mode)
307-
(insert
308-
"##' Add together two numbers.
305+
(with-current-buffer buf
306+
(R-mode)
307+
(ess-roxy-mode)
308+
(insert
309+
"##' Add together two numbers.
309310
##' add(10, 1)
310311
add <- function(x, y) {
311312
x + y
312313
}")
313-
(goto-char (point-min))
314-
(ess-roxy-preview-Rd)
315-
;; Delete the reference to the file which isn't
316-
;; reproducible across different test environments
317-
(goto-char (point-min))
318-
(forward-line 1)
319-
(kill-whole-line)
320-
(buffer-substring-no-properties (point-min) (point-max)))))
321-
(ert-skip "Roxygen2 not installed"))))
314+
(goto-char (point-min))
315+
(ess-roxy-preview-Rd)
316+
;; Delete the reference to the file which isn't
317+
;; reproducible across different test environments
318+
(goto-char (point-min))
319+
(forward-line 1)
320+
(kill-whole-line)
321+
(buffer-substring-no-properties (point-min) (point-max)))))
322+
(ert-skip "Roxygen2 not installed")))))
322323

323324
(ert-deftest ess-test-roxy-font-lock ()
324325
(ess-r-test-with-temp-text

0 commit comments

Comments
 (0)