summaryrefslogtreecommitdiff
path: root/lisp/progmodes/cc-defs.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/cc-defs.el')
-rw-r--r--lisp/progmodes/cc-defs.el203
1 files changed, 158 insertions, 45 deletions
diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el
index 40318b149d8..d20e3ef32d9 100644
--- a/lisp/progmodes/cc-defs.el
+++ b/lisp/progmodes/cc-defs.el
@@ -81,7 +81,7 @@
(progn
(require 'font-lock)
(let (font-lock-keywords)
- (font-lock-compile-keywords '("\\<\\>"))
+ (font-lock-compile-keywords (list regexp-unmatchable))
font-lock-keywords))))
@@ -212,6 +212,13 @@ This variant works around bugs in `eval-when-compile' in various
`(cl-delete-duplicates ,cl-seq ,@cl-keys)
`(delete-duplicates ,cl-seq ,@cl-keys))))
+(defmacro c-font-lock-flush (beg end)
+ "Declare the region BEG...END's fontification as out-of-date.
+On XEmacs and older Emacsen, this refontifies that region immediately."
+ (if (fboundp 'font-lock-flush)
+ `(font-lock-flush ,beg ,end)
+ `(font-lock-fontify-region ,beg ,end)))
+
(defmacro c-point (position &optional point)
"Return the value of certain commonly referenced POSITIONs relative to POINT.
The current point is used if POINT isn't specified. POSITION can be
@@ -219,6 +226,7 @@ one of the following symbols:
`bol' -- beginning of line
`eol' -- end of line
+`eoll' -- end of logical line (i.e. without escaped NL)
`bod' -- beginning of defun
`eod' -- end of defun
`boi' -- beginning of indentation
@@ -240,7 +248,7 @@ to it is returned. This function does not modify the point or the mark."
((eq position 'bol)
(if (and (cc-bytecomp-fboundp 'line-beginning-position) (not point))
- `(line-beginning-position)
+ '(line-beginning-position)
`(save-excursion
,@(if point `((goto-char ,point)))
(beginning-of-line)
@@ -248,12 +256,24 @@ to it is returned. This function does not modify the point or the mark."
((eq position 'eol)
(if (and (cc-bytecomp-fboundp 'line-end-position) (not point))
- `(line-end-position)
+ '(line-end-position)
`(save-excursion
,@(if point `((goto-char ,point)))
(end-of-line)
(point))))
+ ((eq position 'eoll)
+ `(save-excursion
+ ,@(if point `((goto-char ,point)))
+ (while (and
+ (not (eobp))
+ (progn
+ (end-of-line)
+ (prog1 (eq (logand 1 (skip-chars-backward "\\\\")) 1))))
+ (forward-line))
+ (end-of-line)
+ (point)))
+
((eq position 'boi)
`(save-excursion
,@(if point `((goto-char ,point)))
@@ -274,7 +294,7 @@ to it is returned. This function does not modify the point or the mark."
((eq position 'bopl)
(if (and (cc-bytecomp-fboundp 'line-beginning-position) (not point))
- `(line-beginning-position 0)
+ '(line-beginning-position 0)
`(save-excursion
,@(if point `((goto-char ,point)))
(forward-line -1)
@@ -282,7 +302,7 @@ to it is returned. This function does not modify the point or the mark."
((eq position 'bonl)
(if (and (cc-bytecomp-fboundp 'line-beginning-position) (not point))
- `(line-beginning-position 2)
+ '(line-beginning-position 2)
`(save-excursion
,@(if point `((goto-char ,point)))
(forward-line 1)
@@ -290,7 +310,7 @@ to it is returned. This function does not modify the point or the mark."
((eq position 'eopl)
(if (and (cc-bytecomp-fboundp 'line-end-position) (not point))
- `(line-end-position 0)
+ '(line-end-position 0)
`(save-excursion
,@(if point `((goto-char ,point)))
(beginning-of-line)
@@ -299,7 +319,7 @@ to it is returned. This function does not modify the point or the mark."
((eq position 'eonl)
(if (and (cc-bytecomp-fboundp 'line-end-position) (not point))
- `(line-end-position 2)
+ '(line-end-position 2)
`(save-excursion
,@(if point `((goto-char ,point)))
(forward-line 1)
@@ -453,6 +473,13 @@ to it is returned. This function does not modify the point or the mark."
`(int-to-char ,integer)
integer))
+(defmacro c-characterp (arg)
+ ;; Return t when ARG is a character (XEmacs) or integer (Emacs), otherwise
+ ;; return nil.
+ (if (integerp ?c)
+ `(integerp ,arg)
+ `(characterp ,arg)))
+
(defmacro c-last-command-char ()
;; The last character just typed. Note that `last-command-event' exists in
;; both Emacs and XEmacs, but with confusingly different meanings.
@@ -464,17 +491,42 @@ to it is returned. This function does not modify the point or the mark."
;; Get the regular expression `sentence-end'.
(if (cc-bytecomp-fboundp 'sentence-end)
;; Emacs 22:
- `(sentence-end)
+ '(sentence-end)
;; Emacs <22 + XEmacs
- `sentence-end))
+ 'sentence-end))
(defmacro c-default-value-sentence-end ()
;; Get the default value of the variable sentence end.
(if (cc-bytecomp-fboundp 'sentence-end)
;; Emacs 22:
- `(let (sentence-end) (sentence-end))
+ '(let (sentence-end) (sentence-end))
;; Emacs <22 + XEmacs
- `(default-value 'sentence-end)))
+ '(default-value 'sentence-end)))
+
+(defconst c-c++-raw-string-opener-re "R\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)(")
+;; Matches a C++ raw string opener. Submatch 1 is its identifier.
+
+(defconst c-c++-raw-string-opener-1-re "\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)(")
+;; Matches a C++ raw string opener starting after the initial R.
+
+(defmacro c-sub-at-c++-raw-string-opener ()
+ `(save-excursion
+ (and
+ (if (eq (char-after) ?R)
+ (progn (forward-char) t)
+ (eq (char-before) ?R))
+ (looking-at c-c++-raw-string-opener-1-re))))
+
+(defmacro c-at-c++-raw-string-opener (&optional pos)
+ ;; Return non-nil if POS (default point) is either at the start of a C++ raw
+ ;; string opener, or after the introductory R of one. The match data is
+ ;; overwritten. On success the opener's identifier will be (match-string
+ ;; 1). Text properties on any characters are ignored.
+ (if pos
+ `(save-excursion
+ (goto-char ,pos)
+ (c-sub-at-c++-raw-string-opener))
+ `(c-sub-at-c++-raw-string-opener)))
;; The following is essentially `save-buffer-state' from lazy-lock.el.
;; It ought to be a standard macro.
@@ -673,7 +725,7 @@ leave point unmoved.
A LIMIT for the search may be given. The start position is assumed to be
before it."
- `(let ((dest (c-safe-scan-lists ,(or pos `(point)) 1 0 ,limit)))
+ `(let ((dest (c-safe-scan-lists ,(or pos '(point)) 1 0 ,limit)))
(when dest (goto-char dest) dest)))
(defmacro c-go-list-backward (&optional pos limit)
@@ -683,7 +735,7 @@ leave point unmoved.
A LIMIT for the search may be given. The start position is assumed to be
after it."
- `(let ((dest (c-safe-scan-lists ,(or pos `(point)) -1 0 ,limit)))
+ `(let ((dest (c-safe-scan-lists ,(or pos '(point)) -1 0 ,limit)))
(when dest (goto-char dest) dest)))
(defmacro c-up-list-forward (&optional pos limit)
@@ -692,7 +744,7 @@ or nil if no such position exists. The point is used if POS is left out.
A limit for the search may be given. The start position is assumed to
be before it."
- `(c-safe-scan-lists ,(or pos `(point)) 1 1 ,limit))
+ `(c-safe-scan-lists ,(or pos '(point)) 1 1 ,limit))
(defmacro c-up-list-backward (&optional pos limit)
"Return the position of the start of the list sexp containing POS,
@@ -700,7 +752,7 @@ or nil if no such position exists. The point is used if POS is left out.
A limit for the search may be given. The start position is assumed to
be after it."
- `(c-safe-scan-lists ,(or pos `(point)) -1 1 ,limit))
+ `(c-safe-scan-lists ,(or pos '(point)) -1 1 ,limit))
(defmacro c-down-list-forward (&optional pos limit)
"Return the first position inside the first list sexp after POS,
@@ -708,7 +760,7 @@ or nil if no such position exists. The point is used if POS is left out.
A limit for the search may be given. The start position is assumed to
be before it."
- `(c-safe-scan-lists ,(or pos `(point)) 1 -1 ,limit))
+ `(c-safe-scan-lists ,(or pos '(point)) 1 -1 ,limit))
(defmacro c-down-list-backward (&optional pos limit)
"Return the last position inside the last list sexp before POS,
@@ -716,7 +768,7 @@ or nil if no such position exists. The point is used if POS is left out.
A limit for the search may be given. The start position is assumed to
be after it."
- `(c-safe-scan-lists ,(or pos `(point)) -1 -1 ,limit))
+ `(c-safe-scan-lists ,(or pos '(point)) -1 -1 ,limit))
(defmacro c-go-up-list-forward (&optional pos limit)
"Move the point to the first position after the list sexp containing POS,
@@ -877,7 +929,7 @@ be after it."
;; c-beginning-of-statement-1.
;; Languages which don't have EOL terminated statements always return NIL
;; (they _know_ there's no vsemi ;-).
- `(if c-vsemi-status-unknown-p-fn (funcall c-vsemi-status-unknown-p-fn)))
+ '(if c-vsemi-status-unknown-p-fn (funcall c-vsemi-status-unknown-p-fn)))
(defmacro c-benign-error (format &rest args)
@@ -1196,7 +1248,7 @@ Leave point just after the character, and set the match data on
this character, and return point. If the search fails, return
nil; point is then left undefined."
`(let ((char-skip (concat "^" (char-to-string ,char)))
- (-limit- ,limit)
+ (-limit- (or ,limit (point-max)))
(-value- ,value))
(while
(and
@@ -1208,15 +1260,39 @@ nil; point is then left undefined."
(search-forward-regexp ".") ; to set the match-data.
(point))))
+(defmacro c-search-forward-char-property-without-value-on-char
+ (property value char &optional limit)
+ "Search forward for a character CHAR without text property PROPERTY having
+a value CHAR.
+LIMIT bounds the search. The value comparison is done with `equal'.
+PROPERTY must be a constant.
+
+Leave point just after the character, and set the match data on
+this character, and return point. If the search fails, return
+nil; point is then left undefined."
+ `(let ((char-skip (concat "^" (char-to-string ,char)))
+ (-limit- (or ,limit (point-max)))
+ (-value- ,value))
+ (while
+ (and
+ (progn (skip-chars-forward char-skip -limit-)
+ (< (point) -limit-))
+ (equal (c-get-char-property (point) ,property) -value-))
+ (forward-char))
+ (when (< (point) -limit-)
+ (search-forward-regexp ".") ; to set the match-data.
+ (point))))
+
(defun c-clear-char-property-with-value-on-char-function (from to property
value char)
"Remove all text-properties PROPERTY with value VALUE on
characters with value CHAR from the region [FROM, TO), as tested
by `equal'. These properties are assumed to be over individual
characters, having been put there by c-put-char-property. POINT
-remains unchanged."
+remains unchanged. Return the position of the first removed
+property, or nil."
(let ((place from)
- )
+ first)
(while ; loop round occurrences of (PROPERTY VALUE)
(progn
(while ; loop round changes in PROPERTY till we find VALUE
@@ -1225,28 +1301,34 @@ remains unchanged."
(not (equal (get-text-property place property) value)))
(setq place (c-next-single-property-change place property nil to)))
(< place to))
- (if (eq (char-after place) char)
- (remove-text-properties place (1+ place) (cons property nil)))
+ (when (eq (char-after place) char)
+ (remove-text-properties place (1+ place) (cons property nil))
+ (or first (setq first place)))
;; Do we have to do anything with stickiness here?
- (setq place (1+ place)))))
+ (setq place (1+ place)))
+ first))
(defmacro c-clear-char-property-with-value-on-char (from to property value char)
"Remove all text-properties PROPERTY with value VALUE on
characters with value CHAR from the region [FROM, TO), as tested
by `equal'. These properties are assumed to be over individual
characters, having been put there by c-put-char-property. POINT
-remains unchanged."
+remains unchanged. Return the position of the first removed
+property, or nil."
(if c-use-extents
;; XEmacs
`(let ((-property- ,property)
- (-char- ,char))
+ (-char- ,char)
+ (first (1+ (point-max))))
(map-extents (lambda (ext val)
- (if (and (equal (extent-property ext -property-) val)
- (eq (char-after
- (extent-start-position ext))
- -char-))
- (delete-extent ext)))
- nil ,from ,to ,value nil -property-))
+ (when (and (equal (extent-property ext -property-) val)
+ (eq (char-after
+ (extent-start-position ext))
+ -char-))
+ (setq first (min first (extent-start-position ext)))
+ (delete-extent ext)))
+ nil ,from ,to ,value nil -property-)
+ (and (<= first (point-max)) first))
;; GNU Emacs
`(c-clear-char-property-with-value-on-char-function ,from ,to ,property
,value ,char)))
@@ -1298,20 +1380,37 @@ with value CHAR in the region [FROM to)."
;(eval-after-load "edebug" ; 2006-07-09: def-edebug-spec is now in subr.el.
; '(progn
(def-edebug-spec cc-eval-when-compile (&rest def-form))
+(def-edebug-spec c-font-lock-flush t)
+(def-edebug-spec c--mapcan t)
+(def-edebug-spec c--set-difference (form form &rest [symbolp form]))
+(def-edebug-spec c--intersection (form form &rest [symbolp form]))
+(def-edebug-spec c--delete-duplicates (form &rest [symbolp form]))
(def-edebug-spec c-point t)
+(def-edebug-spec c-next-single-property-change t)
+(def-edebug-spec c-delete-and-extract-region t)
(def-edebug-spec c-set-region-active t)
(def-edebug-spec c-set-keymap-parent t)
(def-edebug-spec c-safe t)
+(def-edebug-spec c-int-to-char t)
+(def-edebug-spec c-characterp t)
(def-edebug-spec c-save-buffer-state let*)
(def-edebug-spec c-tentative-buffer-changes t)
(def-edebug-spec c-forward-syntactic-ws t)
(def-edebug-spec c-backward-syntactic-ws t)
(def-edebug-spec c-forward-sexp t)
(def-edebug-spec c-backward-sexp t)
+(def-edebug-spec c-safe-scan-lists t)
+(def-edebug-spec c-go-list-forward t)
+(def-edebug-spec c-go-list-backward t)
(def-edebug-spec c-up-list-forward t)
(def-edebug-spec c-up-list-backward t)
(def-edebug-spec c-down-list-forward t)
(def-edebug-spec c-down-list-backward t)
+(def-edebug-spec c-go-up-list-forward t)
+(def-edebug-spec c-go-up-list-backward t)
+(def-edebug-spec c-go-down-list-forward t)
+(def-edebug-spec c-go-down-list-backward t)
+(def-edebug-spec c-at-vsemi-p t)
(def-edebug-spec c-add-syntax t)
(def-edebug-spec c-add-class-syntax t)
(def-edebug-spec c-benign-error t)
@@ -1319,15 +1418,28 @@ with value CHAR in the region [FROM to)."
(def-edebug-spec c-skip-ws-forward t)
(def-edebug-spec c-skip-ws-backward t)
(def-edebug-spec c-major-mode-is t)
+(def-edebug-spec c-search-forward-char-property t)
+(def-edebug-spec c-search-backward-char-property t)
(def-edebug-spec c-put-char-property t)
(def-edebug-spec c-get-char-property t)
(def-edebug-spec c-clear-char-property t)
+(def-edebug-spec c-clear-char-property-with-value t)
(def-edebug-spec c-clear-char-property-with-value-on-char t)
(def-edebug-spec c-put-char-properties-on-char t)
(def-edebug-spec c-clear-char-properties t)
(def-edebug-spec c-put-overlay t)
(def-edebug-spec c-delete-overlay t)
-(def-edebug-spec c-self-bind-state-cache t);))
+(def-edebug-spec c-mark-<-as-paren t)
+(def-edebug-spec c-mark->-as-paren t)
+(def-edebug-spec c-unmark-<->-as-paren t)
+(def-edebug-spec c-with-<->-as-parens-suppressed (body))
+(def-edebug-spec c-self-bind-state-cache (body))
+(def-edebug-spec c-sc-scan-lists-no-category+1+1 t)
+(def-edebug-spec c-sc-scan-lists-no-category+1-1 t)
+(def-edebug-spec c-sc-scan-lists-no-category-1+1 t)
+(def-edebug-spec c-sc-scan-lists-no-category-1-1 t)
+(def-edebug-spec c-sc-scan-lists t)
+(def-edebug-spec c-sc-parse-partial-sexp t);))
;;; Functions.
@@ -1560,12 +1672,12 @@ with value CHAR in the region [FROM to)."
(defmacro c-looking-at-non-alphnumspace ()
"Are we looking at a character which isn't alphanumeric or space?"
(if (memq 'gen-comment-delim c-emacs-features)
- `(looking-at
-"\\([;#]\\|\\'\\|\\s(\\|\\s)\\|\\s\"\\|\\s\\\\|\\s$\\|\\s<\\|\\s>\\|\\s!\\)")
- `(or (looking-at
-"\\([;#]\\|\\'\\|\\s(\\|\\s)\\|\\s\"\\|\\s\\\\|\\s$\\|\\s<\\|\\s>\\)"
- (let ((prop (c-get-char-property (point) 'syntax-table)))
- (eq prop '(14))))))) ; '(14) is generic comment delimiter.
+ '(looking-at
+ "\\([;#]\\|\\'\\|\\s(\\|\\s)\\|\\s\"\\|\\s\\\\|\\s$\\|\\s<\\|\\s>\\|\\s!\\)")
+ '(or (looking-at
+ "\\([;#]\\|\\'\\|\\s(\\|\\s)\\|\\s\"\\|\\s\\\\|\\s$\\|\\s<\\|\\s>\\)"
+ (let ((prop (c-get-char-property (point) 'syntax-table)))
+ (eq prop '(14))))))) ; '(14) is generic comment delimiter.
(defsubst c-intersect-lists (list alist)
@@ -1722,7 +1834,8 @@ when it's needed. The default is the current language taken from
t))
(setq pos (cdr pos)))
found))
- (setq pos list)
+ (setq pos (copy-tree list)
+ )
(while pos
(if (string-match "\\w\\'" (car pos))
(setcar pos (concat (car pos) unique)))
@@ -1775,10 +1888,10 @@ when it's needed. The default is the current language taken from
(t
re)))
- ;; Produce a regexp that matches nothing.
+ ;; Produce a regexp that doesn't match anything.
(if adorn
- "\\(\\<\\>\\)"
- "\\<\\>")))
+ (concat "\\(" regexp-unmatchable "\\)")
+ regexp-unmatchable)))
(put 'c-make-keywords-re 'lisp-indent-function 1)
@@ -1789,7 +1902,7 @@ The returned string is of the type that can be used with
non-nil, a caret is prepended to invert the set."
;; This function ought to be in the elisp core somewhere.
(let ((str (if inverted "^" "")) char char2)
- (setq chars (sort (append chars nil) `<))
+ (setq chars (sort (append chars nil) #'<))
(while chars
(setq char (pop chars))
(if (memq char '(?\\ ?^ ?-))
@@ -1840,7 +1953,7 @@ non-nil, a caret is prepended to invert the set."
(setq entry (get-char-table ?a table)))
;; incompatible
(t (error "CC Mode is incompatible with this version of Emacs")))
- (setq list (cons (if (= (logand (lsh entry -16) 255) 255)
+ (setq list (cons (if (= (logand (ash entry -16) 255) 255)
'8-bit
'1-bit)
list)))