[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Bug fix for hi-lock mode.
Bug fix for hi-lock mode.
Tue, 05 Oct 2010 10:25:03 -0500
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)
The following patch fixes hi-lock, a minor mode I wrote, which was
broken some time ago due to changes in font-lock behavior.
Problems were due to font-lock-mode turning off and back on again,
that would turn off hi-lock mode. Now, turning off font lock does not
turn off hi-lock. Another problem was due to hi-lock adding keywords
when font lock mode was on (font-lock-mode non-nil) but
font-lock-keywords was nil, that would clobber non-font-lock
highlighting (Bug 635). Now hi-lock uses font-lock-fontified to decide
whether to add keywords to font lock. (If font-lock-fontified is nil
hi-lock will apply its own overlays for highlighting.)
I don't like using font-lock-fontified to determine whether font lock
is active because it's more of an internal font-lock
variable. However, it's the best solution I can come up with at the
moment (and the existing hi-lock code had been using
font-lock-fontified for some time).
Here is a change log entry followed by a patch. Could someone
check this in if it's suitable.
2010-10-05 David Koppelman <address@hidden>
* hi-lock.el (hi-lock-font-lock-hook): Check font-lock-fontified
instead of font-lock-mode before adding keywords. Removed
hi-lock-mode off code. Removed inhibit hack.
(hi-lock-set-pattern): Only add keywords if font-lock-fontified
non-nil; removed hook inhibit hack.
=== modified file 'lisp/hi-lock.el'
--- lisp/hi-lock.el 2010-01-13 08:35:10 +0000
+++ lisp/hi-lock.el 2010-10-05 14:18:04 +0000
@@ -564,23 +564,15 @@ not suitable."
-(defvar hi-lock--inhibit-font-lock-hook nil
- "Inhibit the action of `hi-lock-font-lock-hook'.
-This is used by `hi-lock-set-pattern'.")
(defun hi-lock-set-pattern (regexp face)
"Highlight REGEXP with face FACE."
- (let ((pattern (list regexp (list 0 (list 'quote face) t)))
- ;; The call to `font-lock-add-keywords' below might disable
- ;; and re-enable font-lock mode. If so, we don't want
- ;; `hi-lock-font-lock-hook' to run. This can be removed once
- ;; Bug#635 is fixed. -- cyd
- (hi-lock--inhibit-font-lock-hook t))
+ (let ((pattern (list regexp (list 0 (list 'quote face) t))))
(unless (member pattern hi-lock-interactive-patterns)
- (font-lock-add-keywords nil (list pattern) t)
(push pattern hi-lock-interactive-patterns)
+ (font-lock-add-keywords nil (list pattern) t)
(let* ((serial (hi-lock-string-serialize regexp))
(range-min (- (point) (/ hi-lock-highlight-range 2)))
(range-max (+ (point) (/ hi-lock-highlight-range 2)))
@@ -641,12 +633,9 @@ This is used by `hi-lock-set-pattern'.")
(defun hi-lock-font-lock-hook ()
"Add hi-lock patterns to font-lock's."
- (unless hi-lock--inhibit-font-lock-hook
- (if font-lock-mode
+ (when font-lock-fontified
(font-lock-add-keywords nil hi-lock-file-patterns t)
- (font-lock-add-keywords nil hi-lock-interactive-patterns t))
- (hi-lock-mode -1))))
+ (font-lock-add-keywords nil hi-lock-interactive-patterns t)))
(make-hash-table :test 'equal)
- Bug fix for hi-lock mode.,
David Koppelman <=