aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/cc-cmds.el2
-rw-r--r--lisp/progmodes/cc-defs.el91
-rw-r--r--lisp/progmodes/cc-engine.el4
-rw-r--r--lisp/progmodes/cc-fonts.el47
-rw-r--r--lisp/progmodes/cc-langs.el24
-rw-r--r--lisp/progmodes/cc-mode.el298
-rw-r--r--lisp/progmodes/cc-styles.el1
-rw-r--r--lisp/progmodes/tcl.el5
8 files changed, 342 insertions, 130 deletions
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index c05200b3898..de2543951b9 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -1915,7 +1915,7 @@ with a brace block."
1915 (save-restriction 1915 (save-restriction
1916 (let ((start (point)) 1916 (let ((start (point))
1917 (paren-state (c-parse-state)) 1917 (paren-state (c-parse-state))
1918 lim pos end-pos encl-decl-block where) 1918 lim pos end-pos where)
1919 ;; Narrow enclosing brace blocks out, as required by the values of 1919 ;; Narrow enclosing brace blocks out, as required by the values of
1920 ;; `c-defun-tactic', `near', and the position of point. 1920 ;; `c-defun-tactic', `near', and the position of point.
1921 (when (eq c-defun-tactic 'go-outward) 1921 (when (eq c-defun-tactic 'go-outward)
diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el
index dd8f8afc6a3..85a4085e490 100644
--- a/lisp/progmodes/cc-defs.el
+++ b/lisp/progmodes/cc-defs.el
@@ -44,19 +44,12 @@
44 (load "cc-bytecomp" nil t))) 44 (load "cc-bytecomp" nil t)))
45 45
46(eval-and-compile 46(eval-and-compile
47 (defvar c--mapcan-status 47 (defvar c--cl-library
48 (cond ((and (fboundp 'mapcan) 48 (if (locate-library "cl-lib")
49 (subrp (symbol-function 'mapcan))) 49 'cl-lib
50 ;; XEmacs 50 'cl)))
51 'mapcan) 51
52 ((locate-file "cl-lib.elc" load-path) 52(cc-external-require c--cl-library)
53 ;; Emacs >= 24.3
54 'cl-mapcan)
55 (t
56 ;; Emacs <= 24.2
57 nil))))
58
59(cc-external-require (if (eq c--mapcan-status 'cl-mapcan) 'cl-lib 'cl))
60; was (cc-external-require 'cl). ACM 2005/11/29. 53; was (cc-external-require 'cl). ACM 2005/11/29.
61; Changed from (eval-when-compile (require 'cl)) back to 54; Changed from (eval-when-compile (require 'cl)) back to
62; cc-external-require, 2015-08-12. 55; cc-external-require, 2015-08-12.
@@ -182,9 +175,12 @@ This variant works around bugs in `eval-when-compile' in various
182 ;; The motivation for this macro is to avoid the irritating message 175 ;; The motivation for this macro is to avoid the irritating message
183 ;; "function `mapcan' from cl package called at runtime" produced by Emacs. 176 ;; "function `mapcan' from cl package called at runtime" produced by Emacs.
184 (cond 177 (cond
185 ((eq c--mapcan-status 'mapcan) 178 ((and (fboundp 'mapcan)
179 (subrp (symbol-function 'mapcan)))
180 ;; XEmacs and Emacs >= 26.
186 `(mapcan ,fun ,liszt)) 181 `(mapcan ,fun ,liszt))
187 ((eq c--mapcan-status 'cl-mapcan) 182 ((eq c--cl-library 'cl-lib)
183 ;; Emacs >= 24.3, < 26.
188 `(cl-mapcan ,fun ,liszt)) 184 `(cl-mapcan ,fun ,liszt))
189 (t 185 (t
190 ;; Emacs <= 24.2. It would be nice to be able to distinguish between 186 ;; Emacs <= 24.2. It would be nice to be able to distinguish between
@@ -193,13 +189,13 @@ This variant works around bugs in `eval-when-compile' in various
193 189
194(defmacro c--set-difference (liszt1 liszt2 &rest other-args) 190(defmacro c--set-difference (liszt1 liszt2 &rest other-args)
195 ;; Macro to smooth out the renaming of `set-difference' in Emacs 24.3. 191 ;; Macro to smooth out the renaming of `set-difference' in Emacs 24.3.
196 (if (eq c--mapcan-status 'cl-mapcan) 192 (if (eq c--cl-library 'cl-lib)
197 `(cl-set-difference ,liszt1 ,liszt2 ,@other-args) 193 `(cl-set-difference ,liszt1 ,liszt2 ,@other-args)
198 `(set-difference ,liszt1 ,liszt2 ,@other-args))) 194 `(set-difference ,liszt1 ,liszt2 ,@other-args)))
199 195
200(defmacro c--intersection (liszt1 liszt2 &rest other-args) 196(defmacro c--intersection (liszt1 liszt2 &rest other-args)
201 ;; Macro to smooth out the renaming of `intersection' in Emacs 24.3. 197 ;; Macro to smooth out the renaming of `intersection' in Emacs 24.3.
202 (if (eq c--mapcan-status 'cl-mapcan) 198 (if (eq c--cl-library 'cl-lib)
203 `(cl-intersection ,liszt1 ,liszt2 ,@other-args) 199 `(cl-intersection ,liszt1 ,liszt2 ,@other-args)
204 `(intersection ,liszt1 ,liszt2 ,@other-args))) 200 `(intersection ,liszt1 ,liszt2 ,@other-args)))
205 201
@@ -212,7 +208,7 @@ This variant works around bugs in `eval-when-compile' in various
212 208
213 (defmacro c--delete-duplicates (cl-seq &rest cl-keys) 209 (defmacro c--delete-duplicates (cl-seq &rest cl-keys)
214 ;; Macro to smooth out the renaming of `delete-duplicates' in Emacs 24.3. 210 ;; Macro to smooth out the renaming of `delete-duplicates' in Emacs 24.3.
215 (if (eq c--mapcan-status 'cl-mapcan) 211 (if (eq c--cl-library 'cl-lib)
216 `(cl-delete-duplicates ,cl-seq ,@cl-keys) 212 `(cl-delete-duplicates ,cl-seq ,@cl-keys)
217 `(delete-duplicates ,cl-seq ,@cl-keys)))) 213 `(delete-duplicates ,cl-seq ,@cl-keys))))
218 214
@@ -1175,6 +1171,63 @@ been put there by c-put-char-property. POINT remains unchanged."
1175 nil ,from ,to ,value nil -property-)) 1171 nil ,from ,to ,value nil -property-))
1176 ;; GNU Emacs 1172 ;; GNU Emacs
1177 `(c-clear-char-property-with-value-function ,from ,to ,property ,value))) 1173 `(c-clear-char-property-with-value-function ,from ,to ,property ,value)))
1174
1175(defun c-clear-char-property-with-value-on-char-function (from to property
1176 value char)
1177 "Remove all text-properties PROPERTY with value VALUE on
1178characters with value CHAR from the region [FROM, TO), as tested
1179by `equal'. These properties are assumed to be over individual
1180characters, having been put there by c-put-char-property. POINT
1181remains unchanged."
1182 (let ((place from)
1183 )
1184 (while ; loop round occurrences of (PROPERTY VALUE)
1185 (progn
1186 (while ; loop round changes in PROPERTY till we find VALUE
1187 (and
1188 (< place to)
1189 (not (equal (get-text-property place property) value)))
1190 (setq place (c-next-single-property-change place property nil to)))
1191 (< place to))
1192 (if (eq (char-after place) char)
1193 (remove-text-properties place (1+ place) (cons property nil)))
1194 ;; Do we have to do anything with stickiness here?
1195 (setq place (1+ place)))))
1196
1197(defmacro c-clear-char-property-with-value-on-char (from to property value char)
1198 "Remove all text-properties PROPERTY with value VALUE on
1199characters with value CHAR from the region [FROM, TO), as tested
1200by `equal'. These properties are assumed to be over individual
1201characters, having been put there by c-put-char-property. POINT
1202remains unchanged."
1203 (if c-use-extents
1204 ;; XEmacs
1205 `(let ((-property- ,property)
1206 (-char- ,char))
1207 (map-extents (lambda (ext val)
1208 (if (and (equal (extent-property ext -property-) val)
1209 (eq (char-after
1210 (extent-start-position ext))
1211 -char-))
1212 (delete-extent ext)))
1213 nil ,from ,to ,value nil -property-))
1214 ;; Gnu Emacs
1215 `(c-clear-char-property-with-value-on-char-function ,from ,to ,property
1216 ,value ,char)))
1217
1218(defmacro c-put-char-properties-on-char (from to property value char)
1219 ;; This needs to be a macro because `property' passed to
1220 ;; `c-put-char-property' must be a constant.
1221 "Put the text property PROPERTY with value VALUE on characters
1222with value CHAR in the region [FROM to)."
1223 `(let ((skip-string (concat "^" (list ,char)))
1224 (-to- ,to))
1225 (save-excursion
1226 (goto-char ,from)
1227 (while (progn (skip-chars-forward skip-string -to-)
1228 (< (point) -to-))
1229 (c-put-char-property (point) ,property ,value)
1230 (forward-char)))))
1178 1231
1179;; Macros to put overlays (Emacs) or extents (XEmacs) on buffer text. 1232;; Macros to put overlays (Emacs) or extents (XEmacs) on buffer text.
1180;; For our purposes, these are characterized by being possible to 1233;; For our purposes, these are characterized by being possible to
@@ -1232,6 +1285,8 @@ been put there by c-put-char-property. POINT remains unchanged."
1232(def-edebug-spec c-put-char-property t) 1285(def-edebug-spec c-put-char-property t)
1233(def-edebug-spec c-get-char-property t) 1286(def-edebug-spec c-get-char-property t)
1234(def-edebug-spec c-clear-char-property t) 1287(def-edebug-spec c-clear-char-property t)
1288(def-edebug-spec c-clear-char-property-with-value-on-char t)
1289(def-edebug-spec c-put-char-properties-on-char t)
1235(def-edebug-spec c-clear-char-properties t) 1290(def-edebug-spec c-clear-char-properties t)
1236(def-edebug-spec c-put-overlay t) 1291(def-edebug-spec c-put-overlay t)
1237(def-edebug-spec c-delete-overlay t) 1292(def-edebug-spec c-delete-overlay t)
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index aa84ade083c..955e1ebb08d 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -4809,7 +4809,6 @@ comment at the start of cc-engine.el for more info."
4809 4809
4810 (c-self-bind-state-cache 4810 (c-self-bind-state-cache
4811 (let ((start (point)) 4811 (let ((start (point))
4812 state-2
4813 ;; A list of syntactically relevant positions in descending 4812 ;; A list of syntactically relevant positions in descending
4814 ;; order. It's used to avoid scanning repeatedly over 4813 ;; order. It's used to avoid scanning repeatedly over
4815 ;; potentially large regions with `parse-partial-sexp' to verify 4814 ;; potentially large regions with `parse-partial-sexp' to verify
@@ -7809,8 +7808,7 @@ comment at the start of cc-engine.el for more info."
7809 ;; looking (in C++) like this "FQN::of::base::Class". Move to the start of 7808 ;; looking (in C++) like this "FQN::of::base::Class". Move to the start of
7810 ;; this construct and return t. If the parsing fails, return nil, leaving 7809 ;; this construct and return t. If the parsing fails, return nil, leaving
7811 ;; point unchanged. 7810 ;; point unchanged.
7812 (let ((here (point)) 7811 (let (end)
7813 end)
7814 (if (not (c-on-identifier)) 7812 (if (not (c-on-identifier))
7815 nil 7813 nil
7816 (c-simple-skip-symbol-backward) 7814 (c-simple-skip-symbol-backward)
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el
index 9bae7d9aa2f..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."
702 t) 702 t)
703 (c-put-font-lock-face start (1+ start) 'font-lock-warning-face))))) 703 (c-put-font-lock-face start (1+ start) 'font-lock-warning-face)))))
704 704
705(defun c-font-lock-invalid-single-quotes (limit)
706 ;; This function will be called from font-lock for a region bounded by POINT
707 ;; and LIMIT, as though it were to identify a keyword for
708 ;; font-lock-keyword-face. It always returns NIL to inhibit this and
709 ;; prevent a repeat invocation. See elisp/lispref page "Search-based
710 ;; Fontification".
711 ;;
712 ;; This function fontifies invalid single quotes with
713 ;; `font-lock-warning-face'. These are the single quotes which
714 ;; o - aren't inside a literal;
715 ;; o - are marked with a syntax-table text property value '(1); and
716 ;; o - are NOT marked with a non-null c-digit-separator property.
717 (let ((limits (c-literal-limits))
718 state beg end)
719 (if limits
720 (goto-char (cdr limits))) ; Even for being in a ' '
721 (while (< (point) limit)
722 (setq beg (point))
723 (setq state (parse-partial-sexp (point) limit nil nil nil 'syntax-table))
724 (setq end (point))
725 (goto-char beg)
726 (while (progn (skip-chars-forward "^'" end)
727 (< (point) end))
728 (if (and (equal (c-get-char-property (point) 'syntax-table) '(1))
729 (not (c-get-char-property (point) 'c-digit-separator)))
730 (c-put-font-lock-face (point) (1+ (point)) font-lock-warning-face))
731 (forward-char))
732 (parse-partial-sexp end limit nil nil state 'syntax-table)))
733 nil)
734
705(c-lang-defconst c-basic-matchers-before 735(c-lang-defconst c-basic-matchers-before
706 "Font lock matchers for basic keywords, labels, references and various 736 "Font lock matchers for basic keywords, labels, references and various
707other easily recognizable things that should be fontified before generic 737other easily recognizable things that should be fontified before generic
@@ -723,6 +753,9 @@ casts and declarations are fontified. Used on level 2 and higher."
723 (concat ".\\(" c-string-limit-regexp "\\)") 753 (concat ".\\(" c-string-limit-regexp "\\)")
724 '((c-font-lock-invalid-string))) 754 '((c-font-lock-invalid-string)))
725 755
756 ;; Invalid single quotes.
757 c-font-lock-invalid-single-quotes
758
726 ;; Fontify C++ raw strings. 759 ;; Fontify C++ raw strings.
727 ,@(when (c-major-mode-is 'c++-mode) 760 ,@(when (c-major-mode-is 'c++-mode)
728 '(c-font-lock-raw-strings)) 761 '(c-font-lock-raw-strings))
@@ -777,7 +810,8 @@ casts and declarations are fontified. Used on level 2 and higher."
777 (c-backward-syntactic-ws) 810 (c-backward-syntactic-ws)
778 (setq id-end (point)) 811 (setq id-end (point))
779 (< (skip-chars-backward 812 (< (skip-chars-backward
780 ,(c-lang-const c-symbol-chars)) 0)) 813 ,(c-lang-const c-symbol-chars))
814 0))
781 (not (get-text-property (point) 'face))) 815 (not (get-text-property (point) 'face)))
782 (c-put-font-lock-face (point) id-end 816 (c-put-font-lock-face (point) id-end
783 c-reference-face-name) 817 c-reference-face-name)
@@ -1013,13 +1047,11 @@ casts and declarations are fontified. Used on level 2 and higher."
1013 1047
1014 ;;(message "c-font-lock-declarators from %s to %s" (point) limit) 1048 ;;(message "c-font-lock-declarators from %s to %s" (point) limit)
1015 (c-fontify-types-and-refs 1049 (c-fontify-types-and-refs
1016 ((pos (point)) next-pos id-start id-end 1050 ((pos (point)) next-pos id-start
1017 decl-res 1051 decl-res
1018 paren-depth
1019 id-face got-type got-init 1052 id-face got-type got-init
1020 c-last-identifier-range 1053 c-last-identifier-range
1021 (separator-prop (if types 'c-decl-type-start 'c-decl-id-start)) 1054 (separator-prop (if types 'c-decl-type-start 'c-decl-id-start)))
1022 brackets-after-id)
1023 1055
1024 ;; The following `while' fontifies a single declarator id each time round. 1056 ;; The following `while' fontifies a single declarator id each time round.
1025 ;; It loops only when LIST is non-nil. 1057 ;; It loops only when LIST is non-nil.
@@ -1036,7 +1068,7 @@ casts and declarations are fontified. Used on level 2 and higher."
1036 (forward-char) 1068 (forward-char)
1037 (c-forward-syntactic-ws) 1069 (c-forward-syntactic-ws)
1038 (looking-at "[*&]"))) 1070 (looking-at "[*&]")))
1039 (not (car (cddr decl-res))) ; brackets-after-id 1071 (not (car (cddr decl-res)))
1040 (or (not (c-major-mode-is 'c++-mode)) 1072 (or (not (c-major-mode-is 'c++-mode))
1041 (save-excursion 1073 (save-excursion
1042 (let (c-last-identifier-range) 1074 (let (c-last-identifier-range)
@@ -1375,7 +1407,6 @@ casts and declarations are fontified. Used on level 2 and higher."
1375 ;; it finds any. That's necessary so that we later will 1407 ;; it finds any. That's necessary so that we later will
1376 ;; stop inside them to fontify types there. 1408 ;; stop inside them to fontify types there.
1377 (c-parse-and-markup-<>-arglists t) 1409 (c-parse-and-markup-<>-arglists t)
1378 lbrace ; position of some {.
1379 ;; The font-lock package in Emacs is known to clobber 1410 ;; The font-lock package in Emacs is known to clobber
1380 ;; `parse-sexp-lookup-properties' (when it exists). 1411 ;; `parse-sexp-lookup-properties' (when it exists).
1381 (parse-sexp-lookup-properties 1412 (parse-sexp-lookup-properties
@@ -2503,7 +2534,7 @@ need for `c++-font-lock-extra-types'.")
2503 limit 2534 limit
2504 "[-+]" 2535 "[-+]"
2505 nil 2536 nil
2506 (lambda (match-pos inside-macro &optional top-level) 2537 (lambda (_match-pos _inside-macro &optional _top-level)
2507 (forward-char) 2538 (forward-char)
2508 (c-font-lock-objc-method)))) 2539 (c-font-lock-objc-method))))
2509 nil) 2540 nil)
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index a9d5ac34ad4..8be806094cd 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -130,7 +130,7 @@
130 130
131 131
132;; This file is not always loaded. See note above. 132;; This file is not always loaded. See note above.
133(cc-external-require (if (eq c--mapcan-status 'cl-mapcan) 'cl-lib 'cl)) 133(cc-external-require (if (eq c--cl-library 'cl-lib) 'cl-lib 'cl))
134 134
135 135
136;;; Setup for the `c-lang-defvar' system. 136;;; Setup for the `c-lang-defvar' system.
@@ -474,18 +474,19 @@ so that all identifiers are recognized as words.")
474 ;; The value here may be a list of functions or a single function. 474 ;; The value here may be a list of functions or a single function.
475 t nil 475 t nil
476 c++ '(c-extend-region-for-CPP 476 c++ '(c-extend-region-for-CPP
477; c-before-after-change-extend-region-for-lambda-capture ; doesn't seem needed.
478 c-before-change-check-raw-strings 477 c-before-change-check-raw-strings
479 c-before-change-check-<>-operators 478 c-before-change-check-<>-operators
480 c-depropertize-CPP 479 c-depropertize-CPP
481 c-before-after-change-digit-quote
482 c-invalidate-macro-cache 480 c-invalidate-macro-cache
483 c-truncate-bs-cache) 481 c-truncate-bs-cache
482 c-parse-quotes-before-change)
484 (c objc) '(c-extend-region-for-CPP 483 (c objc) '(c-extend-region-for-CPP
485 c-depropertize-CPP 484 c-depropertize-CPP
486 c-invalidate-macro-cache 485 c-invalidate-macro-cache
487 c-truncate-bs-cache) 486 c-truncate-bs-cache
488 ;; java 'c-before-change-check-<>-operators 487 c-parse-quotes-before-change)
488 java 'c-parse-quotes-before-change
489 ;; 'c-before-change-check-<>-operators
489 awk 'c-awk-record-region-clear-NL) 490 awk 'c-awk-record-region-clear-NL)
490(c-lang-defvar c-get-state-before-change-functions 491(c-lang-defvar c-get-state-before-change-functions
491 (let ((fs (c-lang-const c-get-state-before-change-functions))) 492 (let ((fs (c-lang-const c-get-state-before-change-functions)))
@@ -515,18 +516,19 @@ parameters \(point-min) and \(point-max).")
515 t '(c-depropertize-new-text 516 t '(c-depropertize-new-text
516 c-change-expand-fl-region) 517 c-change-expand-fl-region)
517 (c objc) '(c-depropertize-new-text 518 (c objc) '(c-depropertize-new-text
519 c-parse-quotes-after-change
518 c-extend-font-lock-region-for-macros 520 c-extend-font-lock-region-for-macros
519 c-neutralize-syntax-in-and-mark-CPP 521 c-neutralize-syntax-in-and-mark-CPP
520 c-change-expand-fl-region) 522 c-change-expand-fl-region)
521 c++ '(c-depropertize-new-text 523 c++ '(c-depropertize-new-text
524 c-parse-quotes-after-change
522 c-extend-font-lock-region-for-macros 525 c-extend-font-lock-region-for-macros
523; c-before-after-change-extend-region-for-lambda-capture ; doesn't seem needed.
524 c-before-after-change-digit-quote
525 c-after-change-re-mark-raw-strings 526 c-after-change-re-mark-raw-strings
526 c-neutralize-syntax-in-and-mark-CPP 527 c-neutralize-syntax-in-and-mark-CPP
527 c-restore-<>-properties 528 c-restore-<>-properties
528 c-change-expand-fl-region) 529 c-change-expand-fl-region)
529 java '(c-depropertize-new-text 530 java '(c-depropertize-new-text
531 c-parse-quotes-after-change
530 c-restore-<>-properties 532 c-restore-<>-properties
531 c-change-expand-fl-region) 533 c-change-expand-fl-region)
532 awk '(c-depropertize-new-text 534 awk '(c-depropertize-new-text
@@ -609,6 +611,12 @@ EOL terminated statements."
609 (c c++ objc) t) 611 (c c++ objc) t)
610(c-lang-defvar c-has-bitfields (c-lang-const c-has-bitfields)) 612(c-lang-defvar c-has-bitfields (c-lang-const c-has-bitfields))
611 613
614(c-lang-defconst c-has-quoted-numbers
615 "Whether the language has numbers quoted like 4'294'967'295."
616 t nil
617 c++ t)
618(c-lang-defvar c-has-quoted-numbers (c-lang-const c-has-quoted-numbers))
619
612(c-lang-defconst c-modified-constant 620(c-lang-defconst c-modified-constant
613 "Regexp that matches a “modified” constant literal such as \"L\\='a\\='\", 621 "Regexp that matches a “modified” constant literal such as \"L\\='a\\='\",
614a “long character”. In particular, this recognizes forms of constant 622a “long character”. In particular, this recognizes forms of constant
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index a501ebba256..ef93f75c5f3 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -1083,101 +1083,219 @@ Note that the style variables are always made local to the buffer."
1083 (forward-line)) ; no infinite loop with, e.g., "#//" 1083 (forward-line)) ; no infinite loop with, e.g., "#//"
1084 ))))) 1084 )))))
1085 1085
1086(defun c-before-after-change-digit-quote (beg end &optional old-len) 1086;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1087 ;; This function either removes or applies the punctuation value ('(1)) of 1087;; Parsing of quotes.
1088 ;; the `syntax-table' text property on single quote marks which are 1088;;
1089 ;; separator characters in long integer literals, e.g. "4'294'967'295". It 1089;; Valid digit separators in numbers will get the syntax-table "punctuation"
1090 ;; applies to both decimal/octal and hex literals. (FIXME (2016-06-10): it 1090;; property, '(1), and also the text property `c-digit-separator' value t.
1091 ;; should also apply to binary literals.) 1091;;
1092;; Invalid other quotes (i.e. those not validly bounding a single character,
1093;; or escaped character) will get the syntax-table "punctuation" property,
1094;; '(1), too.
1095;;
1096;; Note that, for convenience, these properties are applied even inside
1097;; comments and strings.
1098
1099(defconst c-maybe-quoted-number-head
1100 (concat
1101 "\\(0\\("
1102 "\\([Xx]\\([0-9a-fA-F]\\('[0-9a-fA-F]\\|[0-9a-fA-F]\\)*'?\\)?\\)"
1103 "\\|"
1104 "\\([Bb]\\([01]\\('[01]\\|[01]\\)*'?\\)?\\)"
1105 "\\|"
1106 "\\('[0-7]\\|[0-7]\\)*'?"
1107 "\\)"
1108 "\\|"
1109 "[1-9]\\('[0-9]\\|[0-9]\\)*'?"
1110 "\\)")
1111 "Regexp matching the head of a numeric literal, including with digit separators.")
1112
1113(defun c-quoted-number-head-before-point ()
1114 ;; Return non-nil when the head of a possibly quoted number is found
1115 ;; immediately before point. The value returned in this case is the buffer
1116 ;; position of the start of the head. That position is also in
1117 ;; (match-beginning 0).
1118 (when c-has-quoted-numbers
1119 (save-excursion
1120 (let ((here (point))
1121 found)
1122 (skip-chars-backward "0-9a-fA-F'")
1123 (if (and (memq (char-before) '(?x ?X))
1124 (eq (char-before (1- (point))) ?0))
1125 (backward-char 2))
1126 (while
1127 (and
1128 (setq found
1129 (search-forward-regexp c-maybe-quoted-number-head here t))
1130 (< found here)))
1131 (and (eq found here) (match-beginning 0))))))
1132
1133(defconst c-maybe-quoted-number-tail
1134 (concat
1135 "\\("
1136 "\\([xX']?[0-9a-fA-F]\\('[0-9a-fA-F]\\|[0-9a-fA-F]\\)*\\)"
1137 "\\|"
1138 "\\([bB']?[01]\\('[01]\\|[01]\\)*\\)"
1139 "\\|"
1140 "\\('?[0-9]\\('[0-9]\\|[0-9]\\)*\\)"
1141 "\\)")
1142 "Regexp matching the tail of a numeric literal, including with digit separators.
1143Note that this is a strict tail, so won't match, e.g. \"0x....\".")
1144
1145(defun c-quoted-number-tail-after-point ()
1146 ;; Return non-nil when a proper tail of a possibly quoted number is found
1147 ;; immediately after point. The value returned in this case is the buffer
1148 ;; position of the end of the tail. That position is also in (match-end 0).
1149 (when c-has-quoted-numbers
1150 (and (looking-at c-maybe-quoted-number-tail)
1151 (match-end 0))))
1152
1153(defconst c-maybe-quoted-number
1154 (concat
1155 "\\(0\\("
1156 "\\([Xx][0-9a-fA-F]\\('[0-9a-fA-F]\\|[0-9a-fA-F]\\)*\\)"
1157 "\\|"
1158 "\\([Bb][01]\\('[01]\\|[01]\\)*\\)"
1159 "\\|"
1160 "\\('[0-7]\\|[0-7]\\)*"
1161 "\\)"
1162 "\\|"
1163 "[1-9]\\('[0-9]\\|[0-9]\\)*"
1164 "\\)")
1165 "Regexp matching a numeric literal, including with digit separators.")
1166
1167(defun c-quoted-number-straddling-point ()
1168 ;; Return non-nil if a definitely quoted number starts before point and ends
1169 ;; after point. In this case the number is bounded by (match-beginning 0)
1170 ;; and (match-end 0).
1171 (when c-has-quoted-numbers
1172 (save-excursion
1173 (let ((here (point))
1174 (bound (progn (skip-chars-forward "0-9a-fA-F'") (point))))
1175 (goto-char here)
1176 (when (< (skip-chars-backward "0-9a-fA-F'") 0)
1177 (if (and (memq (char-before) '(?x ?X))
1178 (eq (char-before (1- (point))) ?0))
1179 (backward-char 2))
1180 (while (and (search-forward-regexp c-maybe-quoted-number bound t)
1181 (<= (match-end 0) here)))
1182 (and (< (match-beginning 0) here)
1183 (> (match-end 0) here)
1184 (save-match-data
1185 (goto-char (match-beginning 0))
1186 (save-excursion (search-forward "'" (match-end 0) t)))))))))
1187
1188(defun c-parse-quotes-before-change (beg end)
1189 ;; This function analyzes 's near the region (c-new-BEG c-new-END), amending
1190 ;; those two variables as needed to include 's into that region when they
1191 ;; might be syntactically relevant to the change in progress.
1092 ;; 1192 ;;
1093 ;; In both uses of the function, the `syntax-table' properties are 1193 ;; Having amended that region, the function removes pertinent text
1094 ;; removed/applied only on quote marks which appear to be digit separators. 1194 ;; properties (syntax-table properties with value '(1) and c-digit-separator
1195 ;; props with value t) from 's in it. This operation is performed even
1196 ;; within strings and comments.
1095 ;; 1197 ;;
1096 ;; Point is undefined on both entry and exit to this function, and the 1198 ;; This function is called exclusively as a before-change function via the
1097 ;; return value has no significance. The function is called solely as a 1199 ;; variable `c-get-state-before-change-functions'.
1098 ;; before-change function (see `c-get-state-before-change-functions') and as 1200 (c-save-buffer-state (p-limit limits found)
1099 ;; an after change function (see `c-before-font-lock-functions', with the 1201 ;; Special consideraton for deleting \ from '\''.
1100 ;; parameters BEG, END, and (optionally) OLD-LEN being given the standard 1202 (if (and (> end beg)
1101 ;; values for before/after-change functions. 1203 (eq (char-before end) ?\\)
1102 (c-save-buffer-state ((num-begin c-new-BEG) digit-re try-end) 1204 (<= c-new-END end))
1205 (setq c-new-END (min (1+ end) (point-max))))
1206
1207 ;; Do we have a ' (or something like ',',',',',') within range of
1208 ;; c-new-BEG?
1209 (goto-char c-new-BEG)
1210 (setq p-limit (max (- (point) 2) (point-min)))
1211 (while (and (skip-chars-backward "^\\\\'" p-limit)
1212 (> (point) p-limit))
1213 (when (eq (char-before) ?\\)
1214 (setq p-limit (max (1- p-limit) (point-min))))
1215 (backward-char)
1216 (setq c-new-BEG (point)))
1217 (beginning-of-line)
1218 (while (and
1219 (setq found (search-forward-regexp "\\('\\([^'\\]\\|\\\\.\\)\\)*'"
1220 c-new-BEG 'limit))
1221 (< (point) (1- c-new-BEG))))
1222 (if found
1223 (setq c-new-BEG
1224 (if (and (eq (point) (1- c-new-BEG))
1225 (eq (char-after) ?')) ; "''" before c-new-BEG.
1226 (1- c-new-BEG)
1227 (match-beginning 0))))
1228
1229 ;; Check for a number with quote separators straddling c-new-BEG
1230 (when c-has-quoted-numbers
1231 (goto-char c-new-BEG)
1232 (when ;; (c-quoted-number-straddling-point)
1233 (c-quoted-number-head-before-point)
1234 (setq c-new-BEG (match-beginning 0))))
1235
1236 ;; Do we have a ' (or something like ',',',',...,',') within range of
1237 ;; c-new-END?
1103 (goto-char c-new-END) 1238 (goto-char c-new-END)
1104 (when (looking-at "\\(x\\)?[0-9a-fA-F']+") 1239 (setq p-limit (min (+ (point) 2) (point-max)))
1105 (setq c-new-END (match-end 0))) 1240 (while (and (skip-chars-forward "^\\\\'" p-limit)
1241 (< (point) p-limit))
1242 (when (eq (char-after) ?\\)
1243 (setq p-limit (min (1+ p-limit) (point-max))))
1244 (forward-char)
1245 (setq c-new-END (point)))
1246 (if (looking-at "[^']?\\('\\([^'\\]\\|\\\\.\\)\\)*'")
1247 (setq c-new-END (match-end 0)))
1248
1249 ;; Check for a number with quote separators straddling c-new-END.
1250 (when c-has-quoted-numbers
1251 (goto-char c-new-END)
1252 (when ;; (c-quoted-number-straddling-point)
1253 (c-quoted-number-tail-after-point)
1254 (setq c-new-END (match-end 0))))
1255
1256 ;; Remove the '(1) syntax-table property from all "'"s within (c-new-BEG
1257 ;; c-new-END).
1258 (c-clear-char-property-with-value-on-char
1259 c-new-BEG c-new-END
1260 'syntax-table '(1)
1261 ?')
1262 ;; Remove the c-digit-separator text property from the same "'"s.
1263 (when c-has-quoted-numbers
1264 (c-clear-char-property-with-value-on-char
1265 c-new-BEG c-new-END
1266 'c-digit-separator t
1267 ?'))))
1268
1269(defun c-parse-quotes-after-change (beg end old-len)
1270 ;; This function applies syntax-table properties (value '(1)) and
1271 ;; c-digit-separator properties as needed to 's within the range (c-new-BEG
1272 ;; c-new-END). This operation is performed even within strings and
1273 ;; comments.
1274 ;;
1275 ;; This function is called exclusively as an after-change function via the
1276 ;; variable `c-before-font-lock-functions'.
1277 (c-save-buffer-state (p-limit limits num-beg num-end clear-from-BEG-to)
1278 ;; Apply the needed syntax-table and c-digit-separator text properties to
1279 ;; quotes.
1106 (goto-char c-new-BEG) 1280 (goto-char c-new-BEG)
1107 (when (looking-at "\\(x?\\)[0-9a-fA-F']") 1281 (while (and (< (point) c-new-END)
1108 (if (re-search-backward "\\(0x\\)?[0-9a-fA-F]*\\=" nil t) 1282 (search-forward "'" c-new-END 'limit))
1109 (setq c-new-BEG (point)))) 1283 (cond ((and (eq (char-before (1- (point))) ?\\)
1110 1284 ;; Check we've got an odd number of \s, here.
1111 (while
1112 (re-search-forward "[0-9a-fA-F]'[0-9a-fA-F]" c-new-END t)
1113 (setq try-end (1- (point)))
1114 (re-search-backward "[^0-9a-fA-F']" num-begin t)
1115 (setq digit-re
1116 (cond
1117 ((and (not (bobp)) (eq (char-before) ?0) (memq (char-after) '(?x ?X)))
1118 "[0-9a-fA-F]")
1119 ((and (eq (char-after (1+ (point))) ?0)
1120 (memq (char-after (+ 2 (point))) '(?b ?B)))
1121 "[01]")
1122 ((memq (char-after (1+ (point))) '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
1123 "[0-9]")
1124 (t nil)))
1125 (when digit-re
1126 (cond ((eq (char-after) ?x) (forward-char))
1127 ((looking-at ".?0[Bb]") (goto-char (match-end 0)))
1128 ((looking-at digit-re))
1129 (t (forward-char)))
1130 (when (not (c-in-literal))
1131 (let ((num-end ; End of valid sequence of digits/quotes.
1132 (save-excursion
1133 (re-search-forward
1134 (concat "\\=\\(" digit-re "+'\\)*" digit-re "+") nil t)
1135 (point))))
1136 (setq try-end ; End of sequence of digits/quotes
1137 (save-excursion 1285 (save-excursion
1138 (re-search-forward 1286 (backward-char)
1139 (concat "\\=\\(" digit-re "\\|'\\)+") nil t) 1287 (eq (logand (skip-chars-backward "\\\\") 1) 1)))) ; not a real '.
1140 (point))) 1288 ((c-quoted-number-straddling-point)
1141 (while (re-search-forward 1289 (setq num-beg (match-beginning 0)
1142 (concat digit-re "\\('\\)" digit-re) num-end t) 1290 num-end (match-end 0))
1143 (if old-len ; i.e. are we in an after-change function? 1291 (c-put-char-properties-on-char num-beg num-end
1144 (c-put-char-property (match-beginning 1) 'syntax-table '(1)) 1292 'syntax-table '(1) ?')
1145 (c-clear-char-property (match-beginning 1) 'syntax-table)) 1293 (c-put-char-properties-on-char num-beg num-end
1146 (backward-char))))) 1294 'c-digit-separator t ?')
1147 (goto-char try-end) 1295 (goto-char num-end))
1148 (setq num-begin (point))))) 1296 ((looking-at "\\([^\\']\\|\\\\.\\)'") ; balanced quoted expression.
1149 1297 (goto-char (match-end 0)))
1150;; The following doesn't seem needed at the moment (2016-08-15). 1298 (t (c-put-char-property (1- (point)) 'syntax-table '(1)))))))
1151;; (defun c-before-after-change-extend-region-for-lambda-capture
1152;; (_beg _end &optional _old-len)
1153;; ;; In C++ Mode, extend the region (c-new-BEG c-new-END) to cover any lambda
1154;; ;; function capture lists we happen to be inside. This function is expected
1155;; ;; to be called both as a before-change and after change function.
1156;; ;;
1157;; ;; Note that these things _might_ be nested, with a capture list looking
1158;; ;; like:
1159;; ;;
1160;; ;; [ ...., &foo = [..](){...}(..), ... ]
1161;; ;;
1162;; ;; . What a wonderful language is C++. ;-)
1163;; (c-save-buffer-state (paren-state pos)
1164;; (goto-char c-new-BEG)
1165;; (setq paren-state (c-parse-state))
1166;; (while (setq pos (c-pull-open-brace paren-state))
1167;; (goto-char pos)
1168;; (when (c-looking-at-c++-lambda-capture-list)
1169;; (setq c-new-BEG (min c-new-BEG pos))
1170;; (if (c-go-list-forward)
1171;; (setq c-new-END (max c-new-END (point))))))
1172
1173;; (goto-char c-new-END)
1174;; (setq paren-state (c-parse-state))
1175;; (while (setq pos (c-pull-open-brace paren-state))
1176;; (goto-char pos)
1177;; (when (c-looking-at-c++-lambda-capture-list)
1178;; (setq c-new-BEG (min c-new-BEG pos))
1179;; (if (c-go-list-forward)
1180;; (setq c-new-END (max c-new-END (point))))))))
1181 1299
1182(defun c-before-change (beg end) 1300(defun c-before-change (beg end)
1183 ;; Function to be put on `before-change-functions'. Primarily, this calls 1301 ;; Function to be put on `before-change-functions'. Primarily, this calls
diff --git a/lisp/progmodes/cc-styles.el b/lisp/progmodes/cc-styles.el
index b3848a74f97..b1c94c3bc6a 100644
--- a/lisp/progmodes/cc-styles.el
+++ b/lisp/progmodes/cc-styles.el
@@ -47,6 +47,7 @@
47;; `c-add-style' often contains references to functions defined there. 47;; `c-add-style' often contains references to functions defined there.
48 48
49;; Silence the compiler. 49;; Silence the compiler.
50(cc-bytecomp-defun c-guess-basic-syntax)
50(cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs 51(cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs
51 52
52 53
diff --git a/lisp/progmodes/tcl.el b/lisp/progmodes/tcl.el
index 902a5aace08..de0cd50911a 100644
--- a/lisp/progmodes/tcl.el
+++ b/lisp/progmodes/tcl.el
@@ -353,8 +353,6 @@ information):
353 Quotes all \"#\" characters that don't correspond to actual 353 Quotes all \"#\" characters that don't correspond to actual
354 Tcl comments. (Useful when editing code not originally created 354 Tcl comments. (Useful when editing code not originally created
355 with this mode). 355 with this mode).
356 `tcl-auto-fill-mode'
357 Auto-filling of Tcl comments.
358 356
359Add functions to the hook with `add-hook': 357Add functions to the hook with `add-hook':
360 358
@@ -1413,6 +1411,9 @@ Prefix argument means switch to the Tcl buffer afterwards."
1413 1411
1414(defun tcl-auto-fill-mode (&optional arg) 1412(defun tcl-auto-fill-mode (&optional arg)
1415 "Like `auto-fill-mode', but sets `comment-auto-fill-only-comments'." 1413 "Like `auto-fill-mode', but sets `comment-auto-fill-only-comments'."
1414 (declare
1415 (obsolete
1416 "Use `auto-fill-mode' with `comment-auto-fill-only-comments'." "26.1"))
1416 (interactive "P") 1417 (interactive "P")
1417 (auto-fill-mode arg) 1418 (auto-fill-mode arg)
1418 (if auto-fill-function 1419 (if auto-fill-function