I'm trying to write a new mode for emacs, using define-generic-mode. I've found a few tutorials which show how you can add keywords (as strings) which will then be highlighted. Is it possible to give define-generic-mode a regular expression so that it can then highlight anything that matches that as a keyword?
I'd like to have a mode in which anything matching a date in the form 15/01/09 is displayed in a different font (preferably underlined, but I'll accept a different colour).
Any ideas?
Robin
Here's an example of define-generic-mode
which sets up the regexp to have all the dates fontified using a custom face with some attributes chosen as examples:
(make-face 'my-date-face)
(set-face-attribute 'my-date-face nil :underline t)
(set-face-attribute 'my-date-face nil :family "times")
(set-face-attribute 'my-date-face nil :slant 'normal)
(set-face-attribute 'my-date-face nil :height '340)
(define-generic-mode my-date-mode
nil
nil
'(("\\([0-9]+/[0-9]+/[0-9]+\\)"
(1 'my-date-face)))
nil
nil)
Oh, and obviously, set the mode by M-x my-date-mode
. This can be done automatically via the auto-mode-alist (5th argument to define-generic-mode
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With