Skip to content

Commit 1a16c90

Browse files
Added nix-shell-ghci and nix-shell-cabal-repl support.
1 parent f23adae commit 1a16c90

File tree

1 file changed

+91
-59
lines changed

1 file changed

+91
-59
lines changed

haskell-process.el

Lines changed: 91 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@
7878
:group 'haskell-interactive
7979
:type '(choice string (repeat string)))
8080

81+
(defcustom haskell-process-path-nix-shell
82+
"nix-shell"
83+
"The path for starting nix-shell."
84+
:group 'haskell-interactive
85+
:type '(choice string (repeat string)))
86+
87+
(defcustom haskell-process-args-nix-shell
88+
'("shell.nix")
89+
"The path for starting nix-shell."
90+
:group 'haskell-interactive
91+
:type '(choice string (repeat string)))
92+
93+
8194
(defcustom haskell-process-args-ghci
8295
'("-ferror-spans")
8396
"Any arguments for starting ghci."
@@ -106,7 +119,8 @@ See `haskell-process-do-cabal' for more details."
106119
(defcustom haskell-process-type
107120
'auto
108121
"The inferior Haskell process type to use."
109-
:type '(choice (const auto) (const ghci) (const cabal-repl) (const cabal-dev) (const cabal-ghci))
122+
:type '(choice (const auto) (const ghci) (const cabal-repl) (const cabal-dev) (const cabal-ghci)
123+
(const nix-shell-ghci) (const nix-shell-cabal-repl)
110124
:group 'haskell-interactive)
111125

112126
(defcustom haskell-process-log
@@ -507,7 +521,9 @@ for various things, but is optional."
507521
"Add <cabal-project-dir>/dist/build/autogen/ to the ghci search
508522
path. This allows modules such as 'Path_...', generated by cabal,
509523
to be loaded by ghci."
510-
(unless (eq 'cabal-repl (haskell-process-type)) ;; redundant with "cabal repl"
524+
(unless (or (eq 'cabal-repl haskell-process-type) ;; redundant with "cabal repl"
525+
(eq 'nix-shell-ghci haskell-process-type)
526+
(eq 'nix-shell-cabal-repl haskell-process-type))
511527
(let*
512528
((session (haskell-session))
513529
(cabal-dir (haskell-session-cabal-dir session))
@@ -541,13 +557,25 @@ to be loaded by ghci."
541557
(cadr state)
542558
(format haskell-process-do-cabal-format-string
543559
(haskell-session-cabal-dir (car state))
544-
(format "%s %s"
545-
(cl-ecase (haskell-process-type)
560+
(format "%s %s %s"
561+
(cl-ecase haskell-process-type
546562
('ghci haskell-process-path-cabal)
547563
('cabal-repl haskell-process-path-cabal)
548564
('cabal-ghci haskell-process-path-cabal)
549-
('cabal-dev haskell-process-path-cabal-dev))
550-
(cl-caddr state)))))
565+
('cabal-dev haskell-process-path-cabal-dev)
566+
('nix-shell-ghci (concat haskell-process-path-nix-shell
567+
" "
568+
haskell-process-args-nix-shell
569+
" --command '"))
570+
('nix-shell-cabal-repl (concat haskell-process-path-nix-shell
571+
" "
572+
haskell-process-args-nix-shell
573+
" --command '")))
574+
(caddr state)
575+
(case haskell-process-type
576+
('nix-shell-ghci "'")
577+
('nix-shell-cabal-repl "'")
578+
(t ""))))))
551579

552580
:live
553581
(lambda (state buffer)
@@ -589,7 +617,9 @@ to be loaded by ghci."
589617
('ghci haskell-process-path-cabal)
590618
('cabal-repl haskell-process-path-cabal)
591619
('cabal-ghci haskell-process-path-cabal)
592-
('cabal-dev haskell-process-path-cabal-dev))
620+
('cabal-dev haskell-process-path-cabal-dev)
621+
('nix-shell-ghci haskell-process-path-nix-shell)
622+
('nix-shell-cabal-repl haskell-process-path-nix-shell))
593623
:app-icon haskell-process-logo
594624
)))))))))
595625

@@ -1016,58 +1046,60 @@ now."
10161046
(haskell-process-set-session process session)
10171047
(haskell-process-set-cmd process nil)
10181048
(haskell-process-set (haskell-session-process session) 'is-restarting nil)
1019-
(let ((default-directory (haskell-session-cabal-dir session)))
1020-
(haskell-session-pwd session)
1021-
(haskell-process-set-process
1022-
process
1023-
(cl-ecase (haskell-process-type)
1024-
('ghci
1025-
(haskell-process-log
1026-
(propertize (format "Starting inferior GHCi process %s ..."
1027-
haskell-process-path-ghci)
1028-
'face font-lock-comment-face))
1029-
(apply #'start-process
1030-
(append (list (haskell-session-name session)
1031-
nil
1032-
haskell-process-path-ghci)
1033-
haskell-process-args-ghci)))
1034-
('cabal-repl
1035-
(haskell-process-log
1036-
(propertize
1037-
(format "Starting inferior `cabal repl' process using %s ..."
1038-
haskell-process-path-cabal)
1039-
'face font-lock-comment-face))
1040-
1041-
(apply #'start-process
1042-
(append (list (haskell-session-name session)
1043-
nil
1044-
haskell-process-path-cabal)
1045-
'("repl") haskell-process-args-cabal-repl
1046-
(let ((target (haskell-session-target session)))
1047-
(if target (list target) nil)))))
1048-
('cabal-ghci
1049-
(haskell-process-log
1050-
(propertize
1051-
(format "Starting inferior cabal-ghci process using %s ..."
1052-
haskell-process-path-cabal-ghci)
1053-
'face font-lock-comment-face))
1054-
(start-process (haskell-session-name session)
1055-
nil
1056-
haskell-process-path-cabal-ghci))
1057-
('cabal-dev
1058-
(let ((dir (concat (haskell-session-cabal-dir session)
1059-
"/cabal-dev")))
1060-
(haskell-process-log
1061-
(propertize (format "Starting inferior cabal-dev process %s -s %s ..."
1062-
haskell-process-path-cabal-dev
1063-
dir)
1064-
'face font-lock-comment-face))
1065-
(start-process (haskell-session-name session)
1066-
nil
1067-
haskell-process-path-cabal-dev
1068-
"ghci"
1069-
"-s"
1070-
dir))))))
1049+
(let ((default-directory (haskell-session-cabal-dir session))
1050+
(targetl (let ((target (haskell-session-target session)))
1051+
(if target (list target) nil))))
1052+
(cl-flet* ((prog-args (prognm args)
1053+
(append (list (haskell-session-name session)
1054+
nil
1055+
prognm)
1056+
args))
1057+
(my-start-process (prognm args)
1058+
(apply #'start-process (prog-args prognm args)))
1059+
(my-log (s)
1060+
(haskell-process-log
1061+
(propertize s 'face font-lock-comment-face))))
1062+
(haskell-session-pwd session)
1063+
(haskell-process-set-process
1064+
process
1065+
(cl-ecase haskell-process-type
1066+
('ghci
1067+
(my-log (format "Starting inferior GHCi process %s ..."
1068+
haskell-process-path-ghci))
1069+
(my-start-process haskell-process-path-ghci haskell-process-args-ghci))
1070+
('cabal-repl
1071+
(my-log (format "Starting inferior `cabal repl' process using %s ..."
1072+
haskell-process-path-cabal))
1073+
1074+
(my-start-process haskell-process-path-cabal
1075+
(append '("repl") haskell-process-args-cabal-repl targetl)))
1076+
('cabal-ghci
1077+
(my-log (format "Starting inferior cabal-ghci process using %s ..."
1078+
haskell-process-path-cabal-ghci))
1079+
(my-start-process haskell-process-path-cabal-ghci nil))
1080+
('cabal-dev
1081+
(let ((dir (concat (haskell-session-cabal-dir session)
1082+
"/cabal-dev")))
1083+
(my-log (format "Starting inferior cabal-dev process %s -s %s ..."
1084+
haskell-process-path-cabal-dev
1085+
dir))
1086+
(my-start-process haskell-process-path-cabal-dev
1087+
(list "ghci" "-s" dir))))
1088+
('nix-shell-ghci
1089+
(let ((args (append haskell-process-args-nix-shell
1090+
'("--command")
1091+
(list haskell-process-path-ghci)
1092+
(let ((target (haskell-session-target session)))
1093+
(if target (list target) nil)))))
1094+
(my-log (format "Starting inferior nix-shell (ghci) process using %s..."
1095+
(mapconcat 'identity args "' '")))
1096+
(my-start-process haskell-process-path-nix-shell args)))
1097+
('nix-shell-cabal-repl
1098+
(let ((args (append haskell-process-args-nix-shell
1099+
'("--command" "cabal repl"))))
1100+
(my-log (format "Starting inferior nix-shell (cabal repl) process using %s..."
1101+
(mapconcat 'identity args "' '")))
1102+
(my-start-process haskell-process-path-nix-shell args)))))))
10711103
(progn (set-process-sentinel (haskell-process-process process) 'haskell-process-sentinel)
10721104
(set-process-filter (haskell-process-process process) 'haskell-process-filter))
10731105
(haskell-process-send-startup process)

0 commit comments

Comments
 (0)