Skip to content

Commit a57ee43

Browse files
committed
Add support for Spago, and define custom vars for helper program paths
1 parent 2b210b4 commit a57ee43

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

psci.el

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@
6464
:group 'psci
6565
:type 'string)
6666

67+
(defcustom psci/psc-package-path "psc-package"
68+
"Path to the `psc-package' binary."
69+
:group 'psci
70+
:type 'string)
71+
72+
(defcustom psci/spago-path "spago"
73+
"Path to the `spago' binary."
74+
:group 'psci
75+
:type 'string)
76+
6777
(defcustom psci/arguments '("src/**/*.purs" "bower_components/purescript-*/src/**/*.purs")
6878
"Commandline arguments to pass to `psci' function."
6979
:group 'psci
@@ -111,8 +121,19 @@ When FILENAME is nil or not a real file, returns nil."
111121
(match-string 1))))
112122

113123
(defun psci/--get-psc-package-sources! ()
114-
(when (file-exists-p "psc-package.json")
115-
(split-string (shell-command-to-string "psc-package sources"))))
124+
(cond
125+
((file-exists-p "psc-package.json")
126+
(process-lines (psci/--executable-find-relative psci/psc-package-path) "sources"))
127+
((file-exists-p "spago.dhall")
128+
(process-lines (psci/--executable-find-relative psci/spago-path) "sources"))))
129+
130+
(defun psci/--executable-find-relative (path)
131+
"If PATH is a relative path to an executable, return its full path.
132+
Otherwise, just return PATH."
133+
(let ((relative (expand-file-name path)))
134+
(if (file-executable-p relative)
135+
relative
136+
path)))
116137

117138
;; public functions
118139

@@ -122,7 +143,9 @@ When FILENAME is nil or not a real file, returns nil."
122143
Relies on .psci file for determining the project's root folder."
123144
(interactive (list (read-directory-name "Project root? "
124145
(psci/--project-root!))))
125-
(let* ((psci-program psci/purs-path)
146+
(let* ((default-directory project-root-folder)
147+
(psci-program psci/purs-path)
148+
(extra-sources (psci/--get-psc-package-sources!))
126149
(buffer (comint-check-proc psci/buffer-name)))
127150
;; pop to the "*psci*" buffer if the process is dead, the
128151
;; buffer is missing or it's got the wrong mode.
@@ -133,10 +156,7 @@ Relies on .psci file for determining the project's root folder."
133156
(current-buffer)))
134157
;; create the comint process if there is no buffer.
135158
(unless buffer
136-
(setq default-directory project-root-folder)
137-
(let ((full-arg-list (-if-let (psc-package-sources (psci/--get-psc-package-sources!))
138-
(append psci/arguments psc-package-sources)
139-
psci/arguments)))
159+
(let ((full-arg-list (append psci/arguments extra-sources)))
140160
(apply 'make-comint-in-buffer psci/buffer-name buffer
141161
psci-program nil "repl" full-arg-list))
142162
(psci-mode))))

0 commit comments

Comments
 (0)