haskell/haskell-mode — pull request #370 by ardumont (2014-11-10 23:12:42+00:00)
Title: Add haskell-process-wrapper

Following this [PR](https://github.com/haskell/haskell-mode/pull/350)
and [its possible improvment](https://github.com/haskell/haskell-mode/pull/350#issuecomment-59434038),
I added the `haskell-process-wrapper`.

This permits to launch the haskell-process-type function inside a
wrapper command (nix-shell for example, or others).

For example, using this:

```elisp
(custom-set-variables '(haskell-process-wrapper '("nix-shell"
"default.nix" "--command"))
'(haskell-process-type 'cabal-repl))
```

This triggers the cabal-repl inside the nix-shell (defined within the
default.nix expression).

I tested manually with:
- haskell-process-wrapper (for nix-shell as above) with
haskell-process-type in '(cabal-repl cabal-ghci ghci)
- haskell-process-wrapper nil (the default) and haskell-process-type
in (cabal-repl cabal-ghci ghci).

The code is generic, so this should work for the other commands that
@chrisdone mentioned.

*Note*
I added unit tests (to enforce that I did not break anything) and I
needed mocks (I added the deps inside the haskell-process-tests.el file
but this must not be what you want. If you have any suggestions on how
to improve this, I'm all for it).

Tests output:

```sh
$ make check
building clean
rm -f ghc-core.elc haskell-align-imports.elc haskell-c.elc
haskell-cabal.elc haskell-checkers.elc haskell-compat.elc
haskell-compile.elc haskell-decl-scan.elc haskell-doc.elc
haskell-font-lock.elc haskell-indent.elc haskell-indentation.elc
haskell-collapse.elc haskell-interactive-mode.elc haskell-menu.elc
haskell-mode.elc haskell-move-nested.elc haskell-navigate-imports.elc
haskell-package.elc haskell-complete-module.elc haskell-process.elc
haskell-session.elc haskell-show.elc haskell-simple-indent.elc
haskell-sort-imports.elc haskell-string.elc haskell-str.elc
haskell-unicode-input-method.elc haskell-utils.elc haskell-yas.elc
haskell-presentation-mode.elc inf-haskell.elc haskell-mode-autoloads.el
haskell-mode-autoloads.elc haskell-mode-13.10.tar haskell-mode.tmp.texi
haskell-mode.info dir
building check-ghc-core
Checking ghc-core.el...
Scanning ghc-core.el...
Scanning ghc-core.el...done
Checking ghc-core.el...OK
Wrote /home/tony/repo/perso/haskell-mode/ghc-core.elc
--
building check-haskell-align-imports
Checking haskell-align-imports.el...
Scanning haskell-align-imports.el...
Scanning haskell-align-imports.el...done
Checking haskell-align-imports.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-align-imports.elc
--
building check-haskell-c
Checking haskell-c.el...
Scanning haskell-c.el...
Scanning haskell-c.el...done
Checking haskell-c.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-c.elc
--
building check-haskell-cabal
Checking haskell-cabal.el...
Scanning haskell-cabal.el...
Scanning haskell-cabal.el...done
Checking haskell-cabal.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-cabal.elc
--
building check-haskell-checkers
Checking haskell-checkers.el...
Scanning haskell-checkers.el...
Scanning haskell-checkers.el...done
Checking haskell-checkers.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-checkers.elc
--
building check-haskell-compat
Checking haskell-compat.el...
Scanning haskell-compat.el...
Scanning haskell-compat.el...done
Checking haskell-compat.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-compat.elc
--
building check-haskell-compile
Checking haskell-compile.el...
Scanning haskell-compile.el...
Scanning haskell-compile.el...done
Checking haskell-compile.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-compile.elc
--
building check-haskell-decl-scan
Checking haskell-decl-scan.el...
Scanning haskell-decl-scan.el...
Scanning haskell-decl-scan.el...done
Checking haskell-decl-scan.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-decl-scan.elc
--
building check-haskell-doc
Checking haskell-doc.el...
Scanning haskell-doc.el...
Scanning haskell-doc.el...done
Checking haskell-doc.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-doc.elc
--
building check-haskell-font-lock
Checking haskell-font-lock.el...
Scanning haskell-font-lock.el...
Scanning haskell-font-lock.el...done
Checking haskell-font-lock.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-font-lock.elc
--
building check-haskell-indent
Checking haskell-indent.el...
Scanning haskell-indent.el...
Scanning haskell-indent.el...done
Checking haskell-indent.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-indent.elc
--
building check-haskell-indentation
Checking haskell-indentation.el...
Scanning haskell-indentation.el...
Scanning haskell-indentation.el...done
Checking haskell-indentation.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-indentation.elc
--
building check-haskell-collapse
Checking haskell-collapse.el...
Scanning haskell-collapse.el...
Scanning haskell-collapse.el...done
Checking haskell-collapse.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-collapse.elc
--
building check-haskell-interactive-mode
Checking haskell-interactive-mode.el...
Scanning haskell-interactive-mode.el...
Scanning haskell-interactive-mode.el...done
Checking haskell-interactive-mode.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-interactive-mode.elc
--
building check-haskell-menu
Checking haskell-menu.el...
Scanning haskell-menu.el...
Scanning haskell-menu.el...done
Checking haskell-menu.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-menu.elc
--
building check-haskell-mode
Checking haskell-mode.el...
Scanning haskell-mode.el...
Malformed declaration for `haskell-process-queue-sync-request'
Scanning haskell-mode.el...done
Checking /home/tony/repo/perso/haskell-mode/haskell-process.el...
Checking /home/tony/repo/perso/haskell-mode/haskell-process.el...OK
Checking /home/tony/repo/perso/haskell-mode/haskell-session.el...
Checking /home/tony/repo/perso/haskell-mode/haskell-session.el...OK
Checking haskell-mode.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-mode.elc

Running 17 tests (2014-11-10 23:11:57+0000)
passed 1/17 constructor
passed 2/17 empty
passed 3/17 in-commas
passed 4/17 in-string
passed 5/17 prime
passed 6/17 prime2
passed 7/17 prime3
passed 8/17 prime4
passed 9/17 prime5
passed 10/17 prime6
passed 11/17 single
passed 12/17 underscore
passed 13/17 underscore2
passed 14/17 underscore3
passed 15/17 unicode
passed 16/17 unicode2
passed 17/17 var

Ran 17 tests, 17 results as expected (2014-11-10 23:11:57+0000)

--
building check-haskell-move-nested
Checking haskell-move-nested.el...
Scanning haskell-move-nested.el...
Scanning haskell-move-nested.el...done
Checking haskell-move-nested.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-move-nested.elc
--
building check-haskell-navigate-imports
Checking haskell-navigate-imports.el...
Scanning haskell-navigate-imports.el...
Scanning haskell-navigate-imports.el...done
Checking haskell-navigate-imports.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-navigate-imports.elc
--
building check-haskell-package
Checking haskell-package.el...
Scanning haskell-package.el...
Scanning haskell-package.el...done
Checking haskell-package.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-package.elc
--
building check-haskell-complete-module
Checking haskell-complete-module.el...
Scanning haskell-complete-module.el...
Scanning haskell-complete-module.el...done
Checking haskell-complete-module.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-complete-module.elc
--
building check-haskell-process
Checking haskell-process.el...
Scanning haskell-process.el...
Scanning haskell-process.el...done
Checking
/home/tony/repo/perso/haskell-mode/haskell-interactive-mode.el...
Checking
/home/tony/repo/perso/haskell-mode/haskell-interactive-mode.el...OK
Checking haskell-process.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-process.elc

Importing package-keyring.gpg...
Importing package-keyring.gpg...done
Contacting host: melpa.milkbox.net:80
Contacting host: melpa.milkbox.net:80
Contacting host: elpa.gnu.org:80
Running 14 tests (2014-11-10 23:12:03+0000)
passed 1/14 haskell-process-stringify-cmd-no-arg
passed 2/14 haskell-process-stringify-cmd-with-args
passed 3/14 haskell-process-wrapper-command-nil
passed 4/14
haskell-process-wrapper-command-with-repeat-string
passed 5/14
haskell-process-wrapper-command-with-string
passed 6/14
haskell-process-wrapper-command-with-string-2

passed 7/14
test-haskell-process--compute-process-log-and-command-cabal-dev

passed 8/14
test-haskell-process--compute-process-log-and-command-cabal-ghci

passed 9/14
test-haskell-process--compute-process-log-and-command-cabal-repl

passed 10/14
test-haskell-process--compute-process-log-and-command-ghci

passed 11/14
test-haskell-process--with-wrapper-compute-process-log-and-command-cabal-dev

passed 12/14
test-haskell-process--with-wrapper-compute-process-log-and-command-cabal-ghci

passed 13/14
test-haskell-process--with-wrapper-compute-process-log-and-command-cabal-repl

passed 14/14
test-haskell-process--with-wrapper-compute-process-log-and-command-ghci

Ran 14 tests, 14 results as expected (2014-11-10 23:12:03+0000)

--
building check-haskell-session
Checking haskell-session.el...
Scanning haskell-session.el...
Scanning haskell-session.el...done
Checking
/home/tony/repo/perso/haskell-mode/haskell-interactive-mode.el...
Checking
/home/tony/repo/perso/haskell-mode/haskell-interactive-mode.el...OK
Checking /home/tony/repo/perso/haskell-mode/haskell-process.el...
Checking /home/tony/repo/perso/haskell-mode/haskell-process.el...OK
Checking haskell-session.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-session.elc
--
building check-haskell-show
Checking haskell-show.el...
Scanning haskell-show.el...
Scanning haskell-show.el...done
Checking haskell-show.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-show.elc
--
building check-haskell-simple-indent
Checking haskell-simple-indent.el...
Scanning haskell-simple-indent.el...
Scanning haskell-simple-indent.el...done
Checking haskell-simple-indent.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-simple-indent.elc
--
building check-haskell-sort-imports
Checking haskell-sort-imports.el...
Scanning haskell-sort-imports.el...
Scanning haskell-sort-imports.el...done
Checking haskell-sort-imports.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-sort-imports.elc

Running 6 tests (2014-11-10 23:12:04+0000)
passed 1/6 bos-270
passed 2/6 empty-buffer
passed 3/6 file-structure
passed 4/6 single-line
passed 5/6 two-idem
passed 6/6 two-rev

Ran 6 tests, 6 results as expected (2014-11-10 23:12:04+0000)

--
building check-haskell-string
Checking haskell-string.el...
Scanning haskell-string.el...
Scanning haskell-string.el...done
Checking haskell-string.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-string.elc
--
building check-haskell-str
Checking haskell-str.el...
Scanning haskell-str.el...
Scanning haskell-str.el...done
Checking haskell-str.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-str.elc

Running 6 tests (2014-11-10 23:12:04+0000)
passed 1/6 haskell-str-ellipsize
passed 2/6 haskell-str-literal-decode-backslash
passed 3/6 haskell-str-literal-decode-empty
passed 4/6 haskell-str-literal-decode-encode
passed 5/6 haskell-str-literal-encode-empty
passed 6/6 haskell-str-take

Ran 6 tests, 6 results as expected (2014-11-10 23:12:05+0000)

--
building check-haskell-unicode-input-method
Checking haskell-unicode-input-method.el...
Scanning haskell-unicode-input-method.el...
Scanning haskell-unicode-input-method.el...done
Checking haskell-unicode-input-method.el...OK
Wrote
/home/tony/repo/perso/haskell-mode/haskell-unicode-input-method.elc
--
building check-haskell-utils
Checking haskell-utils.el...
Scanning haskell-utils.el...
Scanning haskell-utils.el...done
Checking haskell-utils.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-utils.elc
--
building check-haskell-yas
Checking haskell-yas.el...
Scanning haskell-yas.el...
Scanning haskell-yas.el...done
Checking ext:/home/tony/repo/perso/haskell-mode/yasnippet.el...
Checking ext:/home/tony/repo/perso/haskell-mode/yasnippet.el...skipping
external file
Checking haskell-yas.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-yas.elc
--
building check-haskell-presentation-mode
Checking haskell-presentation-mode.el...
Scanning haskell-presentation-mode.el...
Scanning haskell-presentation-mode.el...done
Checking haskell-presentation-mode.el...OK
Wrote /home/tony/repo/perso/haskell-mode/haskell-presentation-mode.elc
--
building check-inf-haskell
Checking inf-haskell.el...
Scanning inf-haskell.el...
Scanning inf-haskell.el...done
Checking inf-haskell.el...OK
Wrote /home/tony/repo/perso/haskell-mode/inf-haskell.elc
--
building check
checks passed!

$
```