Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows some devtools commands to be run in a compilation-mode buffer. #531

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions lisp/ess-r-package.el
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ All children of these directories are also considered source
containing directories. Use `ess-r-package-source-dirs' to get
all source dirs recursively within the current package.")

(defcustom ess-r-package-use-compile-buffer nil
"When t, run some package commands in a separate compilation buffer."
:group 'ess-r-package
:type 'boolean)


;;;*;;; Package Detection

Expand Down Expand Up @@ -268,6 +273,20 @@ arguments, or expressions which return R arguments."
args
(concat ", " args))))

(defun ess-r-package-eval-in-compile-buffer (expr)
"Evalate R expression EXPR in a standalone `compilation-mode'
buffer."
(let* ((procname inferior-ess-r-program-name)
(pkg-info (or (ess-r-package-project)
(ess-r-package-set-package)))
(pkg-name (ess-r-package-name))
(default-directory (cdr pkg-info))
(command (format "%s --slave --no-readline -e \"%s\"" procname expr)))
(compilation-start command nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t instead of nil would result in compilation-shell-minor-mode which should solve the term signals issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this also puts it in comint-mode, which is quite a different experience than the usual compilation-mode. I don't see an obvious way to get term signal handling outside of comint-mode -- do you have any inkling of what could be done?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does that matter? If compilation mode is based on comint this is how it is.

(lambda (name-of-mode)
(concat "*" (downcase name-of-mode) ":" pkg-name "*"))
ess-r-error-regexp-alist)))


;;;*;;; Devtools Integration

Expand All @@ -289,9 +308,13 @@ With prefix ARG ask for extra args."
"Interface for `devtools::check()'.
With prefix ARG ask for extra args."
(interactive "P")
(ess-r-package-eval-linewise
"devtools::check(%s)\n" "Checking %s" arg
'("" (read-string "Arguments: " "vignettes = FALSE"))))
(let ((actions '("" (read-string "Arguments: " "vignettes = FALSE"))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too much copy pasting. I would add a wrapper which would dispatch to ess-r-package-eval-linewise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a hard time coming up with a design for such a wrapper -- do you have an idea about how to do it nicely?

(if ess-r-package-use-compile-buffer
(ess-r-package-eval-in-compile-buffer
(format "devtools::check('.'%s)"
(ess-r-command--build-args arg actions)))
(ess-r-package-eval-linewise
"devtools::check(%s)\n" "Checking %s" arg actions))))

(defun ess-r-devtools-check-with-winbuilder (&optional arg)
"Interface for `devtools::buildwin()'.
Expand Down Expand Up @@ -327,9 +350,13 @@ With prefix arg, build with 'vignettes = FALSE'."
"Interface for `devtools::test()'.
With prefix argument ARG, run tests on current file only."
(interactive "P")
(ess-r-package-eval-linewise
"devtools::test(%s)\n" "Testing %s" arg
'("" ess-r-devtools--cur-file-filter)))
(let ((actions '("" ess-r-devtools--cur-file-filter)))
(if ess-r-package-use-compile-buffer
(ess-r-package-eval-in-compile-buffer
(format "devtools::test('.'%s)"
(ess-r-command--build-args arg actions)))
(ess-r-package-eval-linewise
"devtools::test(%s)\n" "Testing %s" arg actions))))

(defun ess-r-devtools--cur-file-filter ()
(let ((file (or (and buffer-file-name
Expand Down Expand Up @@ -364,9 +391,13 @@ With prefix argument ARG, run tests on current file only."
"Interface for `devtools::document()'.
With prefix ARG ask for extra arguments."
(interactive "P")
(ess-r-package-eval-linewise
"devtools::document(%s)\n" "Documenting %s" arg
'("" (read-string "Arguments: "))))
(let ((actions '("" (read-string "Arguments: "))))
(if ess-r-package-use-compile-buffer
(ess-r-package-eval-in-compile-buffer
(format "devtools::document('.'%s)"
(ess-r-command--build-args arg actions)))
(ess-r-package-eval-linewise
"devtools::document(%s)\n" "Documenting %s" arg actions))))

(defun ess-r-devtools-install-package (&optional arg)
"Interface to `devtools::install()'.
Expand Down