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

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

Re: font-lock keywords that change depending on language


From: Oliver Scholz
Subject: Re: font-lock keywords that change depending on language
Date: 22 Apr 2004 23:52:59 -0700

Joe Corneli <address@hidden> wrote in message news:<address@hidden>...
> I would like to do something like this
> 
> (defvar todl-font-lock-keywords-1
>   (list '((concat "^" todl-top-level-node-phrase ":")
>           . font-lock-builtin-face))
>   "Minimal highlighting expressions for TODL mode.")
> 
> where todl-top-level-node-phrase is "Top-level node" when the user
> is working in English, but "Oberster Stufen Knoten" when the user is
> working in German.  
> 
> Unfortunately, the above does not seem to work at all.  Is this to
> be expected (I'm doing something wrong)? - or is it a bug?

It is to be expected, your expression above gets evaluated (usually)
just once, at load time.

If you want font-lock to constantly check for a variable you could use
a function as MATCHER in `font-lock-keywords'. For example:

(defconst test-font-lock-keywords
  '((test-font-lock-function
     (0 font-lock-warning-face))))

(defvar test-buffer-language
  'english)

(defconst test-english-regexp
  "top level node")

(defconst test-german-regexp
  "oberster Knotenpunkt")

(defun test-font-lock-function (limit)
  ;; We don't need to do anything else here, because
  ;; `re-search-forward' sets the match data as we need it.
  (or (and (eq test-buffer-language
               'english)
           (re-search-forward test-english-regexp
                              limit t))
      (and (eq test-buffer-language
               'german)
           (re-search-forward test-german-regexp
                              limit t))))

;; Testing

;; (define-derived-mode test-mode text-mode "test "
;;   ""
;;   (setq font-lock-defaults
;;      (list test-font-lock-keywords)))


reply via email to

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