From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Brendan Halpin Newsgroups: gmane.emacs.help Subject: Re: How easy to create new major mode? Date: 31 Jan 2003 15:58:35 +0000 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 1044028589 23868 80.91.224.249 (31 Jan 2003 15:56:29 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 31 Jan 2003 15:56:29 +0000 (UTC) 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 18edWm-0006Co-00 for ; Fri, 31 Jan 2003 16:56:28 +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 18edWV-0006uN-0B for gnu-help-gnu-emacs@m.gmane.org; Fri, 31 Jan 2003 10:56:11 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!bloom-beacon.mit.edu!npeer.de.kpn-eurorings.net!fu-berlin.de!uni-berlin.de!wivenhoe.staff8.ul.IE!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 58 Original-NNTP-Posting-Host: wivenhoe.staff8.ul.ie (136.201.147.134) Original-X-Trace: fu-berlin.de 1044028489 35124014 136.201.147.134 (16 [139789]) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 Original-Xref: shelby.stanford.edu gnu.emacs.help:109646 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:6162 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:6162 "Tim Morley \(remove vegetable for email address\)" 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