Skip to content

Commit 63cc0fd

Browse files
committed
Small fixes to (haskell-compile)
Don't reuse cabal or stack command when project dir has changed. When haskell-compiler-type is stack or cabal, and no stack or cabal file was found, run in default-directory. Stack or cabal will fail with appropriate error.
1 parent d004bb8 commit 63cc0fd

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

haskell-compile.el

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,20 @@ base directory for build tools, or the current buffer for
209209
haskell-compile-command
210210
haskell-compile-command)))))
211211

212+
;; Save commands for reuse, but only when in same context.
213+
;; Hence save a pair (COMMAND . DIR); or nil.
212214
(defvar haskell--compile-stack-last nil)
213215
(defvar haskell--compile-cabal-last nil)
214216
(defvar haskell--compile-ghc-last nil)
215217

218+
;; called only by (haskell-compile):
216219
(defun haskell--compile (dir-or-file edit last-sym fallback alt)
217-
(let* ((default (or (symbol-value last-sym) fallback))
220+
(let* ((dir-or-file (or dir-or-file default-directory))
221+
(last-pair (symbol-value last-sym))
222+
(last-command (car last-pair))
223+
(last-dir (cdr last-pair))
224+
(default (or (and last-dir (eq last-dir dir-or-file) last-command)
225+
fallback))
218226
(template (cond
219227
((null edit) default)
220228
((eq edit '-) alt)
@@ -227,7 +235,7 @@ base directory for build tools, or the current buffer for
227235
(file-name-base (directory-file-name dir-or-file))
228236
(file-name-nondirectory dir-or-file))))
229237
(unless (eq edit'-)
230-
(set last-sym template))
238+
(set last-sym (cons template dir-or-file)))
231239
(let ((default-directory dir))
232240
(compilation-start
233241
command

haskell-customize.el

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,18 @@ Used for locating additional package data files.")
5454
5555
When set to 'auto (the default), the directory contents and
5656
available programs will be used to make a best guess at the
57-
process type:
57+
process type and the project directory.
5858
59-
If the project directory or one of its parents contains a
60-
\"cabal.sandbox.config\" file, then cabal-repl will be used.
59+
Emacs looks in the current directory and then in its parents for
60+
a file \"cabal.sandbox.config\" or \"cabal.project\". its
61+
location is the project directory, and \"cabal\" will be used.
6162
62-
If there's a \"stack.yaml\" file and the \"stack\" executable can
63-
be located, then stack-ghci will be used.
63+
Otherwise if a file \"stack.yaml\" is found, its location is the
64+
project directory, and stack will be used
65+
Otherwise if a file \"*.cabal\" is found, its location is the
66+
project directory, and cabal will be used.
67+
If none of the above apply, ghc will be used.
6468
65-
Otherwise if there's a *.cabal file, cabal-repl will be used.
66-
If none of the above apply, ghci will be used.
6769
(The value cabal-new-repl is obsolete, equivalent to cabal-repl)."
6870
:type '(choice (const auto)
6971
(const ghci)
@@ -423,7 +425,7 @@ presence of a *.cabal file or stack.yaml file or something similar.")
423425
When found, returns a pair (TAG . DIR)
424426
where TAG is 'cabal-project, 'cabal-sandbox. 'cabal, or 'stack;
425427
and DIR is the directory containing cabal or stack file.
426-
When none found, DIR is nil, and TAG is 'cabal, 'stack. or 'ghc"
428+
When none found, DIR is nil, and TAG is 'ghc"
427429
;; REVIEW maybe just 'cabal is enough.
428430
(let ((cabal-project (locate-dominating-file default-directory "cabal.project"))
429431
(cabal-sandbox (locate-dominating-file default-directory "cabal.sandbox.config"))
@@ -438,7 +440,7 @@ presence of a *.cabal file or stack.yaml file or something similar.")
438440
((and cabal-project (executable-find "cabal"))
439441
(cons 'cabal-project cabal-project))
440442
((and cabal-sandbox (executable-find "cabal"))
441-
(cons 'cabal cabal-sandbox))
443+
(cons 'cabal-sandbox cabal-sandbox))
442444
((and stack (executable-find "stack"))
443445
(cons 'stack stack))
444446
((and cabal (executable-find "cabal"))

0 commit comments

Comments
 (0)