help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

font-lock function matcher sample


From: Arjan Bos
Subject: font-lock function matcher sample
Date: Sat, 17 Jul 2004 23:08:59 +0200
User-agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7) Gecko/20040616

Hi,

Could anyone of you please post a sample for a font-lock function matcher?

I'm looking for a way to fontify words accoriding to their scrabble score. So if a word would score 6 points in american scrabble, it should get a certain font-locking.

Currently, I have the following elisp, but it does not work. I've been looking at some samples from the emacs lisp directories, but failed to work out the pattern. Also the info node on font-locking and the various font-locking doc-strings were helpful, but not helpful enough. My elisp swings between locking emacs (presumably on font-locking) and no font-locking at all. (this of course when I twiddle around with it)


(defvar scrabble-font-lock-keywords
  (list '(scrabble-6-matcher (1 font-lock-warning-face))
))

(defun scrabble-6-matcher (limit)
  "returns t when the scrabble score of a word is 6."
  (if (and (re-search-forward "\\([a-z]\\)*" limit t)
       (< (scrabble-last-word-score) 5))
      (progn
        (set-match-data
         (list
          (match-beginning 1) (match-end 1)
          (match-beginning 1) (match-end 1)
          nil nil)))
    ;; else
    (set-match-data
     (list
      (match-beginning 1) (match-end 1)
      nil nil
      (match-beginning 1) (match-end 1)))
    t))



(defun scrabble-last-word-score ()
  ""
  5)

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]