[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How easy to create new major mode?
From: |
Brendan Halpin |
Subject: |
Re: How easy to create new major mode? |
Date: |
31 Jan 2003 15:58:35 +0000 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 |
"Tim Morley \(remove vegetable for email address\)" <tim@teamlog.turnip.com>
writes:
> I believe the solution to my current emacs challenge will be to create a new
> major mode, albeit a very simple one. I'd be grateful for
> (a) confirmation that this is the way to attack the problem (or failing
> that, a better suggestion)
> and assuming this is indeed the case
> (b) guidance/URLs/code samples to help me put together what I need.
>
> What I would like to achieve is a customised system of syntax colouration,
> to help with reading through hundreds of lines of text. All I need is for
> lines starting with the word User to come up in, say, magenta, and lines
> starting with System in blue, with a default text colour of grey. (There are
> carriage-returns at the end of each line of text, so my keywords will always
> be at the beginning of a new line).
A major mode might be a neat way to do it, but isn't necessary.
Your requirements are relatively simple, and putting overlays on
top of regexps might be an easy way to do it.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; not really tested
(make-face 'tm-user)
(set-face-foreground 'tm-user "green")
(set-face-background 'tm-user "black")
(make-face 'tm-system)
(set-face-foreground 'tm-system "red")
(set-face-background 'tm-system "grey90")
(defun tm-clear-overlays ()
(dolist (x (append (car (overlay-lists))
(cdr (overlay-lists))))
(if (memq (overlay-get x 'face)
'(tm-user tm-system))
(delete-overlay x))))
(defun tm-set-overlays ()
(tm-clear-overlays)
(save-excursion
(while (re-search-forward "^User:[^\n]+" nil t)
(overlay-put (make-overlay (match-beginning 0)
(match-end 0)) 'face 'tm-user)))
(save-excursion
(while (re-search-forward "^System:[^\n]+" nil t)
(overlay-put (make-overlay (match-beginning 0)
(match-end 0)) 'face 'tm-system))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Obviously, a major mode will scale better than this, but for a
simple application this will do.
Brendan
--
Brendan Halpin, Department of Sociology, University of Limerick, Ireland
Tel: w +353-61-213147 f +353-61-202569 h +353-61-390476; Room F2-025 x 3147
<mailto:brendan.halpin@ul.ie> <http://wivenhoe.staff8.ul.ie/~brendan>