Skip to content

Support 'auto for haskell-process-type, and make it the default #352

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

Merged
merged 1 commit into from
Oct 8, 2014
Merged
Show file tree
Hide file tree
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
25 changes: 18 additions & 7 deletions haskell-process.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -507,7 +507,7 @@ for various things, but is optional."
"Add <cabal-project-dir>/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))
Expand All @@ -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)))
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 ..."
Expand Down Expand Up @@ -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)))
Expand Down
9 changes: 3 additions & 6 deletions haskell-session.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down