From bab9f15a33ae85a685a766e74e57df3ade467274 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 12 Sep 2018 11:21:19 +0200 Subject: [PATCH] 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. --- init/functions.el | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/init/functions.el b/init/functions.el index 019bf1646..ef4c8cef7 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)