all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* font-lock keywords that change depending on language
@ 2004-04-22 23:32 Joe Corneli
  0 siblings, 0 replies; 3+ messages in thread
From: Joe Corneli @ 2004-04-22 23:32 UTC (permalink / raw)


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?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: font-lock keywords that change depending on language
       [not found] <mailman.1103.1082676809.1061.help-gnu-emacs@gnu.org>
@ 2004-04-23  6:52 ` Oliver Scholz
  0 siblings, 0 replies; 3+ messages in thread
From: Oliver Scholz @ 2004-04-23  6:52 UTC (permalink / raw)


Joe Corneli <jcorneli@math.utexas.edu> wrote in message news:<mailman.1103.1082676809.1061.help-gnu-emacs@gnu.org>...
> 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)))

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: font-lock keywords that change depending on language
@ 2004-04-25 23:22 Joe Corneli
  0 siblings, 0 replies; 3+ messages in thread
From: Joe Corneli @ 2004-04-25 23:22 UTC (permalink / raw)


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

Heh.  Thanks.  I seem to have gotten it going now, modulo a few
details that seem unique to my code.  The only difficulty I ran into
adapting your test example was that I forgot to switch the
appearances of `eq' to `equal' to do comparisons between strings.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-04-25 23:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1103.1082676809.1061.help-gnu-emacs@gnu.org>
2004-04-23  6:52 ` font-lock keywords that change depending on language Oliver Scholz
2004-04-25 23:22 Joe Corneli
  -- strict thread matches above, loose matches on Subject: below --
2004-04-22 23:32 Joe Corneli

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.