Skip to content

Commit 2e1809a

Browse files
authored
Merge pull request #1186 from emacs-ess/ask-for-dir-after-ess-inf
[Fix #1185] Move ask-for directory code after ess-r-mode startup
2 parents 157ea5c + f3c196d commit 2e1809a

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

lisp/ess-custom.el

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -314,24 +314,24 @@ buffer.")
314314
(defvaralias 'ess-directory-function 'ess-startup-directory-function)
315315
(defcustom ess-startup-directory-function nil
316316
"Function to return the directory that ESS is run from.
317-
If nil or if the function returns nil then you get `ess-startup-directory'."
318-
:group 'ess
319-
:type '(choice (const nil) function))
320-
321-
(defcustom ess-setup-directory-function nil
322-
"Function to setup the directory that ESS is run from.
323-
This function can be called to set environment variables or to create
324-
a workspace."
317+
Value of `ess-startup-directory' has precedence over this function."
325318
:group 'ess
326319
:type '(choice (const nil) function))
327320

328321
(defvaralias 'ess-directory 'ess-startup-directory)
329322
(defcustom ess-startup-directory nil
330-
"The directory ESS is run from. It must end in a slash.
331-
Provided as a default if `ess-ask-for-ess-directory' is non-nil.
332-
A nil value means use the current buffer's default directory."
323+
"The directory ESS is run from (string or a symbol).
324+
Provided a default (especially useful if
325+
`ess-ask-for-ess-directory' is non-nil). A nil value means use
326+
the value returned by `ess-startup-directory-function'. If nil,
327+
use current project directory, otherwise use to the
328+
`default-directory'.
329+
330+
When this variable is a symbol, use its value. Set this variable
331+
to `'default-directory' in order to always start in the current
332+
directory."
333333
:group 'ess
334-
:type '(choice (const nil) directory))
334+
:type '(choice (const nil) directory symbol))
335335

336336

337337
(defcustom ess-history-directory nil

lisp/ess-inf.el

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,16 @@ This may be useful for debugging."
169169
dialect)
170170
dialect))
171171
(inf-buf (inferior-ess--get-proc-buffer-create temp-dialect))
172-
(proc-name (buffer-local-value 'ess-local-process-name inf-buf))
173-
(cur-dir (inferior-ess--maybe-prompt-startup-directory proc-name temp-dialect))
174-
(default-directory cur-dir))
172+
(proc-name (buffer-local-value 'ess-local-process-name inf-buf)))
175173
(with-current-buffer inf-buf
176174
;; TODO: Get rid of this, we should rely on modes to set the
177175
;; variables they need.
178176
(ess-setq-vars-local customize-alist)
179177
(inferior-ess--set-major-mode ess-dialect)
180178
;; Set local variables after changing mode because they might
181179
;; not be permanent
182-
(setq default-directory cur-dir)
180+
(setq default-directory
181+
(inferior-ess--maybe-prompt-startup-directory proc-name temp-dialect))
183182
(setq inferior-ess--local-data (cons inferior-ess-program start-args))
184183
;; Read the history file
185184
(when ess-history-file
@@ -204,7 +203,7 @@ This may be useful for debugging."
204203
(unless (and proc (eq (process-status proc) 'run))
205204
(error "Process %s failed to start" proc-name))
206205
(when ess-setwd-command
207-
(ess-set-working-directory cur-dir))
206+
(ess-set-working-directory default-directory))
208207
(setq-local font-lock-fontify-region-function #'inferior-ess-fontify-region)
209208
(setq-local ess-sl-modtime-alist nil)
210209
(run-hooks 'ess-post-run-hook)
@@ -623,11 +622,14 @@ process-less buffer because it was created with
623622
;;*;; Requester functions called at startup
624623
(defun inferior-ess--get-startup-directory ()
625624
"Return a startup directory."
626-
(let ((dir (or (and ess-directory-function
627-
(funcall ess-directory-function))
625+
(let ((dir (or (when (boundp 'ess-startup-directory)
626+
(if (symbolp ess-startup-directory)
627+
(symbol-value ess-startup-directory)
628+
ess-startup-directory))
629+
(and ess-startup-directory-function
630+
(funcall ess-startup-directory-function))
628631
(when-let ((proj (project-current)))
629632
(ess--project-root proj))
630-
ess-startup-directory
631633
default-directory)))
632634
(directory-file-name dir)))
633635

@@ -2430,7 +2432,7 @@ START-ARGS gets passed to the dialect-specific
24302432
;; Make sure we don't ask for directory again
24312433
;; Use current working directory as default
24322434
(let ((project-find-functions nil)
2433-
(ess-directory-function nil)
2435+
(ess-startup-directory-function nil)
24342436
(ess-startup-directory (ess-get-process-variable 'default-directory))
24352437
(ess-ask-for-ess-directory nil))
24362438
(ess-quit 'no-save)

lisp/ess-r-mode.el

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,10 @@ will be prompted to enter arguments interactively."
558558
"\n(R): ess-dialect=%s, buf=%s, start-arg=%s\n current-prefix-arg=%s\n"
559559
ess-dialect (current-buffer) start-args current-prefix-arg))
560560
(unless (or (file-remote-p default-directory)
561-
(and ess-startup-directory
562-
(file-remote-p ess-startup-directory))
561+
(when ess-startup-directory
562+
(file-remote-p (if (symbolp ess-startup-directory)
563+
(symbol-value ess-startup-directory)
564+
ess-startup-directory)))
563565
;; TODO: Once we drop Emacs 26 support, can probably
564566
;; just use the REMOTE argument of `executable-find'.
565567
(executable-find inferior-ess-r-program))
@@ -588,9 +590,6 @@ will be prompted to enter arguments interactively."
588590
inferior-R-args " " ; add space just in case
589591
start-args))
590592
(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)))
594593
use-dialog-box)
595594
(when (or ess-microsoft-p
596595
(eq system-type 'cygwin))

lisp/ess-r-package.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ Set this variable to nil to disable the mode line entirely."
527527
(set (make-local-variable var)
528528
(eval (cdr (assq var ess-r-customize-alist)))))
529529
vars))
530-
(add-hook 'project-find-functions #'ess-r-project)
530+
(add-hook 'project-find-functions #'ess-r-project nil 'local)
531531
(run-hooks 'ess-r-package-enter-hook))
532532
(remove-hook 'project-find-functions #'ess-r-project)
533533
(run-hooks 'ess-r-package-exit-hook)))

lisp/ess-sp6-d.el

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@
7676
(inferior-ess-help-command . "help(\"%s\", pager=\"slynx -dump\", window=FALSE)\n")
7777
(inferior-ess-search-list-command . "searchPaths()\n")
7878

79-
(ess-directory-function . S+-directory-function)
80-
(ess-setup-directory-function . S+-setup-directory-function)
79+
(ess-startup-directory-function . S+-directory-function)
8180
(ess-STERM . "iESS"))
8281
S+common-cust-alist)
8382

0 commit comments

Comments
 (0)