@@ -487,6 +487,71 @@ that should be commented under LaTeX-style literate scripts."
487
487
; ; Get help from font-lock-syntactic-keywords.
488
488
(parse-sexp-lookup-properties . t ))))
489
489
490
+ ; ; The main functions.
491
+ (defun turn-on-haskell-font-lock ()
492
+ " Turns on font locking in current buffer for Haskell 1.4 scripts.
493
+
494
+ Changes the current buffer's `font-lock-defaults' , and adds the
495
+ following variables:
496
+
497
+ `haskell-keyword-face' for reserved keywords and syntax,
498
+ `haskell-constructor-face' for data- and type-constructors, class names,
499
+ and module names,
500
+ `haskell-operator-face' for symbolic and alphanumeric operators,
501
+ `haskell-default-face' for ordinary code.
502
+
503
+ The variables are initialised to the following font lock default faces:
504
+
505
+ `haskell-keyword-face' `font-lock-keyword-face'
506
+ `haskell-constructor-face' `font-lock-type-face'
507
+ `haskell-operator-face' `font-lock-function-name-face'
508
+ `haskell-default-face' <default face>
509
+
510
+ Two levels of fontification are defined: level one (the default)
511
+ and level two (more colour). The former does not colour operators.
512
+ Use the variable `font-lock-maximum-decoration' to choose
513
+ non-default levels of fontification. For example, adding this to
514
+ .emacs:
515
+
516
+ (setq font-lock-maximum-decoration '((haskell-mode . 2) (t . 0)))
517
+
518
+ uses level two fontification for `haskell-mode' and default level for
519
+ all other modes. See documentation on this variable for further
520
+ details.
521
+
522
+ To alter an attribute of a face, add a hook. For example, to change
523
+ the foreground colour of comments to brown, add the following line to
524
+ .emacs:
525
+
526
+ (add-hook 'haskell-font-lock-hook
527
+ (lambda ()
528
+ (set-face-foreground 'haskell-comment-face \" brown\" )))
529
+
530
+ Note that the colours available vary from system to system. To see
531
+ what colours are available on your system, call
532
+ `list-colors-display' from emacs.
533
+
534
+ To turn font locking on for all Haskell buffers, add this to .emacs:
535
+
536
+ (add-hook 'haskell-mode-hook 'turn-on-haskell-font-lock)
537
+
538
+ To turn font locking on for the current buffer, call
539
+ `turn-on-haskell-font-lock' . To turn font locking off in the current
540
+ buffer, call `turn-off-haskell-font-lock' .
541
+
542
+ Bird-style literate Haskell scripts are supported: If the value of
543
+ `haskell-literate-bird-style' (automatically set by the Haskell mode
544
+ of Moss&Thorn) is non-nil, a Bird-style literate script is assumed.
545
+
546
+ Invokes `haskell-font-lock-hook' if not nil."
547
+ (haskell-font-lock-defaults-create)
548
+ (run-hooks 'haskell-font-lock-hook )
549
+ (turn-on-font-lock ))
550
+
551
+ (defun turn-off-haskell-font-lock ()
552
+ " Turns off font locking in current buffer."
553
+ (font-lock-mode -1 ))
554
+
490
555
(defun haskell-fontify-as-mode (text mode )
491
556
" Fontify TEXT as MODE, returning the fontified text."
492
557
(with-temp-buffer
0 commit comments