Skip to content

Instantly share code, notes, and snippets.

@aspiwack
Created November 19, 2020 13:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspiwack/b3354e97b3389d2acf6da87f2350dd0d to your computer and use it in GitHub Desktop.
Save aspiwack/b3354e97b3389d2acf6da87f2350dd0d to your computer and use it in GitHub Desktop.
An Emacs configuration to colour Haskell code blocks in lhs2tex
;; I wrote a bit of Emacs configuration (which can be added to your
;; init.el) so that an lhs2tex file can be syntax-highlighted as a
;; Latex file but the Haskell code is highlighted as Haskell code. In
;; fact it's a little more than this, as the code blocks are
;; interpreted with the haskell-mode, so you can use your haskell
;; commands there.
;;
;; I don't recommend opening all `.lhs' file in this mode, as they
;; don't need to be Latex files. Literate Haskell is really agnostic
;; about its surrounding language.
;;
;; Instead I add the following code snippet in the .dir-locals.el of
;; repos where I do lhs2tex stuff.
;;
;; ((nil . ((eval . (add-hook 'hack-local-variables-hook
;; (lambda () (when (derived-mode-p 'latex-mode)
;; (poly-latex-lhs-mode))))))))
(use-package polymode
:ensure t)
(define-innermode aspiwack/poly-latex-haskell-innermode
:mode 'haskell-mode
:head-matcher "^[ \t]*\\\\begin{\\(code\\|spec\\)}"
:tail-matcher "^[ \t]*\\\\end{\\(code\\|spec\\)}"
:head-mode 'host
:tail-mode 'host)
(define-polymode poly-latex-lhs-mode poly-latex-root-polymode
:innermodes '(aspiwack/poly-latex-haskell-innermode))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment