Function: c-after-change
c-after-change is a byte-compiled function defined in cc-mode.el.gz.
Signature
(c-after-change BEG END OLD-LEN)
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cc-mode.el.gz
;; A flag to prevent region expanding stuff being done twice for after-change
;; fontification.
(defun c-after-change (beg end old-len)
;; Function put on `after-change-functions' to adjust various caches
;; etc. Prefer speed to finesse here, since there will be an order
;; of magnitude more calls to this function than any of the
;; functions that use the caches.
;;
;; Note that care must be taken so that this is called before any
;; font-lock callbacks since we might get calls to functions using
;; these caches from inside them, and we must thus be sure that this
;; has already been executed.
;;
;; This calls the language variable c-before-font-lock-functions, if non-nil.
;; This typically sets `syntax-table' properties.
;; We can sometimes get two consecutive calls to `after-change-functions'
;; without an intervening call to `before-change-functions' when reverting
;; the buffer (see bug #24094). Whatever the cause, assume that the entire
;; buffer has changed.
;; Note: c-just-done-before-change is nil, t, or 'whole-buffer.
(unless (c-called-from-text-property-change-p)
(unless (eq c-just-done-before-change t)
(save-restriction
(widen)
(when (null c-just-done-before-change)
(c-before-change (point-min) (point-max)))
(setq beg (point-min)
end (point-max)
old-len (- end beg)
c-new-BEG (point-min)
c-new-END (point-max)))))
;; (c-new-BEG c-new-END) will be the region to fontify. It may become
;; larger than (beg end).
(setq c-new-END (- (+ c-new-END (- end beg)) old-len))
(unless (c-called-from-text-property-change-p)
(setq c-just-done-before-change nil)
(c-save-buffer-state (case-fold-search)
;; When `combine-after-change-calls' is used we might get calls
;; with regions outside the current narrowing. This has been
;; observed in Emacs 20.7.
(save-restriction
(save-match-data ; c-recognize-<>-arglists changes match-data
(widen)
(c-with-string-fences
(when (> end (point-max))
;; Some emacsen might return positions past the end. This
;; has been observed in Emacs 20.7 when rereading a buffer
;; changed on disk (haven't been able to minimize it, but
;; Emacs 21.3 appears to work).
(setq end (point-max))
(when (> beg end)
(setq beg end)))
;; C-y is capable of spuriously converting category
;; properties c-</>-as-paren-syntax and
;; c-cpp-delimiter into hard syntax-table properties.
;; Remove these when it happens.
(when (eval-when-compile (memq 'category-properties c-emacs-features))
(c-save-buffer-state ()
(c-clear-char-property-with-value beg end 'syntax-table
c-<-as-paren-syntax)
(c-clear-char-property-with-value beg end 'syntax-table
c->-as-paren-syntax)
(c-clear-char-property-with-value beg end 'syntax-table nil)))
(c-update-new-id end)
(c-trim-found-types beg end old-len) ; maybe we don't
; need all of these.
(c-after-change-de-typedef beg end old-len)
(c-invalidate-sws-region-after beg end old-len)
;; (c-invalidate-state-cache beg) ; moved to
;; `c-before-change'.
(c-invalidate-find-decl-cache beg)
(when c-recognize-<>-arglists
(c-after-change-check-<>-operators beg end))
(setq c-in-after-change-fontification t)
(save-excursion
(mapc (lambda (fn)
(funcall fn beg end old-len))
c-before-font-lock-functions)))))
;; A workaround for syntax-ppss's failure to notice syntax-table text
;; property changes.
(when (fboundp 'syntax-ppss)
(syntax-ppss-flush-cache c-syntax-table-hwm)))))