[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: cannot activate font-lock-mode
From: |
Stefan Monnier |
Subject: |
Re: cannot activate font-lock-mode |
Date: |
Fri, 20 Apr 2007 14:35:27 -0400 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.97 (gnu/linux) |
>> Now, when desktop.el loads it, it asks if I want to apply the
>> font-lock-keywords customisation, because it is risky (is it?).
> Font-lock can modify arbitrary text properties, such as display
> strings, and not just faces.
And it can also directly run any code, which is even more immediately scary.
We should probably write a font-lock-keywords-safe-p. Something like the
one below, maybe.
Stefan
--- orig/lisp/font-lock.el
+++ mod/lisp/font-lock.el
@@ -454,6 +454,23 @@
user-level keywords, but normally their values have been
optimized.")
+(defun font-lock-keywords-safe-p (val)
+ (catch 'unsafe
+ (while (consp val)
+ (let ((kw (pop val)))
+ (unless (stringp (pop kw)) (throw 'unsafe nil))
+ (while (consp kw)
+ (let ((hl (pop kw)))
+ (unless (natnump (pop hl)) (throw 'unsafe nil))
+ (unless (or (symbolp (car hl))
+ (and (eq 'quote (safe-car (car hl)))
+ (symbolp (safe-car (cdar hl)))))
+ (throw 'unsafe nil))))
+ (when kw (throw 'unsafe nil))))
+ (when val (throw 'unsafe nil))
+ t))
+(put 'font-lock-keywords 'safe-local-variable 'font-lock-keywords-safe-p)
+
(defvar font-lock-keywords-alist nil
"Alist of additional `font-lock-keywords' elements for major modes.