aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2016-06-24 13:26:34 +0000
committerAlan Mackenzie2016-06-24 13:26:34 +0000
commita4750b39560a8a182cf95dd4494f79ab6466e9b2 (patch)
tree825964dd6b6e6eec5ad34517ae694acb28d37e55
parent63457dcfe0fe101d3db131c4b05823e8280b6bff (diff)
downloademacs-a4750b39560a8a182cf95dd4494f79ab6466e9b2.tar.gz
emacs-a4750b39560a8a182cf95dd4494f79ab6466e9b2.zip
Implement ' separators in C++ integer literals.
* lisp/progmodes/cc-langs.el (c-get-state-before-change-functions): insert c-before-after-change-digit-quote into the C++ value. (c-before-font-lock-functions): Insert c-depropertize-new-text into the values for all languages. Insert c-before-after-change-digit-quote into the C++ value. * lisp/progmodes/cc-mode.el (c-depropertize-CPP): Wrap the function in c-save-buffer-state. (c-depropertize-new-text, c-before-after-change-digit-quote): New functions.
-rw-r--r--lisp/progmodes/cc-langs.el17
-rw-r--r--lisp/progmodes/cc-mode.el118
2 files changed, 113 insertions, 22 deletions
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index ba05e81aba3..4d366848998 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -477,6 +477,7 @@ so that all identifiers are recognized as words.")
477 c-before-change-check-raw-strings 477 c-before-change-check-raw-strings
478 c-before-change-check-<>-operators 478 c-before-change-check-<>-operators
479 c-depropertize-CPP 479 c-depropertize-CPP
480 c-before-after-change-digit-quote
480 c-invalidate-macro-cache) 481 c-invalidate-macro-cache)
481 (c objc) '(c-extend-region-for-CPP 482 (c objc) '(c-extend-region-for-CPP
482 c-depropertize-CPP 483 c-depropertize-CPP
@@ -508,18 +509,24 @@ parameters \(point-min) and \(point-max).")
508(c-lang-defconst c-before-font-lock-functions 509(c-lang-defconst c-before-font-lock-functions
509 ;; For documentation see the following c-lang-defvar of the same name. 510 ;; For documentation see the following c-lang-defvar of the same name.
510 ;; The value here may be a list of functions or a single function. 511 ;; The value here may be a list of functions or a single function.
511 t 'c-change-expand-fl-region 512 t '(c-depropertize-new-text
512 (c objc) '(c-extend-font-lock-region-for-macros 513 c-change-expand-fl-region)
514 (c objc) '(c-depropertize-new-text
515 c-extend-font-lock-region-for-macros
513 c-neutralize-syntax-in-and-mark-CPP 516 c-neutralize-syntax-in-and-mark-CPP
514 c-change-expand-fl-region) 517 c-change-expand-fl-region)
515 c++ '(c-extend-font-lock-region-for-macros 518 c++ '(c-depropertize-new-text
519 c-extend-font-lock-region-for-macros
520 c-before-after-change-digit-quote
516 c-after-change-re-mark-raw-strings 521 c-after-change-re-mark-raw-strings
517 c-neutralize-syntax-in-and-mark-CPP 522 c-neutralize-syntax-in-and-mark-CPP
518 c-restore-<>-properties 523 c-restore-<>-properties
519 c-change-expand-fl-region) 524 c-change-expand-fl-region)
520 java '(c-restore-<>-properties 525 java '(c-depropertize-new-text
526 c-restore-<>-properties
521 c-change-expand-fl-region) 527 c-change-expand-fl-region)
522 awk 'c-awk-extend-and-syntax-tablify-region) 528 awk '(c-depropertize-new-text
529 c-awk-extend-and-syntax-tablify-region))
523(c-lang-defvar c-before-font-lock-functions 530(c-lang-defvar c-before-font-lock-functions
524 (let ((fs (c-lang-const c-before-font-lock-functions))) 531 (let ((fs (c-lang-const c-before-font-lock-functions)))
525 (if (listp fs) 532 (if (listp fs)
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index dd8d771a66f..80ac08fb9e0 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -892,23 +892,24 @@ Note that the style variables are always made local to the buffer."
892 ;; This function is in the C/C++/ObjC values of 892 ;; This function is in the C/C++/ObjC values of
893 ;; `c-get-state-before-change-functions' and is called exclusively as a 893 ;; `c-get-state-before-change-functions' and is called exclusively as a
894 ;; before change function. 894 ;; before change function.
895 (goto-char c-new-BEG) 895 (c-save-buffer-state ()
896 (while (and (< (point) beg) 896 (goto-char c-new-BEG)
897 (search-forward-regexp c-anchored-cpp-prefix beg t)) 897 (while (and (< (point) beg)
898 (goto-char (match-beginning 1)) 898 (search-forward-regexp c-anchored-cpp-prefix beg t))
899 (let ((m-beg (point))) 899 (goto-char (match-beginning 1))
900 (c-end-of-macro) 900 (let ((m-beg (point)))
901 (c-clear-char-property-with-value 901 (c-end-of-macro)
902 m-beg (min (point) beg) 'syntax-table '(1)))) 902 (c-clear-char-property-with-value
903 903 m-beg (min (point) beg) 'syntax-table '(1))))
904 (goto-char end) 904
905 (while (and (< (point) c-new-END) 905 (goto-char end)
906 (search-forward-regexp c-anchored-cpp-prefix c-new-END t)) 906 (while (and (< (point) c-new-END)
907 (goto-char (match-beginning 1)) 907 (search-forward-regexp c-anchored-cpp-prefix c-new-END t))
908 (let ((m-beg (point))) 908 (goto-char (match-beginning 1))
909 (c-end-of-macro) 909 (let ((m-beg (point)))
910 (c-clear-char-property-with-value 910 (c-end-of-macro)
911 m-beg (min (point) c-new-END) 'syntax-table '(1))))) 911 (c-clear-char-property-with-value
912 m-beg (min (point) c-new-END) 'syntax-table '(1))))))
912 913
913(defun c-extend-region-for-CPP (beg end) 914(defun c-extend-region-for-CPP (beg end)
914 ;; Adjust `c-new-BEG', `c-new-END' respectively to the beginning and end of 915 ;; Adjust `c-new-BEG', `c-new-END' respectively to the beginning and end of
@@ -932,6 +933,25 @@ Note that the style variables are always made local to the buffer."
932 ; with a c-cpp-delimiter category property 933 ; with a c-cpp-delimiter category property
933 (setq c-new-END (point))) 934 (setq c-new-END (point)))
934 935
936(defun c-depropertize-new-text (beg end old-len)
937 ;; Remove from the new text in (BEG END) any and all text properties which
938 ;; might interfere with CC Mode's proper working.
939 ;;
940 ;; This function is called exclusively as an after-change function. It
941 ;; appears in the value (for all languages) of
942 ;; `c-before-font-lock-functions'. The value of point is undefined both on
943 ;; entry and exit, and the return value has no significance. The parameters
944 ;; BEG, END, and OLD-LEN are the standard ones supplied to all after-change
945 ;; functions.
946 (c-save-buffer-state ()
947 (when (> end beg)
948 (c-clear-char-properties beg end 'syntax-table)
949 (c-clear-char-properties beg end 'category)
950 (c-clear-char-properties beg end 'c-is-sws)
951 (c-clear-char-properties beg end 'c-in-sws)
952 (c-clear-char-properties beg end 'c-type)
953 (c-clear-char-properties beg end 'c-awk-NL-prop))))
954
935(defun c-extend-font-lock-region-for-macros (begg endd old-len) 955(defun c-extend-font-lock-region-for-macros (begg endd old-len)
936 ;; Extend the region (c-new-BEG c-new-END) to cover all (possibly changed) 956 ;; Extend the region (c-new-BEG c-new-END) to cover all (possibly changed)
937 ;; preprocessor macros; The return value has no significance. 957 ;; preprocessor macros; The return value has no significance.
@@ -1042,6 +1062,70 @@ Note that the style variables are always made local to the buffer."
1042 (forward-line)) ; no infinite loop with, e.g., "#//" 1062 (forward-line)) ; no infinite loop with, e.g., "#//"
1043 ))))) 1063 )))))
1044 1064
1065(defun c-before-after-change-digit-quote (beg end &optional old-len)
1066 ;; This function either removes or applies the punctuation value ('(1)) of
1067 ;; the `syntax-table' text property on single quote marks which are
1068 ;; separator characters in long integer literals, e.g. "4'294'967'295". It
1069 ;; applies to both decimal/octal and hex literals. (FIXME (2016-06-10): it
1070 ;; should also apply to binary literals.)
1071 ;;
1072 ;; In both uses of the function, the `syntax-table' properties are
1073 ;; removed/applied only on quote marks which appear to be digit separators.
1074 ;;
1075 ;; Point is undefined on both entry and exit to this function, and the
1076 ;; return value has no significance. The function is called solely as a
1077 ;; before-change function (see `c-get-state-before-change-functions') and as
1078 ;; an after change function (see `c-before-font-lock-functions', with the
1079 ;; parameters BEG, END, and (optionally) OLD-LEN being given the standard
1080 ;; values for before/after-change functions.
1081 (c-save-buffer-state ((num-begin c-new-BEG) digit-re try-end)
1082 (goto-char c-new-END)
1083 (when (looking-at "\\(x\\)?[0-9a-fA-F']+")
1084 (setq c-new-END (match-end 0)))
1085 (goto-char c-new-BEG)
1086 (when (looking-at "\\(x?\\)[0-9a-fA-F']")
1087 (if (re-search-backward "\\(0x\\)?[0-9a-fA-F]*\\=" nil t)
1088 (setq c-new-BEG (point))))
1089
1090 (while
1091 (re-search-forward "[0-9a-fA-F]'[0-9a-fA-F]" c-new-END t)
1092 (setq try-end (1- (point)))
1093 (re-search-backward "[^0-9a-fA-F']" num-begin t)
1094 (setq digit-re
1095 (cond
1096 ((and (not (bobp)) (eq (char-before) ?0) (memq (char-after) '(?x ?X)))
1097 "[0-9a-fA-F]")
1098 ((and (eq (char-after (1+ (point))) ?0)
1099 (memq (char-after (+ 2 (point))) '(?b ?B)))
1100 "[01]")
1101 ((memq (char-after (1+ (point))) '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
1102 "[0-9]")
1103 (t nil)))
1104 (when digit-re
1105 (cond ((eq (char-after) ?x) (forward-char))
1106 ((looking-at ".?0[Bb]") (goto-char (match-end 0)))
1107 ((looking-at digit-re))
1108 (t (forward-char)))
1109 (when (not (c-in-literal))
1110 (let ((num-end ; End of valid sequence of digits/quotes.
1111 (save-excursion
1112 (re-search-forward
1113 (concat "\\=\\(" digit-re "+'\\)*" digit-re "+") nil t)
1114 (point))))
1115 (setq try-end ; End of sequence of digits/quotes
1116 (save-excursion
1117 (re-search-forward
1118 (concat "\\=\\(" digit-re "\\|'\\)+") nil t)
1119 (point)))
1120 (while (re-search-forward
1121 (concat digit-re "\\('\\)" digit-re) num-end t)
1122 (if old-len ; i.e. are we in an after-change function?
1123 (c-put-char-property (match-beginning 1) 'syntax-table '(1))
1124 (c-clear-char-property (match-beginning 1) 'syntax-table))
1125 (backward-char)))))
1126 (goto-char try-end)
1127 (setq num-begin (point)))))
1128
1045(defun c-before-change (beg end) 1129(defun c-before-change (beg end)
1046 ;; Function to be put on `before-change-functions'. Primarily, this calls 1130 ;; Function to be put on `before-change-functions'. Primarily, this calls
1047 ;; the language dependent `c-get-state-before-change-functions'. It is 1131 ;; the language dependent `c-get-state-before-change-functions'. It is