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

Customize starting directory for utop #472

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
27 changes: 24 additions & 3 deletions src/top/utop.el
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ with Emacs to provide an enhanced environment."
:type 'string
:safe 'stringp)

(defcustom utop-starting-directory 'current-directory
"Directory in which utop will be started.

Can be the `current-directory' (default) to use the current buffer's directory or
`project-root' to use the project root as implied by project.el. For most
users, `current-directory' is completely sufficient.
However, if using an .ocamlinit file in the root directory,
it may be desirable to run the project from the root directory."

:type '(choice (const :tag "Project root" project-root)
(const :tag "Current directory" current-directory)))

(defcustom utop-edit-command t
"Whether to read the command from the minibuffer before running utop.

Expand Down Expand Up @@ -1073,9 +1085,18 @@ defaults to 0."
;; Set the state to done to allow utop to be restarted if
;; start-process fails
(setq utop-state 'done)

;; Create the sub-process
(setq utop-process (apply 'start-process "utop" (current-buffer) (car arguments) (cdr arguments)))
(let ((default-directory
(cond ((eq utop-starting-directory 'project-root)
(if (project-current)
(project-root (project-current))
(error "`utop-starting-directory' is set to project-root but not currently inside a project")))
((eq utop-starting-directory 'current-directory)
default-directory)
(t
(error "Wrong value for `utop-starting-directory', please check this variable documentation and set it to a proper value")))))

;; Create the sub-process
(setq utop-process (apply 'start-process "utop" (current-buffer) (car arguments) (cdr arguments))))

;; Set the initial state: we are waiting for ocaml to send the
;; initial prompt
Expand Down