]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/cc-mode.el
; Merge from origin/emacs-25
[gnu-emacs] / lisp / progmodes / cc-mode.el
index 5d8af2399727ac9c1192c75bb3c897622559b976..2ab1d6b0d709213be439e0cdd7f840407ed2cc49 100644 (file)
@@ -1,6 +1,6 @@
 ;;; cc-mode.el --- major mode for editing C and similar languages
 
-;; Copyright (C) 1985, 1987, 1992-2015 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1987, 1992-2016 Free Software Foundation, Inc.
 
 ;; Authors:    2003- Alan Mackenzie
 ;;             1998- Martin Stjernholm
 ;; derived-mode-ex.el>.
 
 (defun c-leave-cc-mode-mode ()
-  (setq c-buffer-is-cc-mode nil))
+  (when c-buffer-is-cc-mode
+    (save-restriction
+      (widen)
+      (c-save-buffer-state ()
+       (c-clear-char-properties (point-min) (point-max) 'category)
+       (c-clear-char-properties (point-min) (point-max) 'syntax-table)
+       (c-clear-char-properties (point-min) (point-max) 'c-is-sws)
+       (c-clear-char-properties (point-min) (point-max) 'c-in-sws)
+       (c-clear-char-properties (point-min) (point-max) 'c-type)
+       (if (c-major-mode-is 'awk-mode)
+           (c-clear-char-properties (point-min) (point-max) 'c-awk-NL-prop))))
+    (setq c-buffer-is-cc-mode nil)))
 
 (defun c-init-language-vars-for (mode)
   "Initialize the language variables for one of the language modes
@@ -585,6 +596,7 @@ that requires a literal mode spec at compile time."
                                     (not (string-equal c-indentation-style
                                                        style)))))))
   (c-setup-paragraph-variables)
+  (c-make-noise-macro-regexps)
 
   ;; we have to do something special for c-offsets-alist so that the
   ;; buffer local value has its own alist structure.
@@ -631,8 +643,11 @@ that requires a literal mode spec at compile time."
     (font-lock-mode 1)))
 
 ;; Buffer local variables defining the region to be fontified by a font lock
-;; after-change function.  They are set in c-after-change to
-;; after-change-functions' BEG and END, and may be modified by functions in
+;; after-change function.  They are initialized in c-before-change to
+;; before-change-functions' BEG and END.  `c-new-END' is amended in
+;; c-after-change with after-change-functions' BEG, END, and OLD-LEN.  These
+;; variables may be modified by any before/after-change function, in
+;; particular by functions in `c-get-state-before-change-functions' and
 ;; `c-before-font-lock-functions'.
 (defvar c-new-BEG 0)
 (make-variable-buffer-local 'c-new-BEG)
@@ -1032,6 +1047,8 @@ Note that the style variables are always made local to the buffer."
              c-just-done-before-change) ; guard against a spurious second
                                        ; invocation of before-change-functions.
     (setq c-just-done-before-change t)
+    ;; (c-new-BEG c-new-END) will be the region to fontify.
+    (setq c-new-BEG beg  c-new-END end)
     (setq c-maybe-stale-found-type nil)
     (save-restriction
       (save-match-data
@@ -1126,7 +1143,8 @@ Note that the style variables are always made local to the buffer."
 
   ;; (c-new-BEG c-new-END) will be the region to fontify.  It may become
   ;; larger than (beg end).
-  (setq c-new-BEG beg  c-new-END end)
+  ;; (setq c-new-BEG beg  c-new-END 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)
@@ -1245,7 +1263,8 @@ Note that the style variables are always made local to the buffer."
   (save-restriction
     (widen)
     (save-excursion
-      (let ((new-beg beg) (new-end end) new-region)
+      (let ((new-beg beg) (new-end end)
+           (new-region (cons beg end)))
        (mapc (lambda (fn)
                (setq new-region (funcall fn new-beg new-end))
                (setq new-beg (car new-region) new-end (cdr new-region)))
@@ -1328,12 +1347,13 @@ This function is called from `c-common-init', once per mode initialization."
           . c-mark-function)))
 
   ;; Prevent `font-lock-default-fontify-region' extending the region it will
-  ;; fontify to whole lines by removing `font-lock-extend-region-whole-lines'
-  ;; (and, coincidentally, `font-lock-extend-region-multiline' (which we do
-  ;; not need)) from `font-lock-extend-region-functions'.  (Emacs only).  This
-  ;; fixes Emacs bug #19669.
+  ;; fontify to whole lines by removing `font-lock-extend-region-wholelines'
+  ;; from `font-lock-extend-region-functions'.  (Emacs only).  This fixes
+  ;; Emacs bug #19669.
   (when (boundp 'font-lock-extend-region-functions)
-    (setq font-lock-extend-region-functions nil))
+    (setq font-lock-extend-region-functions
+         (delq 'font-lock-extend-region-wholelines
+               font-lock-extend-region-functions)))
 
   (make-local-variable 'font-lock-fontify-region-function)
   (setq font-lock-fontify-region-function 'c-font-lock-fontify-region)