Skip to content

Commit cef77bf

Browse files
Added nix-shell-ghci support.
1 parent b214d30 commit cef77bf

File tree

1 file changed

+48
-7
lines changed

1 file changed

+48
-7
lines changed

haskell-process.el

Lines changed: 48 additions & 7 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+
'("nix/devel.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
'ghci
108121
"The inferior Haskell process type to use."
109-
:type '(choice (const ghci) (const cabal-repl) (const cabal-dev) (const cabal-ghci))
122+
:type '(choice (const ghci) (const cabal-repl) (const cabal-dev)
123+
(const cabal-ghci) (const nix-shell-ghci))
110124
:group 'haskell-interactive)
111125

112126
(defcustom haskell-process-log
@@ -504,7 +518,8 @@ for various things, but is optional."
504518
"Add <cabal-project-dir>/dist/build/autogen/ to the ghci search
505519
path. This allows modules such as 'Path_...', generated by cabal,
506520
to be loaded by ghci."
507-
(unless (eq 'cabal-repl haskell-process-type) ;; redundant with "cabal repl"
521+
(unless (or (eq 'cabal-repl haskell-process-type) ;; redundant with "cabal repl"
522+
(eq 'nix-shell-ghci haskell-process-type))
508523
(let*
509524
((session (haskell-session))
510525
(cabal-dir (haskell-session-cabal-dir session))
@@ -527,13 +542,20 @@ to be loaded by ghci."
527542
(cadr state)
528543
(format haskell-process-do-cabal-format-string
529544
(haskell-session-cabal-dir (car state))
530-
(format "%s %s"
545+
(format "%s %s %s"
531546
(ecase haskell-process-type
532547
('ghci haskell-process-path-cabal)
533548
('cabal-repl haskell-process-path-cabal)
534549
('cabal-ghci haskell-process-path-cabal)
535-
('cabal-dev haskell-process-path-cabal-dev))
536-
(caddr state)))))
550+
('cabal-dev haskell-process-path-cabal-dev)
551+
('nix-shell-ghci (concat haskell-process-path-nix-shell
552+
" "
553+
haskell-process-args-nix-shell
554+
" --command '")))
555+
(caddr state)
556+
(case haskell-process-type
557+
('nix-shell-ghci "'")
558+
(t ""))))))
537559

538560
:live
539561
(lambda (state buffer)
@@ -575,7 +597,8 @@ to be loaded by ghci."
575597
('ghci haskell-process-path-cabal)
576598
('cabal-repl haskell-process-path-cabal)
577599
('cabal-ghci haskell-process-path-cabal)
578-
('cabal-dev haskell-process-path-cabal-dev))
600+
('cabal-dev haskell-process-path-cabal-dev)
601+
('nix-shell-ghci haskell-process-path-nix-shell))
579602
:app-icon haskell-process-logo
580603
)))))))))
581604

@@ -1050,7 +1073,25 @@ now."
10501073
haskell-process-path-cabal-dev
10511074
"ghci"
10521075
"-s"
1053-
dir))))))
1076+
dir)))
1077+
('nix-shell-ghci
1078+
(haskell-process-log
1079+
(propertize
1080+
(format "Starting inferior nix-shell (ghci) process using %s %s %s %s..."
1081+
haskell-process-path-nix-shell
1082+
haskell-process-args-nix-shell
1083+
"--command"
1084+
haskell-process-path-ghci)
1085+
'face font-lock-comment-face))
1086+
(apply #'start-process
1087+
(append (list (haskell-session-name session)
1088+
nil
1089+
haskell-process-path-nix-shell)
1090+
haskell-process-args-nix-shell
1091+
'("--command")
1092+
(list haskell-process-path-ghci)
1093+
(let ((target (haskell-session-target session)))
1094+
(if target (list target) nil))))))))
10541095
(progn (set-process-sentinel (haskell-process-process process) 'haskell-process-sentinel)
10551096
(set-process-filter (haskell-process-process process) 'haskell-process-filter))
10561097
(haskell-process-send-startup process)

0 commit comments

Comments
 (0)