* how to font-lock more than one word on a row
@ 2004-07-21 20:55 Arjan Bos
0 siblings, 0 replies; only message in thread
From: Arjan Bos @ 2004-07-21 20:55 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-07-21 20:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-21 20:55 how to font-lock more than one word on a row Arjan Bos
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.