diff options
author | Alan Mackenzie <acm@muc.de> | 2021-08-12 19:04:28 +0000 |
---|---|---|
committer | Alan Mackenzie <acm@muc.de> | 2021-08-12 19:04:28 +0000 |
commit | c4d34d24e36c7f7c54cf3ec3e5d76e3e8fc005aa (patch) | |
tree | 9c051c290e0dfb1d280e6035c0800c00cf1bfbb4 /lisp/progmodes/cc-defs.el | |
parent | 5d50acd0a61f70db4069457a5f14fb1a9b0f7f7c (diff) | |
download | emacs-c4d34d24e36c7f7c54cf3ec3e5d76e3e8fc005aa.tar.gz emacs-c4d34d24e36c7f7c54cf3ec3e5d76e3e8fc005aa.tar.bz2 emacs-c4d34d24e36c7f7c54cf3ec3e5d76e3e8fc005aa.zip |
CC Mode: Enhance C++ Mode raw strings to multi-line strings for any language
* lisp/progmodes/cc-defs.el (cadar, caddr, cdddr): Add defsubsts for these for
when they are missing from the host Emacs.
(c-point): Add new `position' 'boll "beginning of logical line".
(c-clear-char-properties): Return the position of the lowest removed
property.
* lisp/progmodes/cc-engine.el (c-full-pp-to-literal): Fix for rare case where
LIMIT < START in parse-partial-sexp.
(c-old-beg-rs, c-old-end-rs, c-raw-string-end-delim-disrupted)
(c-raw-string-pos, c-raw-string-in-end-delim, c-depropertize-raw-string)
(c-depropertize-raw-strings-in-region, c-before-change-check-raw-strings)
(c-propertize-raw-string-id, c-propertize-raw-string-opener): Old functions
and variables removed or renamed "raw" -> "ml" and adapted.
(c-old-beg-ml, c-old-1-beg-ml, c-old-end-ml, c-beg-pos, c-end-pos)
(c-ml-string-end-delim-disrupted, c-depropertize-ml-string-delims)
(c-ml-string-delims-around-point,c-position-wrt-ml-delims)
(c-before-change-check-ml-strings, c-after-change-unmark-ml-strings)
(c-maybe-re-mark-ml-string, c-propertize-ml-string-id)
(c-propertize-ml-string-opener, c-depropertize-ml-string)
(c-depropertize-ml-strings-in-region): New functions and variables adapted and
possibly renamed from "raw" -> "ml".
(c-ml-string-make-closer-re, c-ml-string-make-opener-re)
(c-c++-make-ml-string-closer-re, c-c++-make-ml-string-opener-re)
(c-get-ml-closer, c-ml-string-opener-around-point)
(c-ml-string-opener-intersects-region, c-ml-string-opener-at-or-around-point)
(c-ml-string-back-to-neutral, c-ml-string-in-end-delim, c-neutralize-pos)
(c-neutralized-prop): New functions and variables.
* lisp/progmodes/cc-fonts.el (c-basic-matchers-before): Replace
c-font-lock-raw-strings with c-font-lock-ml-strings.
(c-font-lock-ml-strings): New function taking the place of the old
c-font-lock-ml-strings.
* lisp/progmodes/cc-langs.el (c-get-state-before-change-functions): Move
c-depropertize-CPP to the second item of the C++ entry, and replace
c-before-change-check-raw-strings by c-before-change-check-ml-strings. Add a
new entry for Pike Mode.
(c-before-font-lock-functions): (Replace c-after-change-unmark-raw-strings by
c-after-change-unmark-ml-strings in the C++ entry, and add a new entry for
Pike Mode.
(c-ml-string-backslash-escapes, c-ml-string-non-punc-skip-chars)
(c-ml-string-opener-re, c-ml-string-max-opener-len, c-ml-string-any-closer-re)
(c-ml-string-max-closer-len, c-ml-string-max-closer-len-no-leader)
(c-ml-string-back-closer-re, c-make-ml-string-closer-re-function)
(c-make-ml-string-opener-re-function, c-ml-string-cpp-or-opener-re)
(c-cpp-or-ml-match-offset): New c-lang-defconsts and c-land-defvars.
(c-multiline-string-start-char): Remove the Pike Mode setting.
* lisp/progmodes/cc-mode.el (c-depropertize-CPP): Test for general ml strings
rather than C++ raw strings.
(c-unescaped-nls-in-string-p): Handle languages with ml strings.
(c-clear-string-fences): Fix bug with wrong parenthesisation.
(c-before-change-check-unbalanced-strings)
(c-after-change-mark-abnormal-strings, c-after-change-escape-NL-in-string):
Adapt for multi-line strings.
Diffstat (limited to 'lisp/progmodes/cc-defs.el')
-rw-r--r-- | lisp/progmodes/cc-defs.el | 53 |
1 files changed, 39 insertions, 14 deletions
diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el index 5d93435066f..01bd64cb5c3 100644 --- a/lisp/progmodes/cc-defs.el +++ b/lisp/progmodes/cc-defs.el @@ -174,6 +174,10 @@ This variant works around bugs in `eval-when-compile' in various ;;; Macros. +(or (fboundp 'cadar) (defsubst cadar (elt) (car (cdar elt)))) +(or (fboundp 'caddr) (defsubst caddr (elt) (car (cddr elt)))) +(or (fboundp 'cdddr) (defsubst cdddr (elt) (cdr (cddr elt)))) + (defmacro c--mapcan (fun liszt) ;; CC Mode equivalent of `mapcan' which bridges the difference ;; between the host [X]Emacsen." @@ -236,6 +240,7 @@ The current point is used if POINT isn't specified. POSITION can be one of the following symbols: `bol' -- beginning of line +`boll' -- beginning of logical line (i.e. without preceding escaped NL) `eol' -- end of line `eoll' -- end of logical line (i.e. without escaped NL) `bod' -- beginning of defun @@ -266,6 +271,15 @@ to it is returned. This function does not modify the point or the mark." (beginning-of-line) (point)))) + ((eq position 'boll) + `(save-excursion + ,@(if point `((goto-char ,point))) + (while (progn (beginning-of-line) + (when (not (bobp)) + (eq (char-before (1- (point))) ?\\))) + (backward-char)) + (point))) + ((eq position 'eol) (if (and (cc-bytecomp-fboundp 'line-end-position) (not point)) '(line-end-position) @@ -1254,6 +1268,9 @@ MODE is either a mode symbol or a list of mode symbols." ;; region that has been put with `c-put-char-property'. PROPERTY is ;; assumed to be constant. ;; + ;; The returned value is the buffer position of the lowest character + ;; whose PROPERTY was removed, or nil if there was none. + ;; ;; Note that this function does not clean up the property from the ;; lists of the `rear-nonsticky' properties in the region, if such ;; are used. Thus it should not be used for common properties like @@ -1262,20 +1279,28 @@ MODE is either a mode symbol or a list of mode symbols." ;; This macro does hidden buffer changes. (declare (debug t)) (setq property (eval property)) - (if c-use-extents - ;; XEmacs. - `(map-extents (lambda (ext ignored) - (delete-extent ext)) - nil ,from ,to nil nil ',property) - ;; Emacs. - (if (and (fboundp 'syntax-ppss) - (eq `,property 'syntax-table)) - `(let ((-from- ,from) (-to- ,to)) - (setq c-syntax-table-hwm - (min c-syntax-table-hwm - (c-min-property-position -from- -to- ',property))) - (remove-text-properties -from- -to- '(,property nil))) - `(remove-text-properties ,from ,to '(,property nil))))) + `(let* ((-to- ,to) + (ret (c-min-property-position ,from -to- ',property))) + (if (< ret -to-) + (progn + ,(cond + (c-use-extents + ;; XEmacs + `(map-extents (lambda (ext ignored) + (delete-extent ext)) + nil ret -to- nil nil ',property)) + ((and (fboundp 'syntax-ppss) + (eq property 'syntax-table)) + ;; Emacs 'syntax-table + `(progn + (setq c-syntax-table-hwm + (min c-syntax-table-hwm ret)) + (remove-text-properties ret -to- '(,property nil)))) + (t + ;; Emacs other property. + `(remove-text-properties ret -to- '(,property nil)))) + ret) + nil))) (defmacro c-clear-syn-tab-properties (from to) ;; Remove all occurrences of the `syntax-table' and `c-fl-syn-tab' text |