summaryrefslogtreecommitdiff
path: root/lisp/progmodes/cc-fonts.el
diff options
context:
space:
mode:
authorAlan Mackenzie <acm@muc.de>2017-07-01 15:43:07 +0000
committerAlan Mackenzie <acm@muc.de>2017-07-01 15:43:07 +0000
commit59d07875df9d44568d93a7517853e6a5ccaf1e5b (patch)
treeec96cf9039ad80fefc6756aee7fbddc05b44ae13 /lisp/progmodes/cc-fonts.el
parente620bbe38ed5e3e2a77f01eac2814c01dfa41c2d (diff)
downloademacs-59d07875df9d44568d93a7517853e6a5ccaf1e5b.tar.gz
Make C++ digit separators work. Amend the handling of single quotes generally
Single quotes, even in strings and comments, are now marked with the "punctuation" syntax-table property, except where they are validly bounding a character literal. They are font locked with font-lock-warning-face except where they are valid. This is done in C, C++, ObjC, and Java Modes. * lisp/progmodes/cc-defs.el (c-clear-char-property-with-value-on-char-function) (c-clear-char-property-with-value-on-char, c-put-char-properties-on-char): New functions/macros. * lisp/progmodes/cc-fonts.el (c-font-lock-invalid-single-quotes): New function. (c-basic-matchers-before): invoke c-font-lock-invalid-single-quotes. * lisp/progmodes/cc-langs.el (c-get-state-before-change-functions): Remove c-before-after-change-digit-quote from wherever it occurs. Insert c-parse-quotes-before-change into the entries for the languages where it is needed. (c-before-font-lock-functions): Remove c-before-after-change-digit-quote from wherever it occurs. Insert c-parse-quotes-after-change into the entries for the languages which need it. (c-has-quoted-numbers): New lang-defconst/-defvar. * lisp/progmodes/cc-mode.el (c-before-after-change-digit-quote): Remove. (c-maybe-quoted-number-head, c-maybe-quoted-number-tail) (c-maybe-quoted-number): New defconsts. (c-quoted-number-head-before-point, c-quoted-number-tail-after-point) (c-quoted-number-straddling-point, c-parse-quotes-before-change) (c-parse-quotes-after-change): New functions.
Diffstat (limited to 'lisp/progmodes/cc-fonts.el')
-rw-r--r--lisp/progmodes/cc-fonts.el33
1 files changed, 33 insertions, 0 deletions
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el
index 00812530357..66f2575f49f 100644
--- a/lisp/progmodes/cc-fonts.el
+++ b/lisp/progmodes/cc-fonts.el
@@ -702,6 +702,36 @@ stuff. Used on level 1 and higher."
t)
(c-put-font-lock-face start (1+ start) 'font-lock-warning-face)))))
+(defun c-font-lock-invalid-single-quotes (limit)
+ ;; This function will be called from font-lock for a region bounded by POINT
+ ;; and LIMIT, as though it were to identify a keyword for
+ ;; font-lock-keyword-face. It always returns NIL to inhibit this and
+ ;; prevent a repeat invocation. See elisp/lispref page "Search-based
+ ;; Fontification".
+ ;;
+ ;; This function fontifies invalid single quotes with
+ ;; `font-lock-warning-face'. These are the single quotes which
+ ;; o - aren't inside a literal;
+ ;; o - are marked with a syntax-table text property value '(1); and
+ ;; o - are NOT marked with a non-null c-digit-separator property.
+ (let ((limits (c-literal-limits))
+ state beg end)
+ (if limits
+ (goto-char (cdr limits))) ; Even for being in a ' '
+ (while (< (point) limit)
+ (setq beg (point))
+ (setq state (parse-partial-sexp (point) limit nil nil nil 'syntax-table))
+ (setq end (point))
+ (goto-char beg)
+ (while (progn (skip-chars-forward "^'" end)
+ (< (point) end))
+ (if (and (equal (c-get-char-property (point) 'syntax-table) '(1))
+ (not (c-get-char-property (point) 'c-digit-separator)))
+ (c-put-font-lock-face (point) (1+ (point)) font-lock-warning-face))
+ (forward-char))
+ (parse-partial-sexp end limit nil nil state 'syntax-table)))
+ nil)
+
(c-lang-defconst c-basic-matchers-before
"Font lock matchers for basic keywords, labels, references and various
other easily recognizable things that should be fontified before generic
@@ -723,6 +753,9 @@ casts and declarations are fontified. Used on level 2 and higher."
(concat ".\\(" c-string-limit-regexp "\\)")
'((c-font-lock-invalid-string)))
+ ;; Invalid single quotes.
+ c-font-lock-invalid-single-quotes
+
;; Fontify C++ raw strings.
,@(when (c-major-mode-is 'c++-mode)
'(c-font-lock-raw-strings))