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