* How easy to create new major mode?
@ 2003-01-31 14:47 Tim Morley (remove vegetable for email address)
2003-01-31 15:31 ` Stefan Monnier <foo@acm.com>
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Tim Morley (remove vegetable for email address) @ 2003-01-31 14:47 UTC (permalink / raw)
Hi all.
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).
I've had a look at the .el files for the various existing modes, but as an
absolute novice in Lisp, I'm not sure which are the relevant bits to
cut-out-and-keep.
Any pointers will be very gratefully received. Cheers all.
Tim Morley
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How easy to create new major mode?
2003-01-31 14:47 How easy to create new major mode? Tim Morley (remove vegetable for email address)
@ 2003-01-31 15:31 ` Stefan Monnier <foo@acm.com>
2003-01-31 15:58 ` Brendan Halpin
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier <foo@acm.com> @ 2003-01-31 15:31 UTC (permalink / raw)
>>>>> "Tim" == Tim Morley \(remove vegetable for email address\) <Tim> 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
I recommend http://www.emacswiki.org/cgi-bin/wiki.pl?SampleMode
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How easy to create new major mode?
2003-01-31 14:47 How easy to create new major mode? Tim Morley (remove vegetable for email address)
2003-01-31 15:31 ` Stefan Monnier <foo@acm.com>
@ 2003-01-31 15:58 ` Brendan Halpin
2003-01-31 16:45 ` Tim Morley (remove vegetable for email address)
2003-01-31 16:45 ` Colin Marquardt
2003-01-31 17:02 ` Friedrich Dominicus
3 siblings, 1 reply; 6+ messages in thread
From: Brendan Halpin @ 2003-01-31 15:58 UTC (permalink / raw)
"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>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How easy to create new major mode?
2003-01-31 15:58 ` Brendan Halpin
@ 2003-01-31 16:45 ` Tim Morley (remove vegetable for email address)
0 siblings, 0 replies; 6+ messages in thread
From: Tim Morley (remove vegetable for email address) @ 2003-01-31 16:45 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3141 bytes --]
Thanks aplenty Brendan -- I've copied your function into my .emacs, pasted
in a few extra regexps to make it really pretty, and learnt a bit of Lisp at
the same time. :o) Cheers for that.
Just one thing -- I had to add `(interactive)' immediately after the two
(defun .......) lines [just blindly following the other functions already in
my .emacs] to be able to access the functions; at least, I can now do it
with M-x tm-set-overlays; maybe I just didn't know how to get at it
before...?
Anyway, thanks for your help.
Tim
"Brendan Halpin" <brendan.halpin@ul.ie> a écrit dans le message news:
m3lm115n10.fsf@wivenhoe.staff8.ul.ie...
> "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>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How easy to create new major mode?
2003-01-31 14:47 How easy to create new major mode? Tim Morley (remove vegetable for email address)
2003-01-31 15:31 ` Stefan Monnier <foo@acm.com>
2003-01-31 15:58 ` Brendan Halpin
@ 2003-01-31 16:45 ` Colin Marquardt
2003-01-31 17:02 ` Friedrich Dominicus
3 siblings, 0 replies; 6+ messages in thread
From: Colin Marquardt @ 2003-01-31 16:45 UTC (permalink / raw)
"Tim Morley \(remove vegetable for email address\)" <tim@teamlog.turnip.com> writes:
> Hi all.
>
> 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).
Funny, I just answered a similar question over in comp.emacs in
<k8z7kclmfxv.fsf@slsf86.stgl.sel.alcatel.de>.
I'll just copy my article:
Pat Colbeck <pcolbeck@bashq.org> writes:
> Can anyone point me at some good references for writing a basic syntax
> highlighting mode. I need to write some for highlighting some debug
> outputs from routers etc. I am not a programer so the simpler the better
> :)
>
> So far I have found:
>
> http://www.emacswiki.org/cgi-bin/wiki.pl?CategoryCode
This also points you to
http://www.emacswiki.org/cgi-bin/wiki.pl?ModeTutorial
which should help if you want to write a full mode.
To stay really simplistic, you could try highlight-regexp like this:
(defun cm-colorize ()
"Colorize stuff. Uses highlight-regexp aka hi-lock-face-buffer from hi-lock.el."
(interactive)
;;(highlight-regexp REGEXP &optional FACE)
(highlight-regexp "ERROR" 'hi-red-b)
(highlight-regexp "FIXME" 'hi-red-b)
(highlight-regexp "ANN:" 'hi-pink)
(highlight-regexp "success" 'hi-green)
(highlight-regexp "\\bcomplete\\b" 'hi-green)
(highlight-regexp "Testing [A-Za-z0-9_]+" 'hi-blue)
)
Or use that here as a starting point:
(defun my-highlight-fixme ()
(interactive)
(font-lock-mode 1)
(font-lock-add-keywords
nil '(("\\<\\(FIXME\\|TODO\\|XXX\\|!!!\\)" 1 font-lock-warning-face prepend))))
(add-hook 'c-mode-common-hook 'my-highlight-fixme)
(add-hook 'cperl-mode-hook 'my-highlight-fixme)
(add-hook 'emacs-lisp-mode-hook 'my-highlight-fixme)
(add-hook 'vhdl-mode-hook 'my-highlight-fixme)
HTH,
Colin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How easy to create new major mode?
2003-01-31 14:47 How easy to create new major mode? Tim Morley (remove vegetable for email address)
` (2 preceding siblings ...)
2003-01-31 16:45 ` Colin Marquardt
@ 2003-01-31 17:02 ` Friedrich Dominicus
3 siblings, 0 replies; 6+ messages in thread
From: Friedrich Dominicus @ 2003-01-31 17:02 UTC (permalink / raw)
"Tim Morley \(remove vegetable for email address\)" <tim@teamlog.turnip.com> writes:
> Hi all.
>
> 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.
Well if you are interested in Emacs Lisp programming, have a look at
"Writing GNU Emacs extensions", there is a chapter in it on how to
develop you own major mode.
>
> 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).
No for such simple thing an own major mode is over-kill.
Check the documentation for font-face, This will be enough for what
you are planning to do.
Regards
Friedrich
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2003-01-31 17:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-01-31 14:47 How easy to create new major mode? Tim Morley (remove vegetable for email address)
2003-01-31 15:31 ` Stefan Monnier <foo@acm.com>
2003-01-31 15:58 ` Brendan Halpin
2003-01-31 16:45 ` Tim Morley (remove vegetable for email address)
2003-01-31 16:45 ` Colin Marquardt
2003-01-31 17:02 ` Friedrich Dominicus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).