Is there a Haskell emacs mode that works well with lhs2TeX? Specifically (a) treating \begin{spec} ... \end{spec} like \begin{code}... \end{code}, and (b) coloring inline code ("|<expr>|)" and maybe inline verbatim ("@<expr>@") as Haskell rather than LaTeX code. - Conal
Is there a Haskell emacs mode that works well with lhs2TeX? Specifically (a) treating \begin{spec} ... \end{spec} like \begin{code}... \end{code}, and (b) coloring inline code ("|<expr>|)" and maybe inline verbatim ("@<expr>@") as Haskell rather than LaTeX code.
It'd be trivial to patch haskell-mode so that it can understand \begin{spec}...\end{spec}. For |<expr>| and @<expr>@, it may be a bit tricker depending on the details (e.g. what about other | or @ chars appearing the TeX code or in Haskell code: do they need to be quoted, if so how? Also: can <expr> span several lines? If yes, is it common or is it rare?). Stefan
"Conal" == Conal Elliott <conal@conal.net> writes:
Conal> Is there a Haskell emacs mode that works well with lhs2TeX? Conal> Specifically (a) treating \begin{spec} ... \end{spec} like Conal> \begin{code}... \end{code}, and (b) coloring inline code Conal> ("|<expr>|)" and maybe inline verbatim ("@<expr>@") as Haskell Conal> rather than LaTeX code. May be mmm-mode will help you, I haven't tried the combination mmm-mode+latex-mode+haskell-mode. AFAIU it should work (I used mmm-mode with cweb mode to highlight latex and c code simultaneously). -- WBR, Max Vasin.
Hi Max. Thanks for the mmm-mode suggestion. It sure looks like it should help, but I didn't see any effect when I tried it. Would you mind sharing the emacs lisp you use with it? Does anyone on this list use mmm-mode for Haskell+LaTeX? - Conal On 4/17/06, Max Vasin <max-appolo@mail.ru> wrote:
"Conal" == Conal Elliott <conal@conal.net> writes:
Conal> Is there a Haskell emacs mode that works well with lhs2TeX? Conal> Specifically (a) treating \begin{spec} ... \end{spec} like Conal> \begin{code}... \end{code}, and (b) coloring inline code Conal> ("|<expr>|)" and maybe inline verbatim ("@<expr>@") as Haskell Conal> rather than LaTeX code.
May be mmm-mode will help you, I haven't tried the combination mmm-mode+latex-mode+haskell-mode. AFAIU it should work (I used mmm-mode with cweb mode to highlight latex and c code simultaneously).
-- WBR, Max Vasin.
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
"Conal" == Conal Elliott <conal@conal.net> writes:
Conal> Hi Max. Hi Conal, Conal> Thanks for the mmm-mode suggestion. It sure looks Conal> like it should help, but I didn't see any effect when I tried Conal> it. Would you mind sharing the emacs lisp you use with it? Well, to see any effect you have to select submode class (C-c % C-c). I used CWEB submode class which shipped with mmm-mode. Defining new submode is pretty easy - look at the documentation which comes with mmm-mode and examples (on my machine they are in /usr/share/emacs/site-lisp/mmm-mode/). -- WBR, Max Vasin.
On Mon, 17 Apr 2006, "Conal Elliott" <conal@conal.net> wrote:
Does anyone on this list use mmm-mode for Haskell+LaTeX?
I do. The following code snippet (which should be cleaned up a little) from my .emacs makes the above combination work fairly well for me: ;;; mmm-mode (add-to-list 'load-path "~/install/usr/share/emacs/site-lisp/mmm-mode/" t) (require 'mmm-auto) ; The following expression was stolen from the Haskell Wiki, then ; modified extensively by me. (mmm-add-classes '((literate-haskell :classes (literate-haskell-bird literate-haskell-laTeX ) ) (literate-haskell-bird :submode literate-haskell-mode :front "^>" :include-front t :back "^[^>]\\|\\'" :include-back nil :insert ((?b insert-literate-haskell-bird-region nil @ ">" @ " " _ @ "\n" @ "\n")) ) (literate-haskell-laTeX :submode haskell-mode :front "^\\\\begin{code}\n" :include-front nil :back "^\\\\end{code}" :include-back nil :insert ((?l insert-literate-haskell-laTeX-region nil @ "\\begin{code}\n" @ _ @ "\\end{code}" @ "\n")) ) (literate-haskell-lhs2TeX :classes (literate-haskell-lhs2TeX-code literate-haskell-lhs2TeX-bird-code literate-haskell-lhs2TeX-bird-spec ; The following two modes cause mmm-parse-buffer to go ; into a loop for || and @@. ; literate-haskell-lhs2TeX-verb ; literate-haskell-lhs2TeX-inline ) ) (literate-haskell-lhs2TeX-code :submode haskell-mode :front "^\\\\begin{code}\\|^\\\\begin{spec}" :front-offset (end-of-line 1) :back "^\\\\end{code}\\|^\\\\end{spec}" :back-offset (beginning-of-line -1) ) (literate-haskell-lhs2TeX-bird-code :submode literate-haskell-mode :front "^> " :include-front true :back "^[^>]" :back-offset (beginning-of-line -1) ) ; literate-haskell-mode doesn't understand <... ; mmm-mode doesn't handle :back "$" :back-offset 0 very well. The ; keyboard bindings of the two modes aren't handled correctly. (literate-haskell-lhs2TeX-bird-spec :submode haskell-mode :front "^< " :back "^[^>]" :back-offset -1 ) (literate-haskell-lhs2TeX-verb :submode haskell-mode :front "@" :back "@" :back-offset -1 ) (literate-haskell-lhs2TeX-inline :submode haskell-mode :front "|" :back "|" :back-offset -1 ) ) ) (dolist (entry '((flyspell-prog-text-faces region) (flyspell-generic-check-word-p region) (haskell-literate region (haskell literate-haskell)) )) (add-to-list 'mmm-save-local-variables entry)) These variables are set by custom-set-variables: '(mmm-global-mode (quote maybe) nil (mmm-mode)) '(mmm-mode-ext-classes-alist (quote ((latex-mode "\\.lhs$" literate-haskell-lhs2TeX) (text-mode "\\.lhs$" literate-haskell))) nil (mmm-mode)) '(mmm-submode-decoration-level 2) -- /NAD
Thanks a bunch, Nils! Your elisp code works great for me. No more manual switching between LaTeX and literate Haskell modes. The one visible shortcoming is that it doesn't handle inline Haskell (|...| or @...@). I see you added support but commented it out. When I tried it myself, I see why. Apparently, closing delimiters are also treated as opening delimiters, so the whole paragraph after the first "|" or "@" ends up treated as Haskell code. Maybe it's impossible to fix this problem, since distinguishing between open and close delimiter is not lexical. Since inline Haskell coloring is not nearly as useful as code block coloring, this problem is fortunately not too big a deal. Still, I'm curious if anyone has a solution. Regards, - Conal
participants (4)
-
Conal Elliott -
Max Vasin -
Nils Anders Danielsson -
Stefan Monnier