I have a macro in an elisp package that lets me define functions in a
special way.
To get those function definitions font-locked I have the following
lines at the end of the file:
;;;Local Variables:
;;;eval:(font-lock-add-keywords nil '(("(\\(gpf-define-state-machine\\)\\>\\s-*\\(\\<\\w+\\>\\)" (1 font-lock-keyword-face) (2 font-lock-function-name-face))))
;;;End:
However, using this I have to confirm the evaluation each time I open
the file. Is it possible to add this font-lock keywords in a way that
is considered "safe" and does not need confirmation?
I want to distribute this package and the self-defined font-lock
makes it much clearer what the purpose of those parts in the code is.
-- Oliver
--
3 Messidor an 210 de la Révolution
Liberté, Egalité, Fraternité!
Notice that `font-lock-keyword-face' does not have a quote
around it: it's actually a variable name (and the variable's
value is the face `font-lock-keyword-face'). Font-lock allows
any expression in that position, so it's inherently dangerous unless
Emacs analyses the whole font-lock keyword to see if the expressions
used are safe.
> I want to distribute this package and the self-defined font-lock
> makes it much clearer what the purpose of those parts in the code is.
Check out hi-lock.el (in Emacs-21). It might be good enough.
Stefan
>>>>>> "os" == Oliver Scholz <alkib...@gmx.de> writes:
>> ;;;eval:(font-lock-add-keywords nil '(("(\\(gpf-define-state-machine\\)\\>\\s-*\\(\\<\\w+\\>\\)" (1 font-lock-keyword-face) (2 font-lock-function-name-face))))
>
> Notice that `font-lock-keyword-face' does not have a quote
> around it: it's actually a variable name (and the variable's
> value is the face `font-lock-keyword-face'). Font-lock allows
> any expression in that position, so it's inherently dangerous unless
> Emacs analyses the whole font-lock keyword to see if the expressions
> used are safe.
[...]
Ah, I see. Thank you.
> Check out hi-lock.el (in Emacs-21). It might be good enough.
Thanks. I found this at the end of the commentary in hi-lock.el:
,----[ hi-lock.el ]
| Sample file patterns:
|
| Hi-lock: (("^;;; .*" (0 (quote hi-black-hb) t)))
| Hi-lock: ( ("make-variable-buffer-\\(local\\)" (0 font-lock-keyword-face)(1 'italic append)))))
| Hi-lock: end
`----
But this doesn't seem to work. (Even not if I remove the superfluous
closing parens at the end.) In fact I am not sure, how I should
understand this part of the commentary, anyway. Is this actually
supposed to be part of a local variables section? What is the
"Hi-lock: end" for?
-- Oliver
--
4 Messidor an 210 de la Révolution
Liberté, Egalité, Fraternité!
> ,----[ hi-lock.el ]
> | Sample file patterns:
> |
> | Hi-lock: (("^;;; .*" (0 (quote hi-black-hb) t)))
> | Hi-lock: ( ("make-variable-buffer-\\(local\\)" (0 font-lock-keyword-face)(1 'italic append)))))
> | Hi-lock: end
> `----
> But this doesn't seem to work. (Even not if I remove the superfluous
> closing parens at the end.) In fact I am not sure, how I should
> understand this part of the commentary, anyway. Is this actually
> supposed to be part of a local variables section?
Yes. Check the end of the hi-lock.el file (it uses itself :-).
> What is the "Hi-lock: end" for?
That's part of the local variables section syntax.
The sample was missing the `Hi-lock: begin', tho.
Stefan
>>>>>> "os" == Oliver Scholz <alkib...@gmx.de> writes:
>> Thanks. I found this at the end of the commentary in hi-lock.el:
>
>> ,----[ hi-lock.el ]
>> | Sample file patterns:
>> |
>> | Hi-lock: (("^;;; .*" (0 (quote hi-black-hb) t)))
>> | Hi-lock: ( ("make-variable-buffer-\\(local\\)" (0 font-lock-keyword-face)(1 'italic append)))))
>> | Hi-lock: end
>> `----
>
>> But this doesn't seem to work. (Even not if I remove the superfluous
>> closing parens at the end.) In fact I am not sure, how I should
>> understand this part of the commentary, anyway. Is this actually
>> supposed to be part of a local variables section?
>
> Yes. Check the end of the hi-lock.el file (it uses itself :-).
[...]
Ah! Judging from the syntax I guessed that this has to be part of the
local variables sections at the _end_ of a file.
That's wrong. It is supposed to be at the _beginning_ of a file:
,----[ C-h f hi-lock-mode RET ]
| [...]
| When hi-lock is started and if the mode is not excluded, the
| beginning of the buffer is searched for lines of the form:
| Hi-lock: FOO
| where FOO is a list of patterns. These are added to the font lock keywords
| already present. The patterns must start before position (number
| of characters into buffer) `hi-lock-file-patterns-range'. Patterns
| will be read until
| Hi-lock: end
| is found. A mode is excluded if it's in the list `hi-lock-exclude-modes'.
`----
And I have to turn hi-lock mode on, to see the results.
Well, that's cool!
Thanks you very much! This is o.k. for me so far, it is a good
work-around for myself.
It would be nice, though, if there could be a special command (a
pseudo-variable) for the local variables section à la ";;;font-lock:
..." to add keywords to font-lock for a single file only. A command
that does not have the security problems you mentioned for
`font-lock-add-keywords'. Of course, I don't know if this is possible
at all.
But if one extends Lisp with functions and macros it would be nice to
give Emacs some hints on how to deal with the new syntax.
For example this is possible for indentation:
;;;Local Variables:
;;;eval:(put 'my-fancy-macro 'lisp-indent-hook 2)
;;;End:
It would be consequent to have something for font-lock, too. Is this
such an uncommon request?
But again: thank you very much!
-- Oliver
--
5 Messidor an 210 de la Révolution
Liberté, Egalité, Fraternité!
Looks like I was wrong, huh!?
> It would be nice, though, if there could be a special command (a
> pseudo-variable) for the local variables section à la ";;;font-lock:
> ..." to add keywords to font-lock for a single file only. A command
> that does not have the security problems you mentioned for
> `font-lock-add-keywords'. Of course, I don't know if this is possible
> at all.
Yes, it could be useful. Some modes provide variables to do some limited
form of customization, such as c-font-lock-extra-types in c-mode.
> But if one extends Lisp with functions and macros it would be nice to
> give Emacs some hints on how to deal with the new syntax.
In your case, I'd recommend you use `define-gpf-state-machine' rather
than `gpf-define-state-machine'. I know one should normally obey the
`gpf-' prefix convention, but symbols that start with `def' are generally
recognized as special constructs, so you can take advantage of it.
I can't remember if it also helps the indentation, but it might.
> It would be consequent to have something for font-lock, too.
> Is this such an uncommon request?
I guess most people just live with what they have without thinking about
what they could have.
Stefan