Skip to content

Commit ee2716b

Browse files
ardumontchrisdone
authored andcommitted
Refactor to use only a haskell-process-wrapper-function.
Following this discussion - #370 (comment). This permits to one's own wrapper function. For example, here is one to use with nix-shell: ```sh (custom-set-variables '(haskell-process-wrapper-function (lambda (argv) (append (list "nix-shell" "default.nix" "--command" ) (list (shell-quote-argument (mapconcat 'identity argv " "))))))) ``` Unit tests are ok. Need to test in real life now. Tests removed.
1 parent ba4990e commit ee2716b

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

haskell-process.el

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -111,29 +111,15 @@ See `haskell-process-do-cabal' for more details."
111111
:type '(choice (const auto) (const ghci) (const cabal-repl) (const cabal-dev) (const cabal-ghci))
112112
:group 'haskell-interactive)
113113

114-
(defcustom haskell-process-wrapper
115-
nil
116-
"A wrapper to launch the Haskell process defined by `haskell-process-type`.
117-
Nix users may want to use the value (\"nix-shell\" \"--command\"),
118-
Docker users may want to use something like \"run-my-docker\"."
119-
:group 'haskell-interactive
120-
:type '(choice string (repeat string)))
114+
(defcustom haskell-process-wrapper-function
115+
#'identity
116+
"A default wrapper function to deal with an eventual haskell-process-wrapper.
121117
122-
(defun haskell-process-stringify-cmd (cmd &optional args)
123-
"Stringify the CMD with optional ARGS."
124-
(format "%s" (mapconcat 'identity (cons cmd args) " ")))
125-
126-
(defun haskell-process-wrapper-command (cmd &optional cmd-args)
127-
"Compute the haskell command to execute to launch the haskell-process type.
128-
if haskell-process-wrapper is set, return a wrapper of the CMD as list.
129-
Otherwise, return CMD as list.
130-
Deal with optional CMD-ARGS for the CMD."
131-
(if haskell-process-wrapper
132-
(let ((wrapped-cmd (haskell-process-stringify-cmd cmd cmd-args)))
133-
(if (stringp haskell-process-wrapper)
134-
(list haskell-process-wrapper wrapped-cmd)
135-
(append haskell-process-wrapper (list wrapped-cmd))))
136-
(cons cmd cmd-args)))
118+
If no wrapper is needed, then using 'identify function is sufficient.
119+
Otherwise, define a function which takes a list of arguments.
120+
For example: (lambda (argv)
121+
(append '(\"nix-shell\" \"haskell-lab.nix\" \"--command\")
122+
(shell-quote-argument argv)))")
137123

138124
(defcustom haskell-process-log
139125
nil
@@ -1044,25 +1030,25 @@ HPTYPE is the result of calling `'haskell-process-type`' function."
10441030
(append (list (format "Starting inferior GHCi process %s ..." haskell-process-path-ghci)
10451031
session-name
10461032
nil)
1047-
(haskell-process-wrapper-command haskell-process-path-ghci haskell-process-args-ghci)))
1033+
(apply haskell-process-wrapper-function (list (cons haskell-process-path-ghci haskell-process-args-ghci)))))
10481034
('cabal-repl
10491035
(append (list (format "Starting inferior `cabal repl' process using %s ..." haskell-process-path-cabal)
10501036
session-name
10511037
nil)
1052-
(haskell-process-wrapper-command haskell-process-path-cabal (cons "repl" haskell-process-args-cabal-repl))
1038+
(apply haskell-process-wrapper-function (list (cons haskell-process-path-cabal (cons "repl" haskell-process-args-cabal-repl))))
10531039
(let ((target (haskell-session-target session)))
10541040
(if target (list target) nil))))
10551041
('cabal-ghci
10561042
(append (list (format "Starting inferior cabal-ghci process using %s ..." haskell-process-path-cabal-ghci)
10571043
session-name
10581044
nil)
1059-
(haskell-process-wrapper-command haskell-process-path-cabal-ghci)))
1045+
(apply haskell-process-wrapper-function (list (list haskell-process-path-cabal-ghci)))))
10601046
('cabal-dev
10611047
(let ((dir (concat (haskell-session-cabal-dir session) "/cabal-dev")))
10621048
(append (list (format "Starting inferior cabal-dev process %s -s %s ..." haskell-process-path-cabal-dev dir)
10631049
session-name
10641050
nil)
1065-
(haskell-process-wrapper-command haskell-process-path-cabal-dev (list "ghci" "-s" dir))))))))
1051+
(apply haskell-process-wrapper-function (list (cons haskell-process-path-cabal-dev (list "ghci" "-s" dir))))))))))
10661052

10671053
;;;###autoload
10681054
(defun haskell-process-start (session)

0 commit comments

Comments
 (0)