From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Arjan Bos Newsgroups: gmane.emacs.help Subject: how to font-lock more than one word on a row Date: Wed, 21 Jul 2004 22:55:15 +0200 Organization: Planet Internet Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: Reply-To: Arjan.Bos@ISeeYou.nl NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1090443461 13712 80.91.224.253 (21 Jul 2004 20:57:41 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 21 Jul 2004 20:57:41 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jul 21 22:57:23 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BnO9S-0005J7-00 for ; Wed, 21 Jul 2004 22:57:23 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BnOCG-0004jW-EK for geh-help-gnu-emacs@m.gmane.org; Wed, 21 Jul 2004 17:00:16 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!border1.nntp.dca.giganews.com!border1.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!newsfeeder.wxs.nl!textnews.wxs.nl!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 162 Original-NNTP-Posting-Host: ip51cd7a2f.adsl-surfen.hetnet.nl Original-X-Trace: reader08.wxs.nl 1090443856 9982 81.205.122.47 (21 Jul 2004 21:04:16 GMT) Original-X-Complaints-To: abuse@planet.nl Original-NNTP-Posting-Date: 21 Jul 2004 21:04:16 GMT User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7) Gecko/20040616 X-Accept-Language: en-us, en Original-Xref: shelby.stanford.edu gnu.emacs.help:124395 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:19732 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:19732 Hi all, Currently I'm trying to work out how to font-lock more than one word on a row using matcher functions. I have the following file that I want to font-lock. -- start of file a a aaaaa aa aa a aa aaa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaa aaaaaaaaa -- end of file The font-locking is done according to the scrabble score and I have it sort of working. I'm using a's because it scores 1 in scrabble. The font-locking colours the first word. The second word only gets coloured if it has the same score. So on the first line, `a a' gets coloured, but `aaaaa' remains uncoloured. If I move `aaaaa' to a new line, then it gets coloured, but only because I changed something on that line. I'm using jit-lock-mode. The following (partial) code is what I use to do this. Could someone please tell me where I go wrong? (I'm hoping that it is something obvious, or something obscure but small ;-) ) (defvar scrabble-font-lock-keywords nil "font locking for scrabble-mode. Done with functions") (setq scrabble-font-lock-keywords (append (list '(scrabble-<5-p-matcher 1 scrabble-font-lock-<5-face)) (list '(scrabble-=5-p-matcher 1 scrabble-font-lock-=5-face)) (list '(scrabble-=6-p-matcher 1 scrabble-font-lock-=6-face)) (list '(scrabble-=7-p-matcher 1 scrabble-font-lock-=7-face)) (list '(scrabble-=8-p-matcher 1 scrabble-font-lock-=8-face)) (list '(scrabble-=9-p-matcher 1 scrabble-font-lock-=9-face)) (list '(scrabble-=10-p-matcher 1 scrabble-font-lock-=10-face)) (list '(scrabble-=11-p-matcher 1 scrabble-font-lock-=11-face)) (list '(scrabble-=12-p-matcher 1 scrabble-font-lock-=12-face)) (list '(scrabble-=13-p-matcher 1 scrabble-font-lock-=13-face)) (list '(scrabble-=14-p-matcher 1 scrabble-font-lock-=14-face)) (list '(scrabble-=15-p-matcher 1 scrabble-font-lock-=15-face)) (list '(scrabble-=16-p-matcher 1 scrabble-font-lock-=16-face)) (list '(scrabble-=17-p-matcher 1 scrabble-font-lock-=17-face)) ;; (list '(scrabble-=>18-<=23-p-matcher 1 scrabble-font-lock-=>18-<=23-face)) (list '(scrabble->23-p-matcher 1 scrabble-font-lock->23-face)))) (defconst scrabble-font-matcher-regexp "\\<\\([a-zA-Z]*\\)\\>" "Regular expression used to match words in scrabble") (defun scrabble-<5-p-matcher (limit) "returns t when the scrabble score of a word is less than 5." (and (re-search-forward scrabble-font-matcher-regexp limit t) (< (scrabble-last-word-score) 5))) (defun scrabble-=5-p-matcher (limit) "returns t when the scrabble score of a word equals 5." (and (re-search-forward scrabble-font-matcher-regexp limit t) (= (scrabble-last-word-score) 5))) (defun scrabble-=6-p-matcher (limit) "returns t when the scrabble score of a word equals 6." (and (re-search-forward scrabble-font-matcher-regexp limit t) (= (scrabble-last-word-score) 6))) (defun scrabble-=7-p-matcher (limit) "returns t when the scrabble score of a word equals 7." (and (re-search-forward scrabble-font-matcher-regexp limit t) (= (scrabble-last-word-score) 7))) (defun scrabble-=8-p-matcher (limit) "returns t when the scrabble score of a word equals 8." (and (re-search-forward scrabble-font-matcher-regexp limit t) (= (scrabble-last-word-score) 8))) (defun scrabble-=9-p-matcher (limit) "returns t when the scrabble score of a word equals 9." (and (re-search-forward scrabble-font-matcher-regexp limit t) (= (scrabble-last-word-score) 9))) (defun scrabble-=10-p-matcher (limit) "returns t when the scrabble score of a word equals 10." (and (re-search-forward scrabble-font-matcher-regexp limit t) (= (scrabble-last-word-score) 10))) (defun scrabble-=11-p-matcher (limit) "returns t when the scrabble score of a word equals 11." (and (re-search-forward scrabble-font-matcher-regexp limit t) (= (scrabble-last-word-score) 11))) (defun scrabble-=12-p-matcher (limit) "returns t when the scrabble score of a word equals 12." (and (re-search-forward scrabble-font-matcher-regexp limit t) (= (scrabble-last-word-score) 12))) (defun scrabble-=13-p-matcher (limit) "returns t when the scrabble score of a word equals 13." (and (re-search-forward scrabble-font-matcher-regexp limit t) (= (scrabble-last-word-score) 13))) (defun scrabble-=14-p-matcher (limit) "returns t when the scrabble score of a word equals 14." (and (re-search-forward scrabble-font-matcher-regexp limit t) (= (scrabble-last-word-score) 14))) (defun scrabble-=15-p-matcher (limit) "returns t when the scrabble score of a word equals 15." (and (re-search-forward scrabble-font-matcher-regexp limit t) (= (scrabble-last-word-score) 15))) (defun scrabble-=16-p-matcher (limit) "returns t when the scrabble score of a word equals 16." (and (re-search-forward scrabble-font-matcher-regexp limit t) (= (scrabble-last-word-score) 16))) (defun scrabble-=17-p-matcher (limit) "returns t when the scrabble score of a word equals 17." (and (re-search-forward scrabble-font-matcher-regexp limit t) (= (scrabble-last-word-score) 17))) (defun scrabble-=>18-<=23-p-matcher (limit) "returns t when the scrabble score of a word is between 18 and 23 (inclusive)." (and (re-search-forward scrabble-font-matcher-regexp limit t) (< (scrabble-last-word-score) 24) (> (scrabble-last-word-score) 17))) (defun scrabble->23-p-matcher (limit) "returns t when the scrabble score of a word is greater than 23." (and (re-search-forward scrabble-font-matcher-regexp limit t) (> (scrabble-last-word-score) 23))) (defun scrabble-last-word-score () "Returns the scrabble score of the word before or at point." (let ((str (match-string-no-properties 1)) (score 0) (n 0)) (setq str (downcase str)) (while (< n (length str)) (setq score (+ score (scrabble-letter-score (substring str n (+ n 1)))) n (+ n 1))) score)) TIA, Arjan -- -- If you really want to contact me, then replace the "I see you" text by its three letter accronym, hetnet. Fabricate Diem PVNC, Motto of the Night Watch -- Terry Pratchett