lazy-lock-after-change
10 years, 2 months
Jerry James
I use cc-mode's electric behavior, which is great, except that whenever I
type a '}' as the last character in a buffer, I get something like this:
(1) (change/warning) Error in `after-change-functions': (args-out-of-range
(foo.c 99 100))
Backtrace follows:
# bind (inhibit-quit)
put-text-property(99 100 font-lock-pending t)
# bind (old-len end beg)
ad-Orig-font-lock-after-change-function(99 100 1)
(setq ad-return-value (ad-Orig-font-lock-after-change-function beg end
old-len))
# bind (ad-return-value)
(let (ad-return-value) (when c-buffer-is-cc-mode (save-excursion (setq
end c-new-END) (setq beg c-new-BEG))) (setq ad-return-value
(ad-Orig-font-lock-after-change-function beg end old-len)) ad-return-value)
# bind (old-len end beg)
font-lock-after-change-function(99 99 1)
# (unwind-protect ...)
# bind (old-len end beg)
lazy-lock-after-change(99 99 1)
# (unwind-protect ...)
# (catch #<INTERNAL OBJECT (XEmacs bug?) (opaque, size=0) 0x0> ...)
# (unwind-protect ...)
# (unwind-protect ...)
# (unwind-protect ...)
delete-char(-1)
byte-code("..." [start delete-char -1] 2)
# bind (c-syntactic-context c-macro-start c-fix-backslashes has-backslash
insert-backslash start col newline-arg)
c-newline-and-indent()
# bind (c-echo-syntactic-information-p newlines ln-syntax br-syntax
syntax old-blink-paren safepos literal blink-paren-function
case-fold-search arg)
c-electric-brace(nil)
# bind (command-debug-status)
call-interactively(c-electric-brace)
# (condition-case ... . error)
# (catch top-level ...)
The immediate problem is that the original font-lock-after-change-function
is called with begin and end arguments equal to 99 and 100, even though 99
is the last valid position in the buffer. We can see that the adviced
font-lock-after-change-function got called with 99 and 99, which is
correct, so the problem is that the adviced function is screwing up the end
argument somehow. The adviced function looks like this:
(defadvice font-lock-after-change-function (before get-awk-region activate)
;; Make sure that any string/regexp is completely font-locked.
(when c-buffer-is-cc-mode
(save-excursion
(ad-set-arg 1 c-new-END) ; end
(ad-set-arg 0 c-new-BEG))))) ; beg
Therefore, c-new-END is wrong. Why? The value of after-change-functions
is (lazy-lock-after-change c-after-change t) in the C buffer. There's the
problem. We need c-after-change to run first, to update the caches, then
lazy-lock-after-change can run on the updated region.
So the bug is in, I think, xemacs-packages/edit-utils/lazy-lock.el, which
does this:
(add-hook 'after-change-functions 'lazy-lock-after-change nil t)
when I think it should be doing this:
(add-hook 'after-change-functions 'lazy-lock-after-change t t)
Opinions?
--
Jerry James
http://www.jamezone.org/
_______________________________________________
XEmacs-Beta mailing list
XEmacs-Beta(a)xemacs.org
http://lists.xemacs.org/mailman/listinfo/xemacs-beta