about summary refs log tree commit diff
path: root/init/functions.el
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2018-09-12T09·21+0200
committerVincent Ambo <github@tazj.in>2019-02-10T20·43+0100
commitbab9f15a33ae85a685a766e74e57df3ade467274 (patch)
tree4556e500cd1a858ed2f74d035fe946c517437a4b /init/functions.el
parent0cf7af4403ea17603fd3627c8791e9c8ab12de9b (diff)
fix: Add temporary workaround for Intero + GHC 8.4 bug
Adds a workaround for commercialhaskell/intero#569 by adding a
function that disables the offending GHCi flag in the Intero REPL, and
advising the `intero-repl` and `intero-repl-load` commands to always
execute it.

I did not manage to locate a common entrypoint to the REPL, but it's
probably not worth spending more time on as this will be fixed
properly in a future GHC release.
Diffstat (limited to 'init/functions.el')
-rw-r--r--init/functions.el28
1 files changed, 28 insertions, 0 deletions
diff --git a/init/functions.el b/init/functions.el
index 019bf1646079..ef4c8cef79d9 100644
--- a/init/functions.el
+++ b/init/functions.el
@@ -231,4 +231,32 @@ Including indent-buffer, which should not be called automatically on save."
   (inferior-erlang
    (format "nix-shell --command erl %s" (cdr (project-current)))))
 
+(defun intero-fix-ghci-panic ()
+  "Disable deferring of out of scope variable errors, which
+  triggers a bug in the interactive Emacs REPL printing a panic
+  under certain conditions."
+
+  (interactive)
+  (let* ((root (intero-project-root))
+         (package-name (intero-package-name))
+         (backend-buffer (intero-buffer 'backend))
+         (name (format "*intero:%s:%s:repl*"
+                       (file-name-nondirectory root)
+                       package-name))
+         (setting ":set -fno-defer-out-of-scope-variables\n"))
+    (when (get-buffer name)
+      (with-current-buffer (get-buffer name)
+        (goto-char (point-max))
+        (let ((process (get-buffer-process (current-buffer))))
+          (when process (process-send-string process setting)))))))
+
+;; Brute-force fix: Ensure the setting is injected every time the REPL
+;; is selected.
+;;
+;; Upstream issue: https://github.com/commercialhaskell/intero/issues/569
+(advice-add 'intero-repl :before (lambda (&rest r) (intero-fix-ghci-panic))
+            '((name . intero-panic-fix)))
+(advice-add 'intero-repl-load :before (lambda (&rest r) (intero-fix-ghci-panic))
+            '((name . intero-panic-fix)))
+
 (provide 'functions)