unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Colin Marquardt <c.marquardt@alcatel.de>
Subject: Re: How easy to create new major mode?
Date: Fri, 31 Jan 2003 17:45:59 +0100	[thread overview]
Message-ID: <k8z3cn9mfnc.fsf@slsf86.stgl.sel.alcatel.de> (raw)
In-Reply-To: b1e285$rr6$1@s1.read.news.oleane.net

"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

  parent reply	other threads:[~2003-01-31 16:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2003-01-31 17:02 ` Friedrich Dominicus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=k8z3cn9mfnc.fsf@slsf86.stgl.sel.alcatel.de \
    --to=c.marquardt@alcatel.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).