Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

default lambda symbol in emacs haskell mode?

Tags:

emacs

haskell

Does anyone know how I can print λ instead of \ using haskell in emacs. I know that one can use haskell-font-lock-symbols, but I find the rest of them hard to read - the arrows are TOO small!

Is there a simple way of over-riding the rest of the keys?

like image 384
beoliver Avatar asked May 05 '12 20:05

beoliver


2 Answers

You can also solve the problem with something like

(eval-after-load 'haskell-font-lock
 '(setq haskell-font-lock-symbols-alist
        (delq nil
              (mapcar (lambda (rewrite)
                        (if (member (car rewrite) '("->" "<-"))
                            nil rewrite))
                      haskell-font-lock-symbols-alist))))

which should keep all mappings except for the one that changes "->" into "→" and "<-" into "←".

like image 107
Stefan Avatar answered Sep 22 '22 20:09

Stefan


You can do this:

(defun pretty-lambdas-haskell ()
  (font-lock-add-keywords
   nil `((,(concat "\\(" (regexp-quote "\\") "\\)")
          (0 (progn (compose-region (match-beginning 1) (match-end 1)
                                    ,(make-char 'greek-iso8859-7 107))
                    nil))))))

(add-hook 'haskell-mode-hook 'pretty-lambdas-haskell)

This adds the lambda as a keyword, meaning that it won't appear in escape sequences in strings for example (TODO: this is not the case after changing a thing). The ,(make-char 'greek-iso8859-7 107) is of course equivalent to , but you must make sure that your Emacs init file is encoded as unicode in that case.

You can also enable full symbol font locking and use a better (read: with wider arrows) font, like Pragmata Pro, Inconsolata or Ubuntu Monospace. I use the following code to select a good font:

(defun font-existsp (font)
  "Check to see if the named FONT is available."
  (if (null (x-list-fonts font))
      nil t))

(require 'cl)
(defun font-avail (fonts)
  "Finds the available fonts."
  (remove-if-not 'font-existsp fonts))

(defvar font-preferences
      '("PragmataPro"
        "Inconsolata"
        "DejaVu Sans Mono"
        "Bitstream Vera Sans Mono"
        "Anonymous Pro"
        "Menlo"
        "Consolas"))

(unless (eq window-system nil)
  (let ((fonts (font-avail font-preferences)))
    (unless (null fonts)
      (set-face-attribute
       'default nil :font
       (car fonts)))))
like image 41
dflemstr Avatar answered Sep 22 '22 20:09

dflemstr