+(defun c-before-after-change-digit-quote (beg end &optional old-len)
+ ;; This function either removes or applies the punctuation value ('(1)) of
+ ;; the `syntax-table' text property on single quote marks which are
+ ;; separator characters in long integer literals, e.g. "4'294'967'295". It
+ ;; applies to both decimal/octal and hex literals. (FIXME (2016-06-10): it
+ ;; should also apply to binary literals.)
+ ;;
+ ;; In both uses of the function, the `syntax-table' properties are
+ ;; removed/applied only on quote marks which appear to be digit separators.
+ ;;
+ ;; Point is undefined on both entry and exit to this function, and the
+ ;; return value has no significance. The function is called solely as a
+ ;; before-change function (see `c-get-state-before-change-functions') and as
+ ;; an after change function (see `c-before-font-lock-functions', with the
+ ;; parameters BEG, END, and (optionally) OLD-LEN being given the standard
+ ;; values for before/after-change functions.
+ (c-save-buffer-state ((num-begin c-new-BEG) digit-re try-end)
+ (goto-char c-new-END)
+ (when (looking-at "\\(x\\)?[0-9a-fA-F']+")
+ (setq c-new-END (match-end 0)))
+ (goto-char c-new-BEG)
+ (when (looking-at "\\(x?\\)[0-9a-fA-F']")
+ (if (re-search-backward "\\(0x\\)?[0-9a-fA-F]*\\=" nil t)
+ (setq c-new-BEG (point))))
+
+ (while
+ (re-search-forward "[0-9a-fA-F]'[0-9a-fA-F]" c-new-END t)
+ (setq try-end (1- (point)))
+ (re-search-backward "[^0-9a-fA-F']" num-begin t)
+ (setq digit-re
+ (cond
+ ((and (not (bobp)) (eq (char-before) ?0) (memq (char-after) '(?x ?X)))
+ "[0-9a-fA-F]")
+ ((and (eq (char-after (1+ (point))) ?0)
+ (memq (char-after (+ 2 (point))) '(?b ?B)))
+ "[01]")
+ ((memq (char-after (1+ (point))) '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
+ "[0-9]")
+ (t nil)))
+ (when digit-re
+ (cond ((eq (char-after) ?x) (forward-char))
+ ((looking-at ".?0[Bb]") (goto-char (match-end 0)))
+ ((looking-at digit-re))
+ (t (forward-char)))
+ (when (not (c-in-literal))
+ (let ((num-end ; End of valid sequence of digits/quotes.
+ (save-excursion
+ (re-search-forward
+ (concat "\\=\\(" digit-re "+'\\)*" digit-re "+") nil t)
+ (point))))
+ (setq try-end ; End of sequence of digits/quotes
+ (save-excursion
+ (re-search-forward
+ (concat "\\=\\(" digit-re "\\|'\\)+") nil t)
+ (point)))
+ (while (re-search-forward
+ (concat digit-re "\\('\\)" digit-re) num-end t)
+ (if old-len ; i.e. are we in an after-change function?
+ (c-put-char-property (match-beginning 1) 'syntax-table '(1))
+ (c-clear-char-property (match-beginning 1) 'syntax-table))
+ (backward-char)))))
+ (goto-char try-end)
+ (setq num-begin (point)))))
+