all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Evaluating a 'variable' in a nested list
@ 2010-04-21  1:44 Tim Johnson
  2010-04-21 19:16 ` Dmitry Dzhus
  0 siblings, 1 reply; 3+ messages in thread
From: Tim Johnson @ 2010-04-21  1:44 UTC (permalink / raw
  To: help-gnu-emacs

I'm using emacs 23.1.1 on slackware 13.0 32-bit.
I've created an elisp file to set highlighting patterns for extra
keywords for the scheme programming language.
The file appears thusly:
;; ================================================================
(defface scheme-font-lock-user-keywords-face
  '((((class color) (background light)) (:foreground "red4"))
    (((class color) (background dark)) (:foreground "yellow3"))
    (((class grayscale) (background light)) (:foreground "dimgray" :italic t))
    (((class grayscale) (background dark)) (:foreground "lightgray" :italic t))
    (t (:bold t)))
  "Font lock mode face used to highlight user-defined keywords for scheme mode."
  :group 'font-lock-faces)
(defvar scheme-font-lock-user-keywords-face 
  'scheme-font-lock-user-keywords-face)
;; Test a single regex for the eq? keyword
(defconst scheme-user-keywords-regexp
		  (regexp-opt 
			'("eq?")))
(provide 'tj-scheme)
;; =================================================================
Using 
  http://www.gnu.org/software/emacs/manual/html_node/emacs/Font-Lock.html
as an example, I have added the following to my .emacs
;; ===============================================================
(require 'tj-scheme)
(add-hook 'scheme-mode-hook
		  (lambda ()
			(font-lock-add-keywords 
			  nil 
			  '((scheme-user-keywords-regexp 1 scheme-font-lock-user-keywords-face t)))))
;; ==================================================================
When I load a scheme file, syntax highlight fails and I get the 
following error message:
"""
Error during redisplay: (void-function scheme-user-keywords-regexp)
"""
I believe that I have coded the following form:
'((scheme-user-keywords-regexp 1 scheme-font-lock-user-keywords-face t))
Incorrectly, so that 'scheme-user-keywords-regexp is being treated 
as a function when the hook is run.

I can verify that scheme-user-keywords-regexp is being displayed correctly when
I invoke C-h v
Can someone advise me of the appropriate syntax for the form?
thanks
-- 
Tim 
tim@ johnsons-web.com||akwebsoft.com
http://www.akwebsoft.com


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

* Re: Evaluating a 'variable' in a nested list
  2010-04-21  1:44 Evaluating a 'variable' in a nested list Tim Johnson
@ 2010-04-21 19:16 ` Dmitry Dzhus
  2010-04-21 21:44   ` Tim Johnson
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Dzhus @ 2010-04-21 19:16 UTC (permalink / raw
  To: help-gnu-emacs

Tim Johnson wrote:

> When I load a scheme file, syntax highlight fails and I get the 
> following error message:
> """
> Error during redisplay: (void-function scheme-user-keywords-regexp)
> """
> I believe that I have coded the following form:
> '((scheme-user-keywords-regexp 1 scheme-font-lock-user-keywords-face t))
> Incorrectly, so that 'scheme-user-keywords-regexp is being treated 
> as a function when the hook is run.

By reading docs for `font-lock-add-keywords` function and
`font-lock-keywords`, you may find out that each element of keywords
list starts from either regexp or name of function to be called to match
string for highlighting. Since you've used the quote syntax,
`scheme-user-keywords` is added into the list of font lock rules as a
symbol and is then treated as a function name. You may use the
quasiquote syntax to evaluate just one element of list you use for
`font-lock-add-keywords`:

    (add-hook 'scheme-mode-hook
              (lambda ()
                (font-lock-add-keywords 
                 nil 
                 `((,scheme-user-keywords-regexp 0 scheme-font-lock-user-keywords-face t)))))

So *the value* of `scheme-user-keywords-regexp` gets into the list.

Note that since your matcher regular expression has no subexpressions,
you must use index 0 to highlight the whole matched string; instead, you
could've just used this:

    (add-hook 'scheme-mode-hook
              (lambda ()
                (font-lock-add-keywords 
                 nil 
                 `((,scheme-user-keywords-regexp . scheme-font-lock-user-keywords-face)))))
-- 
Happy Hacking.

http://sphinx.net.ru^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Evaluating a 'variable' in a nested list
  2010-04-21 19:16 ` Dmitry Dzhus
@ 2010-04-21 21:44   ` Tim Johnson
  0 siblings, 0 replies; 3+ messages in thread
From: Tim Johnson @ 2010-04-21 21:44 UTC (permalink / raw
  To: help-gnu-emacs

On 2010-04-21, Dmitry Dzhus <dima@sphinx.net.ru> wrote:
> Tim Johnson wrote:
<<..>> Incorrectly, so that 'scheme-user-keywords-regexp is being treated 
>> as a function when the hook is run.
>
> By reading docs for `font-lock-add-keywords` function and
> `font-lock-keywords`, you may find out that each element of keywords
> list starts from either regexp or name of function to be called to match
> string for highlighting. Since you've used the quote syntax,
> `scheme-user-keywords` is added into the list of font lock rules as a
> symbol and is then treated as a function name. You may use the
> quasiquote syntax to evaluate just one element of list you use for
> `font-lock-add-keywords`:
 I did find the quasi-quote solution independently, but thank you for
 the explanation above. That explains things quite well.

> (add-hook 'scheme-mode-hook
>           (lambda ()
>             (font-lock-add-keywords 
>               nil 
>               `((,scheme-user-keywords-regexp 0 
>                   scheme-font-lock-user-keywords-face t)))))
>
> So *the value* of `scheme-user-keywords-regexp` gets into the list.
 :)
> Note that since your matcher regular expression has no subexpressions,
> you must use index 0 to highlight the whole matched string; instead, you
> could've just used this:
 And I did arrive at index 0 myself. Your reformatted example below
> (add-hook 'scheme-mode-hook
>    (lambda ()
>       (font-lock-add-keywords 
>        nil 
>         `((,scheme-user-keywords-regexp . ;; Note the dot
>           scheme-font-lock-user-keywords-face)))))
  Ah!  
	Thanks very much

-- 
Tim 
tim@ johnsons-web.com||akwebsoft.com
http://www.akwebsoft.com


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

end of thread, other threads:[~2010-04-21 21:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-21  1:44 Evaluating a 'variable' in a nested list Tim Johnson
2010-04-21 19:16 ` Dmitry Dzhus
2010-04-21 21:44   ` Tim Johnson

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.