diff --git a/haskell-process.el b/haskell-process.el index a71ff684a..534e5ea48 100644 --- a/haskell-process.el +++ b/haskell-process.el @@ -104,9 +104,9 @@ See `haskell-process-do-cabal' for more details." :type 'string) (defcustom haskell-process-type - 'ghci + 'auto "The inferior Haskell process type to use." - :type '(choice (const ghci) (const cabal-repl) (const cabal-dev) (const cabal-ghci)) + :type '(choice (const auto) (const ghci) (const cabal-repl) (const cabal-dev) (const cabal-ghci)) :group 'haskell-interactive) (defcustom haskell-process-log @@ -507,7 +507,7 @@ for various things, but is optional." "Add /dist/build/autogen/ to the ghci search path. This allows modules such as 'Path_...', generated by cabal, to be loaded by ghci." - (unless (eq 'cabal-repl haskell-process-type) ;; redundant with "cabal repl" + (unless (eq 'cabal-repl (haskell-process-type)) ;; redundant with "cabal repl" (let* ((session (haskell-session)) (cabal-dir (haskell-session-cabal-dir session)) @@ -516,6 +516,17 @@ to be loaded by ghci." (haskell-process) (format ":set -i%s" ghci-gen-dir))))) +(defun haskell-process-type () + "Return `haskell-process-type', or a guess if that variable is 'auto." + (if (eq 'auto haskell-process-type) + (if (locate-dominating-file default-directory + (lambda (f) + (or (string= ".cabal-sandbox" f) + (string-match-p "\\.cabal\\'" f)))) + 'cabal-repl + 'ghci) + haskell-process-type)) + (defun haskell-process-do-cabal (command) "Run a Cabal command." (let ((process (haskell-process))) @@ -531,7 +542,7 @@ to be loaded by ghci." (format haskell-process-do-cabal-format-string (haskell-session-cabal-dir (car state)) (format "%s %s" - (cl-ecase haskell-process-type + (cl-ecase (haskell-process-type) ('ghci haskell-process-path-cabal) ('cabal-repl haskell-process-path-cabal) ('cabal-ghci haskell-process-path-cabal) @@ -574,7 +585,7 @@ to be loaded by ghci." (notifications-notify :title (format "*%s*" (haskell-session-name (car state))) :body msg - :app-name (cl-ecase haskell-process-type + :app-name (cl-ecase (haskell-process-type) ('ghci haskell-process-path-cabal) ('cabal-repl haskell-process-path-cabal) ('cabal-ghci haskell-process-path-cabal) @@ -1006,7 +1017,7 @@ now." (haskell-session-pwd session) (haskell-process-set-process process - (cl-ecase haskell-process-type + (cl-ecase (haskell-process-type) ('ghci (haskell-process-log (propertize (format "Starting inferior GHCi process %s ..." @@ -1057,7 +1068,7 @@ now." (progn (set-process-sentinel (haskell-process-process process) 'haskell-process-sentinel) (set-process-filter (haskell-process-process process) 'haskell-process-filter)) (haskell-process-send-startup process) - (unless (eq 'cabal-repl haskell-process-type) ;; "cabal repl" sets the proper CWD + (unless (eq 'cabal-repl (haskell-process-type)) ;; "cabal repl" sets the proper CWD (haskell-process-change-dir session process (haskell-session-current-dir session))) diff --git a/haskell-session.el b/haskell-session.el index b31f3645b..5bb117caf 100644 --- a/haskell-session.el +++ b/haskell-session.el @@ -36,9 +36,7 @@ (declare-function haskell-kill-session-process "haskell-process" (&optional session)) (declare-function haskell-process-start "haskell-process" (session)) (declare-function haskell-process-cd "haskell-process" (&optional not-interactive)) - -;; Dynamically scoped variables. -(defvar haskell-process-type) +(declare-function haskell-process-type "haskell-process" ()) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Configuration @@ -85,11 +83,10 @@ If DONTCREATE is non-nil don't create a new session." ;; ;; Ugliness aside, if it saves us time to type it's a winner. ;; - ;; FIXME/TODO: add support for (eq 'cabal-repl haskell-process-type) - (require 'haskell-process) ; hack for accessing haskell-process-type + ;; FIXME/TODO: add support for (eq 'cabal-repl (haskell-process-type)) (let ((modules (shell-command-to-string (format "%s | %s | %s" - (if (eq 'cabal-dev haskell-process-type) + (if (eq 'cabal-dev (haskell-process-type)) (if (or (not dontcreate) (haskell-session-maybe)) (format "cabal-dev -s %s/cabal-dev ghc-pkg dump" (haskell-session-cabal-dir (haskell-session)))