Skip to content

Instantly share code, notes, and snippets.

@nkpart
Last active June 18, 2019 14:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nkpart/cc852b43d948a33a04c8 to your computer and use it in GitHub Desktop.
Save nkpart/cc852b43d948a33a04c8 to your computer and use it in GitHub Desktop.
Using ghcid inside of emacs
Pieces you need:
* emacs
* ghcid
ghcid needs to know the height of the terminal, we'll set it explicitly
height = (window-height) - (scroll-margin) - 1
set this height as your term-buffer-maximum-size
(setq term-buffer-maximum-size XXX)
Start an ansi-term session using bash
SPC-'
run ghcid with this height, in your project root
ghcid -c "cabal repl" -h HEIGHT
turn on compilation-minor-mode in the buffer
@srid
Copy link

srid commented Mar 21, 2018

I didn't have to set the height. It sort of works. Error navigation works on some lines, but not on others. After using error navigation, when ghcid renders the new build output it doesn't scroll the terminal buffer. Is this also your experience, @nkpart, or am I missing something?

@23Skidoo
Copy link

23Skidoo commented Oct 4, 2018

@nkpart I wrote the following helper based on your notes, seems to work okay so far:

(defun ghcid ()
  "Runs ghcid in a `term' buffer."
  (interactive)
  (require 'term)
  (let* ((cmd "ghcid")
         (h (- (window-height) scroll-margin 3))
         (term-buffer-maximum-size h)
         (args (format "-h %d" h))
         (switches (split-string-and-unquote args))
         (termbuf (apply 'make-term "ghcid" cmd nil switches)))
    (set-buffer termbuf)
    (term-mode)
    (term-char-mode)
    (compilation-minor-mode)
    (switch-to-buffer termbuf)))

I put project-specific configuration into .ghci and .ghcid files, so don't need to provide any further command-line arguments to ghcid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment