Skip to content

Commit c59d8c1

Browse files
committed
Start inf processes in the project folder by default
1 parent fd3e217 commit c59d8c1

File tree

6 files changed

+19
-35
lines changed

6 files changed

+19
-35
lines changed

doc/newfeat.texi

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

7+
@item ESS[R]: Add support for R projects and start R by default in the project folder.
8+
79
@item ESS[R]: Backticked symbols in the process buffer are no
810
longer fontified as strings.
911

lisp/ess-custom.el

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ This, plus `ess-language', should be able to determine the exact
311311
version of the statistical package being executed in the particular
312312
buffer.")
313313

314-
(defcustom ess-directory-function nil
314+
(defvaralias 'ess-directory-function 'ess-startup-directory-function)
315+
(defcustom ess-startup-directory-function nil
315316
"Function to return the directory that ESS is run from.
316317
If nil or if the function returns nil then you get `ess-startup-directory'."
317318
:group 'ess
@@ -2465,9 +2466,6 @@ Used to store the values for passing on to newly created buffers.")
24652466
(defvar-local ess-listing-minor-mode nil
24662467
"Non-nil if using `ess-listing-minor-mode'.")
24672468

2468-
(defvar ess--enable-experimental-projects nil
2469-
"Enable experimental project support in ESS.")
2470-
24712469
(defvar ess-STERM nil
24722470
"Placeholder for dialect-specific STERM.")
24732471

lisp/ess-inf.el

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -621,29 +621,22 @@ process-less buffer because it was created with
621621

622622

623623
;;*;; Requester functions called at startup
624-
625-
;; FIXME EMACS 25.1:
626-
;; Deprecate `ess-directory-function' in favor of `project-find-functions'?
627624
(defun inferior-ess--get-startup-directory ()
628625
"Return a startup directory."
629-
(let ((dir (or (and ess--enable-experimental-projects
630-
(fboundp 'project-current)
631-
(cdr (project-current)))
632-
(and ess-directory-function
626+
(let ((dir (or (and ess-directory-function
633627
(funcall ess-directory-function))
628+
(when-let ((proj (project-current)))
629+
(ess--project-root proj))
634630
ess-startup-directory
635631
default-directory)))
636632
(directory-file-name dir)))
637633

638-
(defun inferior-ess--maybe-prompt-startup-directory (procname dialect)
634+
(defun inferior-ess--maybe-prompt-startup-directory (procname _dialect)
639635
"Possibly prompt for a startup directory.
640636
When `ess-ask-for-ess-directory' is non-nil, prompt. PROCNAME is
641637
the name of the inferior process (e.g. \"R:1\"), and DIALECT is
642638
the language dialect (e.g. \"R\")."
643-
(let ((default-dir (if (fboundp 'inferior-ess-r--adjust-startup-directory)
644-
(inferior-ess-r--adjust-startup-directory
645-
(inferior-ess--get-startup-directory) dialect)
646-
(inferior-ess--get-startup-directory))))
639+
(let ((default-dir (inferior-ess--get-startup-directory)))
647640
(if ess-ask-for-ess-directory
648641
(let ((prompt (format "%s starting project directory? " procname)))
649642
(ess-prompt-for-directory default-dir prompt))

lisp/ess-r-flymake.el

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
(declare-function flymake-diag-region "flymake")
4141
(declare-function flymake-make-diagnostic "flymake")
4242
(declare-function flymake--overlays "flymake")
43+
(declare-function ess-r-project "ess-r-mode")
44+
(declare-function ess-r-package-project "ess-r-package")
4345

4446
(defcustom ess-r-flymake-linters
4547
'("closed_curly_linter = NULL"
@@ -103,7 +105,7 @@ we couldn't find a .lintr file."
103105
;; `(locate-dominating-file ".lintr")`?
104106
(let* ((cur-file (expand-file-name ".lintr" default-directory))
105107
(pkg (cdr (ess-r-package-project)))
106-
(pkg-file (and proj (expand-file-name ".lintr" pkg)))
108+
(pkg-file (and pkg (expand-file-name ".lintr" pkg)))
107109
(proj (ess-r-project))
108110
(proj-file (and proj (expand-file-name ".lintr" proj)))
109111
(home-file (expand-file-name ".lintr" (getenv "HOME"))))

lisp/ess-r-mode.el

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,9 @@ will be prompted to enter arguments interactively."
588588
inferior-R-args " " ; add space just in case
589589
start-args))
590590
(debug (string-match-p " -d \\| --debugger=" r-start-args))
591+
(project-find-functions (if (memq 'ess-r-project project-find-functions)
592+
project-find-functions
593+
(cons 'ess-r-project project-find-functions)))
591594
use-dialog-box)
592595
(when (or ess-microsoft-p
593596
(eq system-type 'cygwin))
@@ -618,21 +621,6 @@ will be prompted to enter arguments interactively."
618621
;; FIXME: Current ob-R expects current buffer set to process buffer
619622
(set-buffer (run-ess-r start-args)))
620623

621-
(defun inferior-ess-r--adjust-startup-directory (dir dialect)
622-
"Adjust startup directory DIR if DIALECT is R.
623-
If in a package project, prefer the tests directory but only if
624-
the package directory was selected in the first place."
625-
(if (string= dialect "R")
626-
(let* ((project-dir (cdr (ess-r-package-project)))
627-
(tests-dir (expand-file-name (file-name-as-directory "tests")
628-
project-dir)))
629-
(if (and project-dir
630-
(string= project-dir dir)
631-
(string= default-directory tests-dir))
632-
tests-dir
633-
dir))
634-
dir))
635-
636624
(defun inferior-ess-r--init-callback (_proc _name)
637625
(R-initialize-on-start))
638626

@@ -870,7 +858,7 @@ efficiency reasons."
870858
(file-exists-p (expand-file-name "DESCRIPTION" dir))
871859
(let ((nm (file-name-nondirectory (directory-file-name dir))))
872860
(file-exists-p (expand-file-name (concat nm ".Rproj") dir))))))))
873-
(when dir
861+
(when dir
874862
(let ((dir (directory-file-name dir)))
875863
(unless (member dir (list "~" (getenv "HOME")))
876864
(list :name (file-name-nondirectory dir)

lisp/ess-r-package.el

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
;; Silence the byte compiler, OK because this file is only loaded by
3737
;; ess-r-mode and has no autoloads.
3838
(defvar ess-r-customize-alist)
39+
(declare-function ess-r-project "ess-r-mode")
3940
(declare-function inferior-ess-r-force "ess-r-mode")
4041
(declare-function ess-r-get-evaluation-env "ess-r-mode")
4142
(declare-function ess-r-set-evaluation-env "ess-r-mode")
@@ -526,9 +527,9 @@ Set this variable to nil to disable the mode line entirely."
526527
(set (make-local-variable var)
527528
(eval (cdr (assq var ess-r-customize-alist)))))
528529
vars))
529-
(add-hook 'project-find-functions #'ess-r-package-project)
530+
(add-hook 'project-find-functions #'ess-r-project)
530531
(run-hooks 'ess-r-package-enter-hook))
531-
(remove-hook 'project-find-functions #'ess-r-package-project)
532+
(remove-hook 'project-find-functions #'ess-r-project)
532533
(run-hooks 'ess-r-package-exit-hook)))
533534

534535
(add-hook 'after-change-major-mode-hook 'ess-r-package-auto-activate)

0 commit comments

Comments
 (0)