unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Replace regex strings with variables for font-lock
@ 2005-04-28 16:03 Ryan Bowman
  0 siblings, 0 replies; 2+ messages in thread
From: Ryan Bowman @ 2005-04-28 16:03 UTC (permalink / raw)


I'm trying to write a major mode, using the following
from
http://www.emacswiki.org/cgi-bin/wiki/EasyFontLock

(defun my-mode () "my-mode" (interactive)
  (kill-all-local-variables)
  (make-local-variable 'font-lock-defaults)
  (setq font-lock-defaults 
'(my-mode-font-lock-keywords t)))

(defvar my-mode-font-lock-keywords nil 
  "Keywords/Regexp for fontlocking of my-mode")

(setq my-mode-font-lock-keywords
	  (list
	   '("^#.*$" 0 'bold)
	   '("\\(foo\\)\\(bar\\)" ; the word foobar in two
faces
		 (1 'font-lock-warning-face)
		 (2 'font-lock-type-face))))

That second part, being able to font-lock with
multiple faces is awesome.
Anyway, I want to replace the regex strings with
customizable variables, so I used defcustom to define
a variable and then in place of '("&#.*S" 0 'bold) I
tried '(my-var 0 'bold) but it didn't work, meaning to
the face wasn't applied.  I tried defining the
variable with defcustom and defvar but neither had the
effect I wanted.  Is there a way to use defcustom to
define a variable that contains a regex that will be
recognized by font-lock?

----
Ryan Bowman

While any text editor can save your files, only Emacs can save your soul. -- Per Abrahamsen

Emacs is not built by hate of vi. vi is irrelevant - it is no more than a strange punishment that the unbelievers submit themselves to. -- Matan Ninio
----


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/ 

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

* Re: Replace regex strings with variables for font-lock
       [not found] <mailman.3315.1114704273.2895.help-gnu-emacs@gnu.org>
@ 2005-04-28 16:31 ` Lute Kamstra
  0 siblings, 0 replies; 2+ messages in thread
From: Lute Kamstra @ 2005-04-28 16:31 UTC (permalink / raw)


Ryan Bowman <ryanlbowman@yahoo.com> writes:

[...]

> (setq my-mode-font-lock-keywords
> 	  (list
> 	   '("^#.*$" 0 'bold)
> 	   '("\\(foo\\)\\(bar\\)" ; the word foobar in two faces
> 		 (1 'font-lock-warning-face)
> 		 (2 'font-lock-type-face))))
>
> That second part, being able to font-lock with
> multiple faces is awesome.
> Anyway, I want to replace the regex strings with
> customizable variables, so I used defcustom to define
> a variable and then in place of '("&#.*S" 0 'bold) I
> tried '(my-var 0 'bold) but it didn't work, meaning to
> the face wasn't applied.  I tried defining the
> variable with defcustom and defvar but neither had the
> effect I wanted.  Is there a way to use defcustom to
> define a variable that contains a regex that will be
> recognized by font-lock?

(setq my-mode-font-lock-keywords
      `((,my-var 0 'bold)
	("\\(foo\\)\\(bar\\)"
	 (1 'font-lock-warning-face)
	 (2 'font-lock-type-face))))

Lute.

-- 
(spook) => "UOP Agfa computer terrorism"
(insert-file-contents "~/.signature") => (error "`~/.signature' too rude")

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

end of thread, other threads:[~2005-04-28 16:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.3315.1114704273.2895.help-gnu-emacs@gnu.org>
2005-04-28 16:31 ` Replace regex strings with variables for font-lock Lute Kamstra
2005-04-28 16:03 Ryan Bowman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).