aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/progmodes/cc-mode.el128
1 files changed, 76 insertions, 52 deletions
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 1f58ba1ee9b..3c1aec472cd 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -511,6 +511,14 @@ that requires a literal mode spec at compile time."
511 (set (make-local-variable 'comment-line-break-function) 511 (set (make-local-variable 'comment-line-break-function)
512 'c-indent-new-comment-line) 512 'c-indent-new-comment-line)
513 513
514 ;; Prevent time-wasting activity on C-y.
515 (when (boundp 'yank-handled-properties)
516 (make-local-variable 'yank-handled-properties)
517 (let ((yank-cat-handler (assq 'category yank-handled-properties)))
518 (when yank-cat-handler
519 (setq yank-handled-properties (remq yank-cat-handler
520 yank-handled-properties)))))
521
514 ;; For the benefit of adaptive file, which otherwise mis-fills. 522 ;; For the benefit of adaptive file, which otherwise mis-fills.
515 (setq fill-paragraph-handle-comment nil) 523 (setq fill-paragraph-handle-comment nil)
516 524
@@ -839,6 +847,18 @@ Note that the style variables are always made local to the buffer."
839(defvar c-old-EOM 0) 847(defvar c-old-EOM 0)
840(make-variable-buffer-local 'c-old-EOM) 848(make-variable-buffer-local 'c-old-EOM)
841 849
850(defun c-called-from-text-property-change-p ()
851 ;; Is the primitive which invoked `before-change-functions' or
852 ;; `after-change-functions' one which merely changes text properties? This
853 ;; function must be called directly from a member of one of the above hooks.
854 ;;
855 ;; In the following call, frame 0 is `backtrace-frame', frame 1 is
856 ;; `c-called-from-text-property-change-p', frame 2 is
857 ;; `c-before/after-change', frame 3 is the primitive invoking the change
858 ;; hook.
859 (memq (cadr (backtrace-frame 3))
860 '(put-text-property remove-list-of-text-properties)))
861
842(defun c-extend-region-for-CPP (beg end) 862(defun c-extend-region-for-CPP (beg end)
843 ;; Set c-old-BOM or c-old-EOM respectively to BEG, END, each extended to the 863 ;; Set c-old-BOM or c-old-EOM respectively to BEG, END, each extended to the
844 ;; beginning/end of any preprocessor construct they may be in. 864 ;; beginning/end of any preprocessor construct they may be in.
@@ -1009,8 +1029,9 @@ Note that the style variables are always made local to the buffer."
1009 ;; it/them from the cache. Don't worry about being inside a string 1029 ;; it/them from the cache. Don't worry about being inside a string
1010 ;; or a comment - "wrongly" removing a symbol from `c-found-types' 1030 ;; or a comment - "wrongly" removing a symbol from `c-found-types'
1011 ;; isn't critical. 1031 ;; isn't critical.
1012 (unless c-just-done-before-change ; Guard against a spurious second 1032 (unless (or (c-called-from-text-property-change-p)
1013 ; invocation of before-change-functions. 1033 c-just-done-before-change) ; guard against a spurious second
1034 ; invocation of before-change-functions.
1014 (setq c-just-done-before-change t) 1035 (setq c-just-done-before-change t)
1015 (setq c-maybe-stale-found-type nil) 1036 (setq c-maybe-stale-found-type nil)
1016 (save-restriction 1037 (save-restriction
@@ -1105,51 +1126,53 @@ Note that the style variables are always made local to the buffer."
1105 ;; This calls the language variable c-before-font-lock-functions, if non nil. 1126 ;; This calls the language variable c-before-font-lock-functions, if non nil.
1106 ;; This typically sets `syntax-table' properties. 1127 ;; This typically sets `syntax-table' properties.
1107 1128
1108 (setq c-just-done-before-change nil) 1129 ;; (c-new-BEG c-new-END) will be the region to fontify. It may become
1109 (c-save-buffer-state (case-fold-search open-paren-in-column-0-is-defun-start) 1130 ;; larger than (beg end).
1110 ;; When `combine-after-change-calls' is used we might get calls 1131 (setq c-new-BEG beg c-new-END end)
1111 ;; with regions outside the current narrowing. This has been 1132
1112 ;; observed in Emacs 20.7. 1133 (unless (c-called-from-text-property-change-p)
1113 (save-restriction 1134 (setq c-just-done-before-change nil)
1114 (save-match-data ; c-recognize-<>-arglists changes match-data 1135 (c-save-buffer-state (case-fold-search open-paren-in-column-0-is-defun-start)
1115 (widen) 1136 ;; When `combine-after-change-calls' is used we might get calls
1116 1137 ;; with regions outside the current narrowing. This has been
1117 (when (> end (point-max)) 1138 ;; observed in Emacs 20.7.
1118 ;; Some emacsen might return positions past the end. This has been 1139 (save-restriction
1119 ;; observed in Emacs 20.7 when rereading a buffer changed on disk 1140 (save-match-data ; c-recognize-<>-arglists changes match-data
1120 ;; (haven't been able to minimize it, but Emacs 21.3 appears to 1141 (widen)
1121 ;; work). 1142
1122 (setq end (point-max)) 1143 (when (> end (point-max))
1123 (when (> beg end) 1144 ;; Some emacsen might return positions past the end. This has been
1124 (setq beg end))) 1145 ;; observed in Emacs 20.7 when rereading a buffer changed on disk
1125 1146 ;; (haven't been able to minimize it, but Emacs 21.3 appears to
1126 ;; C-y is capable of spuriously converting category properties 1147 ;; work).
1127 ;; c-</>-as-paren-syntax and c-cpp-delimiter into hard syntax-table 1148 (setq end (point-max))
1128 ;; properties. Remove these when it happens. 1149 (when (> beg end)
1129 (when (eval-when-compile (memq 'category-properties c-emacs-features)) 1150 (setq beg end)))
1130 (c-clear-char-property-with-value beg end 'syntax-table 1151
1131 c-<-as-paren-syntax) 1152 ;; C-y is capable of spuriously converting category properties
1132 (c-clear-char-property-with-value beg end 'syntax-table 1153 ;; c-</>-as-paren-syntax and c-cpp-delimiter into hard syntax-table
1133 c->-as-paren-syntax) 1154 ;; properties. Remove these when it happens.
1134 (c-clear-char-property-with-value beg end 'syntax-table nil)) 1155 (when (eval-when-compile (memq 'category-properties c-emacs-features))
1135 1156 (c-save-buffer-state ()
1136 (c-trim-found-types beg end old-len) ; maybe we don't need all of these. 1157 (c-clear-char-property-with-value beg end 'syntax-table
1137 (c-invalidate-sws-region-after beg end) 1158 c-<-as-paren-syntax)
1138 ;; (c-invalidate-state-cache beg) ; moved to `c-before-change'. 1159 (c-clear-char-property-with-value beg end 'syntax-table
1139 (c-invalidate-find-decl-cache beg) 1160 c->-as-paren-syntax)
1140 1161 (c-clear-char-property-with-value beg end 'syntax-table nil)))
1141 (when c-recognize-<>-arglists 1162
1142 (c-after-change-check-<>-operators beg end)) 1163 (c-trim-found-types beg end old-len) ; maybe we don't need all of these.
1143 1164 (c-invalidate-sws-region-after beg end)
1144 ;; (c-new-BEG c-new-END) will be the region to fontify. It may become 1165 ;; (c-invalidate-state-cache beg) ; moved to `c-before-change'.
1145 ;; larger than (beg end). 1166 (c-invalidate-find-decl-cache beg)
1146 (setq c-new-BEG beg 1167
1147 c-new-END end) 1168 (when c-recognize-<>-arglists
1148 (setq c-in-after-change-fontification t) 1169 (c-after-change-check-<>-operators beg end))
1149 (save-excursion 1170
1150 (mapc (lambda (fn) 1171 (setq c-in-after-change-fontification t)
1151 (funcall fn beg end old-len)) 1172 (save-excursion
1152 c-before-font-lock-functions)))))) 1173 (mapc (lambda (fn)
1174 (funcall fn beg end old-len))
1175 c-before-font-lock-functions)))))))
1153 1176
1154(defun c-fl-decl-start (pos) 1177(defun c-fl-decl-start (pos)
1155 ;; If the beginning of the line containing POS is in the middle of a "local" 1178 ;; If the beginning of the line containing POS is in the middle of a "local"
@@ -1322,7 +1345,7 @@ This function is called from `c-common-init', once per mode initialization."
1322 (add-hook 'font-lock-mode-hook 'c-after-font-lock-init nil t)) 1345 (add-hook 'font-lock-mode-hook 'c-after-font-lock-init nil t))
1323 1346
1324;; Emacs 22 and later. 1347;; Emacs 22 and later.
1325(defun c-extend-after-change-region (_beg _end _old-len) 1348(defun c-extend-after-change-region (beg end _old-len)
1326 "Extend the region to be fontified, if necessary." 1349 "Extend the region to be fontified, if necessary."
1327 ;; Note: the parameter OLD-LEN is ignored here. This somewhat indirect 1350 ;; Note: the parameter OLD-LEN is ignored here. This somewhat indirect
1328 ;; implementation exists because it is minimally different from the 1351 ;; implementation exists because it is minimally different from the
@@ -1336,10 +1359,11 @@ This function is called from `c-common-init', once per mode initialization."
1336 (when (eq font-lock-support-mode 'jit-lock-mode) 1359 (when (eq font-lock-support-mode 'jit-lock-mode)
1337 (save-restriction 1360 (save-restriction
1338 (widen) 1361 (widen)
1339 (if (< c-new-BEG beg) 1362 (c-save-buffer-state () ; Protect the undo-list from put-text-property.
1340 (put-text-property c-new-BEG beg 'fontified nil)) 1363 (if (< c-new-BEG beg)
1341 (if (> c-new-END end) 1364 (put-text-property c-new-BEG beg 'fontified nil))
1342 (put-text-property end c-new-END 'fontified nil)))) 1365 (if (> c-new-END end)
1366 (put-text-property end c-new-END 'fontified nil)))))
1343 (cons c-new-BEG c-new-END)) 1367 (cons c-new-BEG c-new-END))
1344 1368
1345;; Emacs < 22 and XEmacs 1369;; Emacs < 22 and XEmacs