aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2015-03-30 16:37:04 +0000
committerAlan Mackenzie2015-03-30 16:37:04 +0000
commit05a5a94000b82c81dc86cb7e2f3b4010bb2a4f0b (patch)
treedcb09fa7a5196aa42e50e0b940f9e3af0009bb21
parentd9eff02736c975dc5035e02249ff17c8a068d203 (diff)
downloademacs-05a5a94000b82c81dc86cb7e2f3b4010bb2a4f0b.tar.gz
emacs-05a5a94000b82c81dc86cb7e2f3b4010bb2a4f0b.zip
Correct calculation of CC Mode's font-lock region.
* cc-mode.el (c-fl-decl-start): Renamed from c-set-fl-decl-start. * Change signature such that nil is returned when no declaration is found. (c-change-expand-fl-region): Renamed from c-change-set-fl-decl-start. This now also handles expanding the font lock region to whole lines. (c-context-expand-fl-region): Renamed from c-context-set-fl-decl-start. This now also handles expanding the font lock region to whole lines. (c-font-lock-fontify-region): When a change font lock region is spuriously enlarged to the beginning-of-line by jit-lock, fontify the extra bit separately from the region calculated by CC Mode. (c-extend-after-change-region): Explicitly apply 'fontified properties to the extended bits of the font lock region. * cc-langs.el (c-before-font-lock-functions) (c-before-context-fontification-functions): Use new names for existing functions (see above).
-rw-r--r--lisp/ChangeLog23
-rw-r--r--lisp/progmodes/cc-langs.el4
-rw-r--r--lisp/progmodes/cc-mode.el114
3 files changed, 106 insertions, 35 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 69d9ab9f977..649e8849732 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,26 @@
12015-03-30 Alan Mackenzie <acm@muc.de>
2
3 Correct calculation of CC Mode's font-lock region.
4
5 * progmodes/cc-mode.el (c-fl-decl-start): Renamed from
6 c-set-fl-decl-start. Change signature such that nil is returned
7 when no declaration is found.
8 (c-change-expand-fl-region): Renamed from
9 c-change-set-fl-decl-start. This now also handles expanding the
10 font lock region to whole lines.
11 (c-context-expand-fl-region): Renamed from
12 c-context-set-fl-decl-start. This now also handles expanding the
13 font lock region to whole lines.
14 (c-font-lock-fontify-region): When a change font lock region is
15 spuriously enlarged to the beginning-of-line by jit-lock, fontify
16 the extra bit separately from the region calculated by CC Mode.
17 (c-extend-after-change-region): Explicitly apply 'fontified
18 properties to the extended bits of the font lock region.
19
20 * progmodes/cc-langs.el (c-before-font-lock-functions)
21 (c-before-context-fontification-functions): Use new names for
22 existing functions (see above).
23
12015-03-30 Richard Ryniker <ryniker@alum.mit.edu> (tiny change) 242015-03-30 Richard Ryniker <ryniker@alum.mit.edu> (tiny change)
2 25
3 * mail/sendmail.el (sendmail-send-it): Do not attempt to switch 26 * mail/sendmail.el (sendmail-send-it): Do not attempt to switch
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 4d16a9b9d33..c7b24e185c2 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -497,7 +497,7 @@ parameters \(point-min) and \(point-max).")
497 ;; The value here may be a list of functions or a single function. 497 ;; The value here may be a list of functions or a single function.
498 t 'c-change-set-fl-decl-start 498 t 'c-change-set-fl-decl-start
499 (c c++ objc) '(c-neutralize-syntax-in-and-mark-CPP 499 (c c++ objc) '(c-neutralize-syntax-in-and-mark-CPP
500 c-change-set-fl-decl-start) 500 c-change-expand-fl-region)
501 awk 'c-awk-extend-and-syntax-tablify-region) 501 awk 'c-awk-extend-and-syntax-tablify-region)
502(c-lang-defvar c-before-font-lock-functions 502(c-lang-defvar c-before-font-lock-functions
503 (let ((fs (c-lang-const c-before-font-lock-functions))) 503 (let ((fs (c-lang-const c-before-font-lock-functions)))
@@ -524,7 +524,7 @@ parameters \(point-min), \(point-max) and <buffer size>.")
524 524
525(c-lang-defconst c-before-context-fontification-functions 525(c-lang-defconst c-before-context-fontification-functions
526 awk nil 526 awk nil
527 t 'c-context-set-fl-decl-start) 527 t 'c-context-expand-fl-region)
528 ;; For documentation see the following c-lang-defvar of the same name. 528 ;; For documentation see the following c-lang-defvar of the same name.
529 ;; The value here may be a list of functions or a single function. 529 ;; The value here may be a list of functions or a single function.
530(c-lang-defvar c-before-context-fontification-functions 530(c-lang-defvar c-before-context-fontification-functions
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index f84f4ae2c20..c95e8a91555 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -1148,11 +1148,11 @@ Note that the style variables are always made local to the buffer."
1148 (funcall fn beg end old-len)) 1148 (funcall fn beg end old-len))
1149 c-before-font-lock-functions)))))) 1149 c-before-font-lock-functions))))))
1150 1150
1151(defun c-set-fl-decl-start (pos) 1151(defun c-fl-decl-start (pos)
1152 ;; If the beginning of the line containing POS is in the middle of a "local" 1152 ;; If the beginning of the line containing POS is in the middle of a "local"
1153 ;; declaration (i.e. one which does not start outside of braces enclosing 1153 ;; declaration (i.e. one which does not start outside of braces enclosing
1154 ;; POS, such as a struct), return the beginning of that declaration. 1154 ;; POS, such as a struct), return the beginning of that declaration.
1155 ;; Otherwise return POS. Note that declarations, in this sense, can be 1155 ;; Otherwise return nil. Note that declarations, in this sense, can be
1156 ;; nested. 1156 ;; nested.
1157 ;; 1157 ;;
1158 ;; This function is called indirectly from font locking stuff - either from 1158 ;; This function is called indirectly from font locking stuff - either from
@@ -1189,29 +1189,50 @@ Note that the style variables are always made local to the buffer."
1189 (1- (point)) 'syntax-table) 1189 (1- (point)) 'syntax-table)
1190 c-<-as-paren-syntax))))) 1190 c-<-as-paren-syntax)))))
1191 (not (bobp))) 1191 (not (bobp)))
1192 (backward-char)) 1192 (backward-char)) ; back over (, [, <.
1193 new-pos)) ; back over (, [, <. 1193 (and (/= new-pos pos) new-pos)))
1194 1194
1195(defun c-change-set-fl-decl-start (_beg _end _old-len) 1195(defun c-change-expand-fl-region (beg end old-len)
1196 ;; Set c-new-BEG to the beginning of a "local" declaration if it('s BOL) is 1196 ;; Expand the region (c-new-BEG c-new-END) to an after-change font-lock
1197 ;; inside one. This is called from an after-change-function, but the 1197 ;; region. This will usually be the smallest sequence of whole lines
1198 ;; parameters BEG END and OLD-LEN are ignored. See `c-set-fl-decl-start' 1198 ;; containing `c-new-BEG' and `c-new-END', but if `c-new-BEG' is in a
1199 ;; for the detailed functionality. 1199 ;; "local" declaration (see `c-fl-decl-start') the beginning of this is used
1200 (if font-lock-mode 1200 ;; as the lower bound.
1201 (setq c-new-BEG (c-set-fl-decl-start c-new-BEG)))) 1201 ;;
1202 1202 ;; This is called from an after-change-function, but the parameters BEG END
1203(defun c-context-set-fl-decl-start (beg end) 1203 ;; and OLD-LEN are not used.
1204 ;; Return a cons (NEW-BEG . END), where NEW-BEG is the beginning of a 1204 (if font-lock-mode
1205 ;; "local" declaration (BOL at) NEW is inside or BEG. See 1205 (setq c-new-BEG
1206 ;; `c-set-fl-decl-start' for the detailed functionality. 1206 (or (c-fl-decl-start c-new-BEG) (c-point 'bol c-new-BEG))
1207 (cons (c-set-fl-decl-start beg) end)) 1207 c-new-END (c-point 'bonl c-new-END))))
1208
1209(defun c-context-expand-fl-region (beg end)
1210 ;; Return a cons (NEW-BEG . NEW-END), where NEW-BEG is the beginning of a
1211 ;; "local" declaration containing BEG (see `c-fl-decl-start') or BOL BEG is
1212 ;; in. NEW-END is beginning of the line after the one END is in.
1213 (cons (or (c-fl-decl-start beg) (c-point 'bol beg))
1214 (c-point 'bonl end)))
1215
1216(defun c-before-context-fl-expand-region (beg end)
1217 ;; Expand the region (BEG END) as specified by
1218 ;; `c-before-context-fontification-functions'. Return a cons of the bounds
1219 ;; of the new region.
1220 (save-restriction
1221 (widen)
1222 (save-excursion
1223 (let ((new-beg beg) (new-end end) new-region)
1224 (mapc (lambda (fn)
1225 (setq new-region (funcall fn new-beg new-end))
1226 (setq new-beg (car new-region) new-end (cdr new-region)))
1227 c-before-context-fontification-functions)
1228 new-region))))
1208 1229
1209(defun c-font-lock-fontify-region (beg end &optional verbose) 1230(defun c-font-lock-fontify-region (beg end &optional verbose)
1210 ;; Effectively advice around `font-lock-fontify-region' which extends the 1231 ;; Effectively advice around `font-lock-fontify-region' which extends the
1211 ;; region (BEG END), for example, to avoid context fontification chopping 1232 ;; region (BEG END), for example, to avoid context fontification chopping
1212 ;; off the start of the context. Do not do anything if it's already been 1233 ;; off the start of the context. Do not extend the region if it's already
1213 ;; done (i.e. from an after-change fontification. An example (C++) where 1234 ;; been done (i.e. from an after-change fontification. An example (C++)
1214 ;; this used to happen is this: 1235 ;; where the chopping off used to happen is this:
1215 ;; 1236 ;;
1216 ;; template <typename T> 1237 ;; template <typename T>
1217 ;; 1238 ;;
@@ -1220,17 +1241,39 @@ Note that the style variables are always made local to the buffer."
1220 ;; 1241 ;;
1221 ;; Type a space in the first blank line, and the fontification of the next 1242 ;; Type a space in the first blank line, and the fontification of the next
1222 ;; line was fouled up by context fontification. 1243 ;; line was fouled up by context fontification.
1223 (let ((new-beg beg) (new-end end) new-region case-fold-search 1244 (let (new-beg new-end new-region case-fold-search
1224 open-paren-in-column-0-is-defun-start) 1245 open-paren-in-column-0-is-defun-start)
1225 (if c-in-after-change-fontification 1246 (if (and c-in-after-change-fontification
1226 (setq c-in-after-change-fontification nil) 1247 (< beg c-new-END) (> end c-new-BEG))
1227 (save-restriction 1248 ;; Region and the latest after-change fontification region overlap.
1228 (widen) 1249 ;; Determine the upper and lower bounds of our adjusted region
1229 (save-excursion 1250 ;; separately.
1230 (mapc (lambda (fn) 1251 (progn
1231 (setq new-region (funcall fn new-beg new-end)) 1252 (if (<= beg c-new-BEG)
1232 (setq new-beg (car new-region) new-end (cdr new-region))) 1253 (setq c-in-after-change-fontification nil))
1233 c-before-context-fontification-functions)))) 1254 (setq new-beg
1255 (if (and (>= beg (c-point 'bol c-new-BEG))
1256 (<= beg c-new-BEG))
1257 ;; Either jit-lock has accepted `c-new-BEG', or has
1258 ;; (probably) extended the change region spuriously to
1259 ;; BOL, which position likely has a syntactically
1260 ;; different position. To ensure correct fontification,
1261 ;; we start at `c-new-BEG', assuming any characters to the
1262 ;; left of `c-new-BEG' on the line do not require
1263 ;; fontification.
1264 c-new-BEG
1265 (setq new-region (c-before-context-fl-expand-region beg end)
1266 new-end (cdr new-region))
1267 (car new-region)))
1268 (setq new-end
1269 (if (and (>= end (c-point 'bol c-new-END))
1270 (<= end c-new-END))
1271 c-new-END
1272 (or new-end
1273 (cdr (c-before-context-fl-expand-region beg end))))))
1274 ;; Context (etc.) fontification.
1275 (setq new-region (c-before-context-fl-expand-region beg end)
1276 new-beg (car new-region) new-end (cdr new-region)))
1234 (funcall (default-value 'font-lock-fontify-region-function) 1277 (funcall (default-value 'font-lock-fontify-region-function)
1235 new-beg new-end verbose))) 1278 new-beg new-end verbose)))
1236 1279
@@ -1277,7 +1320,7 @@ This function is called from `c-common-init', once per mode initialization."
1277;; Emacs 22 and later. 1320;; Emacs 22 and later.
1278(defun c-extend-after-change-region (_beg _end _old-len) 1321(defun c-extend-after-change-region (_beg _end _old-len)
1279 "Extend the region to be fontified, if necessary." 1322 "Extend the region to be fontified, if necessary."
1280 ;; Note: the parameters are ignored here. This somewhat indirect 1323 ;; Note: the parameter OLD-LEN is ignored here. This somewhat indirect
1281 ;; implementation exists because it is minimally different from the 1324 ;; implementation exists because it is minimally different from the
1282 ;; stand-alone CC Mode which, lacking 1325 ;; stand-alone CC Mode which, lacking
1283 ;; font-lock-extend-after-change-region-function, is forced to use advice 1326 ;; font-lock-extend-after-change-region-function, is forced to use advice
@@ -1286,6 +1329,11 @@ This function is called from `c-common-init', once per mode initialization."
1286 ;; Of the seven CC Mode languages, currently (2009-05) only C, C++, Objc 1329 ;; Of the seven CC Mode languages, currently (2009-05) only C, C++, Objc
1287 ;; (the languages with #define) and AWK Mode make non-null use of this 1330 ;; (the languages with #define) and AWK Mode make non-null use of this
1288 ;; function. 1331 ;; function.
1332 (when (eq font-lock-support-mode 'jit-lock-mode)
1333 (if (< c-new-BEG beg)
1334 (put-text-property c-new-BEG beg 'fontified nil))
1335 (if (> c-new-END end)
1336 (put-text-property end c-new-END 'fontified nil)))
1289 (cons c-new-BEG c-new-END)) 1337 (cons c-new-BEG c-new-END))
1290 1338
1291;; Emacs < 22 and XEmacs 1339;; Emacs < 22 and XEmacs