* Adding a font-lock face to a major mode
@ 2006-01-04 17:16 Tim Johnson
2006-01-05 2:07 ` Adding a font-lock face to a major mode/revisited Tim Johnson
0 siblings, 1 reply; 4+ messages in thread
From: Tim Johnson @ 2006-01-04 17:16 UTC (permalink / raw)
Hi:
I would like to be able to add a font-lock face to a major mode at load
time.
I've written the following code in a file called lisp-mode++.
I need some help in adding the face properly.
FYI: *If possible*, I'd like this to be cross-compatible to Xemacs.
but is not a critical need.
;; code follows:
(defconst tj-word-end "\\)\\b")
(defconst tj-word-begin "\\b\\(")
(defconst tj-lisp-user-keywords
(concat tj-word-begin ;; test some symbols not highlighted
(regexp-opt '( "and" "apply" "concatenate" "format" "funcall" "list" "lambda"
"mapcar" "not" "print" "push" "return-from " "setf" "setq"))
tj-word-end))
(add-hook 'lisp-mode-hook
'(lambda ()
(require 'extra-faces) ;; font-lock-user-keyword-face defined here
'turn-on-font-lock
(cons font-lock-defaults ;; this is wrong, I know!
(list tj-lisp-user-keywords '1 'font-lock-user-keyword-face))
(message "lisp-mode++ loaded"))) ;; test!
(provide 'lisp-mode++) ;; .emacs has (require 'lisp-mode++)
;;
TIA
tim
--
Tim Johnson <tim@johnsons-web.com>
http://www.alaska-internet-solutions.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Adding a font-lock face to a major mode/revisited
2006-01-04 17:16 Adding a font-lock face to a major mode Tim Johnson
@ 2006-01-05 2:07 ` Tim Johnson
2006-01-05 2:11 ` Tim Johnson
2006-01-05 16:38 ` Kevin Rodgers
0 siblings, 2 replies; 4+ messages in thread
From: Tim Johnson @ 2006-01-05 2:07 UTC (permalink / raw)
After studying documentation, I have taken a different approach.
Code for lisp-mode++.el is not as follows:
;;
(defconst tj-word-end "\\)\\b")
(defconst tj-lisp-user-keywords
(concat tj-word-begin
(regexp-opt '("and" "apply" "concatenate" "format" "funcall" "list" "lambda"
"mapcar" "not" "print" "push" "return-from " "setf" "setq")
) tj-word-end))
(make-local-variable 'lisp-font-lock-keywords-tj)
(defvar lisp-font-lock-keywords-tj
(list
(list tj-lisp-user-keywords '1 'font-lock-user-keyword-face))
"Additional keywords and groups for lisp-mode")
(add-hook 'lisp-mode-hook
'(lambda ()
(require 'extra-faces) ;; font-lock-user-keyword-face defined here
'turn-on-font-lock
;; I have tried both of the lines below, with no good effect
(put 'lisp-mode 'font-lock-defaults '(lisp-font-lock-keywords-tj))
;(cons font-lock-defaults lisp-font-lock-keywords-tj)
(message "lisp-mode++ loaded")))
(provide 'lisp-mode++) ;; .emacs has (require 'lisp-mode++)
;;
What works:
'add hook is being executed.
I see the message
Even with "debug on error" turned on, there are no errors.
the 'require form is being evaluated as
'font-lock-user-keyword-face appears as a defined variable.
lisp-font-lock-keywords-tj appears as a defined variable.
The regex part of the variable seems to work as tested with
re-builder
What doesn't work:
No syntax highlighting appears for the keywords.
c-h v font-lock-defaults => provides a printed representation
that does not show lisp-font-lock-keywords-tj as a component of
that variable.
Unfortunately I have not yet found any examples to work from. I suspect
that neither the 'put nor the 'cons calls are wrong.
Any help would be appreciated.
tim
--
Tim Johnson <tim@johnsons-web.com>
http://www.alaska-internet-solutions.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Adding a font-lock face to a major mode/revisited
2006-01-05 2:07 ` Adding a font-lock face to a major mode/revisited Tim Johnson
@ 2006-01-05 2:11 ` Tim Johnson
2006-01-05 16:38 ` Kevin Rodgers
1 sibling, 0 replies; 4+ messages in thread
From: Tim Johnson @ 2006-01-05 2:11 UTC (permalink / raw)
* Tim Johnson <tim@johnsons-web.com> [060104 17:09]:
There is a typo here:
where I said:
> Unfortunately I have not yet found any examples to work from. I suspect
> that neither the 'put nor the 'cons calls are wrong.
I meant to say that it appears that
neither the 'put nor the 'cons cells are correct.
Ssoorryy!
tj
> After studying documentation, I have taken a different approach.
> Code for lisp-mode++.el is not as follows:
> ;;
> (defconst tj-word-end "\\)\\b")
> (defconst tj-lisp-user-keywords
> (concat tj-word-begin
> (regexp-opt '("and" "apply" "concatenate" "format" "funcall" "list" "lambda"
> "mapcar" "not" "print" "push" "return-from " "setf" "setq")
> ) tj-word-end))
> (make-local-variable 'lisp-font-lock-keywords-tj)
> (defvar lisp-font-lock-keywords-tj
> (list
> (list tj-lisp-user-keywords '1 'font-lock-user-keyword-face))
> "Additional keywords and groups for lisp-mode")
> (add-hook 'lisp-mode-hook
> '(lambda ()
> (require 'extra-faces) ;; font-lock-user-keyword-face defined here
> 'turn-on-font-lock
> ;; I have tried both of the lines below, with no good effect
> (put 'lisp-mode 'font-lock-defaults '(lisp-font-lock-keywords-tj))
> ;(cons font-lock-defaults lisp-font-lock-keywords-tj)
> (message "lisp-mode++ loaded")))
> (provide 'lisp-mode++) ;; .emacs has (require 'lisp-mode++)
> ;;
> What works:
> 'add hook is being executed.
> I see the message
> Even with "debug on error" turned on, there are no errors.
> the 'require form is being evaluated as
> 'font-lock-user-keyword-face appears as a defined variable.
> lisp-font-lock-keywords-tj appears as a defined variable.
> The regex part of the variable seems to work as tested with
> re-builder
> What doesn't work:
> No syntax highlighting appears for the keywords.
> c-h v font-lock-defaults => provides a printed representation
> that does not show lisp-font-lock-keywords-tj as a component of
> that variable.
>
> Unfortunately I have not yet found any examples to work from. I suspect
> that neither the 'put nor the 'cons calls are wrong.
>
> Any help would be appreciated.
> tim
>
> --
> Tim Johnson <tim@johnsons-web.com>
> http://www.alaska-internet-solutions.com
>
>
> _______________________________________________
> help-gnu-emacs mailing list
> help-gnu-emacs@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
--
Tim Johnson <tim@johnsons-web.com>
http://www.alaska-internet-solutions.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Adding a font-lock face to a major mode/revisited
2006-01-05 2:07 ` Adding a font-lock face to a major mode/revisited Tim Johnson
2006-01-05 2:11 ` Tim Johnson
@ 2006-01-05 16:38 ` Kevin Rodgers
1 sibling, 0 replies; 4+ messages in thread
From: Kevin Rodgers @ 2006-01-05 16:38 UTC (permalink / raw)
Tim Johnson wrote:
> (make-local-variable 'lisp-font-lock-keywords-tj)
Why?
> (add-hook 'lisp-mode-hook
> '(lambda ()
> (require 'extra-faces) ;; font-lock-user-keyword-face
defined here
> 'turn-on-font-lock
That quoted symbol inside the lambda body has no effect whatsoever. I
think you want to call the function, so either do so: (turn-on-font-lock)
or add it as a separate hook: (add-hook 'lisp-mode-hook 'turn-on-font-lock)
> ;; I have tried both of the lines below, with no good effect
> (put 'lisp-mode 'font-lock-defaults
'(lisp-font-lock-keywords-tj))
> ;(cons font-lock-defaults lisp-font-lock-keywords-tj)
I don't see anything in the documentation that suggests that the
font-lock-defaults property of a major-mode has any effect. I think you
want:
(set (make-local-variable 'font-lock-defaults) lisp-font-lock-keywords-tj)
or perhaps:
(set (make-local-variable 'font-lock-defaults)
(append font-lock-defaults lisp-font-lock-keywords-tj))
> (message "lisp-mode++ loaded")))
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-01-05 16:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-04 17:16 Adding a font-lock face to a major mode Tim Johnson
2006-01-05 2:07 ` Adding a font-lock face to a major mode/revisited Tim Johnson
2006-01-05 2:11 ` Tim Johnson
2006-01-05 16:38 ` Kevin Rodgers
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).