Skip to content

Instantly share code, notes, and snippets.

@BJTerry
Created September 10, 2012 20:04
Show Gist options
  • Save BJTerry/3693479 to your computer and use it in GitHub Desktop.
Save BJTerry/3693479 to your computer and use it in GitHub Desktop.
Code to fix ghc-mod, flymake, haskell-mode when used with yesod
;; Add this code to your .emacs file so it will be loaded at start, after installing ghc-mod
;; This code checks the parent folders of new haskell buffers to see if they contain .cabal
;; files. If so, it changes the working directory of the buffer to point to that directory.
(defun change-to-cabal-directory ()
(if (buffer-file-name)
(change-to-cabal-directory-from-directory (file-name-directory buffer-file-name))))
(defun change-to-cabal-directory-from-directory (directory)
(if (file-accessible-directory-p directory)
(if (find-cabal-files directory)
(cd directory)
(let ((parent-directory (file-name-directory
(directory-file-name directory))))
(if (string= parent-directory directory)
nil
(change-to-cabal-directory-from-directory
parent-directory))))))
(defun find-cabal-files (directory)
(let ((file-list (directory-files directory)))
(delq nil
(mapcar (lambda (file)
(if (> (length file) 6)
(string= (substring file (- 0 6)) ".cabal")
nil))
file-list))))
;; From the ghc-mod instructions
(autoload 'ghc-init "ghc" nil t)
;; This should replace the call to add-hook from the ghc-mod instructions:
(add-hook 'haskell-mode-hook (lambda () (ghc-init) (change-to-cabal-directory) (flymake-mode)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment