Hi, Jerry.
On Mon, Aug 11, 2014 at 09:15:41AM -0600, Jerry James wrote:
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, ....
If you have just typed a '}', why is it correct that the BEG and END
arguments are equal? Surely they should differ by 1, or even more if
you've got auto-newline enabled for '}'.
.... 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.
Yes.
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?
I think the bug here may be rather that font-lock-mode-hook is not being
invoked when lazy-lock is active. CC Mode installs
c-after-font-lock-init on font-lock-mode-hook; that function ensures that
c-after-change comes first in after-change-functions.
I think {before,after}-change-functions belong more to the major mode
than any active minor modes; how can font-lock know whether its
a-c-function should be last?
#########################################################################
Incidentally, I've had problems setting up my XEmacs to use lazy-lock -
it's not well documented. In my init.el I've got
(require 'font-lock)
, which automatically sets font-lock-auto-fontify, and
(setq font-lock-support-mode 'lazy-lock-mode)
, which ought to cause lazy-lock to be enabled when a file is loaded into
a buffer. It doesn't - after-change-functions contains
font-lock-after-change-function, not the lazy one. What am I doing
wrong, here?
Incidentally2, when I reinitialise C Mode (with M-x c-mode), font lock
gets turned off for that buffer. I think it's XEmacs doing this, not CC
Mode. Is this intentional? It feels wrong.
--
Alan Mackenzie (Nuremberg, Germany).
_______________________________________________
XEmacs-Beta mailing list
XEmacs-Beta(a)xemacs.org
http://lists.xemacs.org/mailman/listinfo/xemacs-beta