branch: externals/ess commit da413b8bd14205890c087f56b2cf7445adc18cc6 Author: Lionel Henry <lionel....@gmail.com> Commit: Lionel Henry <lionel....@gmail.com>
Carefully check for disabled bg eval --- lisp/ess-inf.el | 15 +++++++-- lisp/ess-r-completion.el | 88 ++++++++++++++++++++++-------------------------- 2 files changed, 53 insertions(+), 50 deletions(-) diff --git a/lisp/ess-inf.el b/lisp/ess-inf.el index 486baabb9b..cf1a28d357 100644 --- a/lisp/ess-inf.el +++ b/lisp/ess-inf.el @@ -931,6 +931,16 @@ no such process has been found." (inferior-ess-available-p proc))) (throw 'found proc)))))))) +(defun ess-get-next-available-bg-process (&optional proc dialect ignore-busy) + "Returns first avaiable process only if background evaluations are allowed. +Same as `ess-get-next-available-process' but checks for +`ess-can-eval-in-background' carefully." + ;; Don't check for availability if background evals were disabled + (when ess-can-eval-in-background + (when-let ((proc (or proc (ess-get-next-available-process dialect ignore-busy)))) + (when (ess-can-eval-in-background proc) + proc)))) + ;;*;;; Commands for switching to the process buffer @@ -2190,9 +2200,8 @@ any. This makes it possible to disable background evals for a specific process, for instance in case it was not initialized properly." (when ess-can-eval-in-background - (if-let ((proc (or proc (ess-get-current-process)))) - (not (process-get proc 'bg-eval-disabled)) - t))) + (when-let ((proc (or proc (ess-get-current-process)))) + (not (process-get proc 'bg-eval-disabled))))) ;;;*;;; Hot key commands diff --git a/lisp/ess-r-completion.el b/lisp/ess-r-completion.el index b06e1b613f..da7c7abe6a 100644 --- a/lisp/ess-r-completion.el +++ b/lisp/ess-r-completion.el @@ -53,37 +53,36 @@ "Return the doc string, or nil. If an ESS process is not associated with the buffer, do not try to look up any doc strings." - (when (and eldoc-mode (ess-can-eval-in-background)) - (let* ((proc (ess-get-next-available-process)) - (funname (and proc (or (and ess-eldoc-show-on-symbol ;; Aggressive completion - (thing-at-point 'symbol)) - (car (ess--fn-name-start)))))) - (when funname - (let* ((args (ess-function-arguments funname proc)) - (bargs (cadr args)) - (doc (mapconcat (lambda (el) - (if (equal (car el) "...") - "..." - (concat (car el) "=" (cdr el)))) - bargs ", ")) - (margs (nth 2 args)) - (W (- (window-width (minibuffer-window)) (+ 4 (length funname)))) - (multiline (eq t eldoc-echo-area-use-multiline-p)) - doc1) - (when doc - (setq doc (ess-eldoc-docstring-format funname doc (not multiline))) - (when (or multiline (and margs (< (length doc1) W))) - (setq doc1 (concat doc (propertize " || " 'face font-lock-function-name-face))) - (while (and margs (< (length doc1) W)) - (let ((head (pop margs))) - (unless (assoc head bargs) - (setq doc doc1 - doc1 (concat doc1 head "=, "))))) - (when (equal (substring doc -2) ", ") - (setq doc (substring doc 0 -2))) - (when (and margs (< (length doc) W)) - (setq doc (concat doc " {--}")))) - doc)))))) + (when eldoc-mode + (when-let ((proc (ess-get-next-available-bg-process)) + (funname (or (and ess-eldoc-show-on-symbol ;; Aggressive completion + (thing-at-point 'symbol)) + (car (ess--fn-name-start))))) + (let* ((args (ess-function-arguments funname proc)) + (bargs (cadr args)) + (doc (mapconcat (lambda (el) + (if (equal (car el) "...") + "..." + (concat (car el) "=" (cdr el)))) + bargs ", ")) + (margs (nth 2 args)) + (W (- (window-width (minibuffer-window)) (+ 4 (length funname)))) + (multiline (eq t eldoc-echo-area-use-multiline-p)) + doc1) + (when doc + (setq doc (ess-eldoc-docstring-format funname doc (not multiline))) + (when (or multiline (and margs (< (length doc1) W))) + (setq doc1 (concat doc (propertize " || " 'face font-lock-function-name-face))) + (while (and margs (< (length doc1) W)) + (let ((head (pop margs))) + (unless (assoc head bargs) + (setq doc doc1 + doc1 (concat doc1 head "=, "))))) + (when (equal (substring doc -2) ", ") + (setq doc (substring doc 0 -2))) + (when (and margs (< (length doc) W)) + (setq doc (concat doc " {--}")))) + doc))))) (defun ess-eldoc-docstring-format (funname doc &optional truncate) (save-match-data @@ -325,7 +324,7 @@ To be used instead of ESS' completion engine for R versions >= 2.7.0." (defun ess-r-get-object-help-string (sym) "Help string for ac." - (let ((proc (ess-get-next-available-process))) + (let ((proc (ess-get-next-available-bg-process))) (if (null proc) "No free ESS process found" (let ((buf (get-buffer-create " *ess-command-output*"))) @@ -342,7 +341,7 @@ To be used instead of ESS' completion engine for R versions >= 2.7.0." (defun ess-r-get-arg-help-string (sym &optional proc) "Help string for ac." (setq sym (replace-regexp-in-string " *= *\\'" "" sym)) - (let ((proc (or proc (ess-get-next-available-process)))) + (let ((proc (ess-get-next-available-bg-process proc))) (if (null proc) "No free ESS process found" (let ((fun (car ess--fn-name-start-cache))) @@ -364,11 +363,9 @@ To be used instead of ESS' completion engine for R versions >= 2.7.0." (let ((start (ess-symbol-start))) (when start (buffer-substring-no-properties start (point)))))) - (candidates (when (ess-can-eval-in-background) - (let ((proc (ess-get-next-available-process))) - (when proc - (with-current-buffer (process-buffer proc) - (all-completions arg (ess--get-cached-completions arg))))))) + (candidates (when-let ((proc (ess-get-next-available-bg-process))) + (with-current-buffer (process-buffer proc) + (all-completions arg (ess--get-cached-completions arg))))) (doc-buffer (company-doc-buffer (ess-r-get-object-help-string arg))))) (defun company-R-args (command &optional arg &rest ignored) @@ -383,21 +380,18 @@ To be used instead of ESS' completion engine for R versions >= 2.7.0." (cons prefix (>= (length prefix) ess-company-arg-prefix-length)) prefix)))))) - (candidates (when (ess-can-eval-in-background) - (let* ((proc (ess-get-next-available-process)) - (args (delete "..." (nth 2 (ess-function-arguments + (candidates (when-let ((proc (ess-get-next-available-bg-process))) + (let* ((args (delete "..." (nth 2 (ess-function-arguments (car ess--fn-name-start-cache) proc)))) (args (mapcar (lambda (a) (concat a ess-R-argument-suffix)) args))) (all-completions arg args)))) ;; Displaying help for the argument in the echo area is disabled ;; by default for performance reasons. It causes delays or hangs (#1062). - (meta (when (and (ess-can-eval-in-background) - (bound-and-true-p ess-r--company-meta)) - (let ((proc (ess-get-next-available-process))) - (when (and proc - (with-current-buffer (process-buffer proc) - (not (file-remote-p default-directory)))) + (meta (when (bound-and-true-p ess-r--company-meta) + (when-let ((proc (ess-get-next-available-bg-process))) + (when (with-current-buffer (process-buffer proc) + (not (file-remote-p default-directory))) ;; fixme: ideally meta should be fetched with args (let ((doc (ess-r-get-arg-help-string arg proc))) (replace-regexp-in-string "^ +\\| +$" ""