From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Colin Marquardt Newsgroups: gmane.emacs.help Subject: Re: How easy to create new major mode? Date: Fri, 31 Jan 2003 17:45:59 +0100 Organization: I'd rather call it chaos ... Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1044031941 9558 80.91.224.249 (31 Jan 2003 16:52:21 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 31 Jan 2003 16:52:21 +0000 (UTC) Keywords: highlight-regexp,my-highlight-fixme,add-hook,text,starting,org,need,mode Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18eeOn-0002Te-00 for ; Fri, 31 Jan 2003 17:52:17 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18eeNJ-0000jV-02 for gnu-help-gnu-emacs@m.gmane.org; Fri, 31 Jan 2003 11:50:45 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!news.stgl.sel.alcatel.DE!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 66 Original-NNTP-Posting-Host: news.stgl.sel.alcatel.de (194.113.59.80) Original-X-Trace: fu-berlin.de 1044031560 34776630 194.113.59.80 (16 [131051]) X-Disclaimer: Opinions expressed are not those of Alcatel. User-Agent: Gnus/5.090012 (Oort Gnus v0.12) Emacs/21.2 (sparc-sun-solaris2.8) Cancel-Lock: sha1:tjUutjp/pAg/SPML+lcVbmPA4NE= Cache-Post-Path: news.alcatel.de!unknown@slse6w.stgl.sel.alcatel.de X-Cache: nntpcache 2.4.0b5 (see http://www.nntpcache.org/) Original-Xref: shelby.stanford.edu gnu.emacs.help:109651 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:6168 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:6168 "Tim Morley \(remove vegetable for email address\)" 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 . I'll just copy my article: Pat Colbeck 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