From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Alan Mackenzie <acm@muc.de>
Cc: emacs-devel@gnu.org
Subject: Re: Sync'ing cc-mode
Date: Fri, 26 Sep 2014 15:19:46 -0400 [thread overview]
Message-ID: <jwvzjdm9pb6.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <jwvy4tj32aa.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Tue, 16 Sep 2014 13:30:05 -0400")
Hi Alan,
Find below a patch against Emacs's trunk which should bring Emacs's
trunk up-to-date w.r.t your standalone cc-mode Hg repository.
IOW I think that most of the remaining differences should either be
applied to your Hg repository, or kept as "differences between the two
versions". Note that many/most of the differences are in whitespace, so
use "diff -bw" or something like that if you want to see the "real"
remaining changes. I decided to keep the whitespace as it is in Emacs
rather than in your branch, except for some cases where our branch had
clearly some mis-indentations (which can be seen in big hunks in
cc-engine.el below, which merit checking with diff-refine-hunk to see
that they indeed only change whitespace).
Actually, there are also a few grey areas where I couldn't decide how to
merge the two: e.g. one side uses `eval-after-load' and the other
commented it out and I'm not sure exactly how they should be merged.
Guaranteed 99% untested (I can open a file in C, C++, Java, AWK modes,
but I didn't get to test much more than that).
Stefan
PS: Most changes are just straightforward inclusion of new code from
your branch, but there are a few other details of note:
- rather than merge your cc-bytecomp-defmacro and cc-bytecomp-push
thingies, I just removed all their uses, since there pretty much weren't
any left anyway.
- I define c-subword-mode as an obsolete alias for subword-mode when
subword-mode is available so as to try and share some code between the
two cases.
- I use c--macroexpand-all to handle the fact that some emacsen
don't have cl-macroexpand-all and some don't have macroexpand-all.
- I use c--make-local-hook to handle the fact that some emacsen require
the use of make-local-hook whereas others have obsoleted it many years
ago and removed it a few years ago.
- I reverted the Emacs code to use `cl' instead of `cl-lib' in cc-langs
now that it's not loaded at runtime any more.
- When introducing c-unmark-<->-as-paren, you changed
a (c-clear-char-property pos 'category) to (c-unmark-<->-as-paren
(point)) and I assumed this was a copy&paste error.
=== modified file 'lisp/progmodes/cc-align.el'
--- lisp/progmodes/cc-align.el 2014-01-01 07:43:34 +0000
+++ lisp/progmodes/cc-align.el 2014-09-25 17:09:45 +0000
@@ -1229,6 +1229,18 @@
(back-to-indentation)
(vector (current-column))))
+(defun c-lineup-respect-col-0 (langelem)
+ "If the current line starts at column 0, return [0]. Otherwise return nil.
+
+This can be used for comments (in conjunction with, say,
+`c-lineup-comment'), to keep comments already at column 0
+anchored there, but reindent other comments."
+ (save-excursion
+ (back-to-indentation)
+ (if (eq (current-column) 0)
+ [0]
+ nil)))
+
\f
(defun c-snug-do-while (syntax pos)
"Dynamically calculate brace hanginess for do-while statements.
=== modified file 'lisp/progmodes/cc-awk.el'
--- lisp/progmodes/cc-awk.el 2014-09-10 21:38:11 +0000
+++ lisp/progmodes/cc-awk.el 2014-09-25 17:09:33 +0000
@@ -61,7 +61,6 @@
(cc-bytecomp-defun c-backward-token-1)
(cc-bytecomp-defun c-beginning-of-statement-1)
(cc-bytecomp-defun c-backward-sws)
-(cc-bytecomp-defun c-forward-sws)
(defvar awk-mode-syntax-table
(let ((st (make-syntax-table)))
@@ -174,6 +173,7 @@
(concat "\"\\(" c-awk-string-ch-re "\\|" c-awk-esc-pair-re "\\)*"
"\\(\"\\|$\\|\\'\\)"))
+
;; REGEXPS FOR AWK REGEXPS.
(defconst c-awk-regexp-normal-re "[^[/\\\n\r]")
;; Matches any AWK regexp character which doesn't require special analysis.
@@ -201,6 +201,7 @@
(concat "/" c-awk-regexp-innards-re))
;; Matches an AWK regexp up to, but not including, any terminating /.
+
;; REGEXPS used for scanning an AWK buffer in order to decide IF A '/' IS A
;; REGEXP OPENER OR A DIVISION SIGN. By "state" in the following is meant
;; whether a '/' at the current position would by a regexp opener or a
=== modified file 'lisp/progmodes/cc-bytecomp.el'
--- lisp/progmodes/cc-bytecomp.el 2014-01-01 07:43:34 +0000
+++ lisp/progmodes/cc-bytecomp.el 2014-09-25 21:30:55 +0000
@@ -65,8 +65,7 @@
;; elsewhere in the load path.
;;
;; To suppress byte compiler warnings, use the macros
-;; `cc-bytecomp-defun', `cc-bytecomp-defvar',
-;; `cc-bytecomp-obsolete-fun', and `cc-bytecomp-obsolete-var'.
+;; `cc-bytecomp-defun' and `cc-bytecomp-defvar'.
;;
;; This file is not used at all after the package has been byte
;; compiled. It is however necessary when running uncompiled.
@@ -78,6 +77,12 @@
(defvar cc-bytecomp-original-functions nil)
(defvar cc-bytecomp-original-properties nil)
(defvar cc-bytecomp-loaded-files nil)
+
+(setq cc-bytecomp-unbound-variables nil)
+(setq cc-bytecomp-original-functions nil)
+(setq cc-bytecomp-original-properties nil)
+(setq cc-bytecomp-loaded-files nil)
+
(defvar cc-bytecomp-environment-set nil)
(defmacro cc-bytecomp-debug-msg (&rest args)
@@ -370,33 +375,6 @@
"cc-bytecomp-put: Bound property %s for %s to %s"
,propname ,symbol ,value)))
-(defmacro cc-bytecomp-obsolete-var (symbol)
- "Suppress warnings that the given symbol is an obsolete variable.
-Don't use within `eval-when-compile'."
- `(eval-when-compile
- (if (get ',symbol 'byte-obsolete-variable)
- (cc-bytecomp-put ',symbol 'byte-obsolete-variable nil)
- ;; This avoids a superfluous compiler warning
- ;; about calling `get' for effect.
- t)))
-
-(defun cc-bytecomp-ignore-obsolete (form)
- ;; Wraps a call to `byte-compile-obsolete' that suppresses the warning.
- (let ((byte-compile-warnings byte-compile-warnings))
- (byte-compile-disable-warning 'obsolete)
- (byte-compile-obsolete form)))
-
-(defmacro cc-bytecomp-obsolete-fun (symbol)
- "Suppress warnings that the given symbol is an obsolete function.
-Don't use within `eval-when-compile'."
- `(eval-when-compile
- (if (eq (get ',symbol 'byte-compile) 'byte-compile-obsolete)
- (cc-bytecomp-put ',symbol 'byte-compile
- 'cc-bytecomp-ignore-obsolete)
- ;; This avoids a superfluous compiler warning
- ;; about calling `get' for effect.
- t)))
-
(defmacro cc-bytecomp-boundp (symbol)
"Return non-nil if the given symbol is bound as a variable outside
the compilation. This is the same as using `boundp' but additionally
=== modified file 'lisp/progmodes/cc-cmds.el'
--- lisp/progmodes/cc-cmds.el 2014-02-17 18:16:32 +0000
+++ lisp/progmodes/cc-cmds.el 2014-09-26 15:25:52 +0000
@@ -45,8 +45,11 @@
(cc-require 'cc-engine)
;; Silence the compiler.
+(cc-bytecomp-defun delete-forward-p) ; XEmacs
(cc-bytecomp-defvar filladapt-mode) ; c-fill-paragraph contains a kludge
; which looks at this.
+(cc-bytecomp-defun c-forward-subword)
+(cc-bytecomp-defun c-backward-subword)
\f
;; Indentation / Display syntax functions
(defvar c-fix-backslashes t)
@@ -258,9 +261,11 @@
"a" "")
(if c-hungry-delete-key "h" "")
(if (and
- ;; subword might not be loaded.
- (boundp 'subword-mode)
- (symbol-value 'subword-mode))
+ ;; (cc-)subword might not be loaded.
+ (boundp 'c-subword-mode)
+ (symbol-value 'c-subword-mode))
+ ;; FIXME: subword-mode already comes with its
+ ;; own lighter!
"w"
"")))
;; FIXME: Derived modes might want to use something else
@@ -936,8 +941,15 @@
;; do all cleanups and newline insertions if c-auto-newline is on.
(if (or (not c-auto-newline)
(not (looking-at "[ \t]*\\\\?$")))
- (if c-syntactic-indentation
- (c-indent-line))
+ (when c-syntactic-indentation
+ (let ((syntax (c-guess-basic-syntax)))
+ (c-indent-line syntax)
+ ;; Guard against the C hacker inserting a statement before a
+ ;; non-compound statement in an if/while/for.
+ (if (eq (caar syntax) 'substatement)
+ (save-excursion
+ (if (eq 0 (forward-line))
+ (c-indent-line))))))
;; clean ups: list-close-comma or defun-close-semi
(let ((pos (- (point-max) (point))))
(if (c-save-buffer-state ()
@@ -1090,7 +1102,7 @@
(interactive "*P")
(let ((c-echo-syntactic-information-p nil)
- final-pos close-paren-inserted found-delim case-fold-search)
+ final-pos found-delim case-fold-search)
(self-insert-command (prefix-numeric-value arg))
(setq final-pos (point))
@@ -1303,20 +1315,43 @@
(declare-function subword-forward "subword" (&optional arg))
(declare-function subword-backward "subword" (&optional arg))
+(cond
+ ((and (fboundp 'subword-mode) (not (fboundp 'c-subword-mode)))
+ ;; Recent Emacsen come with their own subword support. Use that.
+ (define-obsolete-function-alias 'c-subword-mode 'subword-mode "24.3")
+ (define-obsolete-variable-alias 'c-subword-mode 'subword-mode "24.3"))
+ (t
+ ;; Autoload directive for emacsen that doesn't have an older CC Mode
+ ;; version in the dist.
+ (autoload 'c-subword-mode "cc-subword"
+ "Mode enabling subword movement and editing keys." t)))
+
;; "nomenclature" functions + c-scope-operator.
(defun c-forward-into-nomenclature (&optional arg)
"Compatibility alias for `c-forward-subword'."
(interactive "p")
- (require 'subword)
- (subword-forward arg))
-(make-obsolete 'c-forward-into-nomenclature 'subword-forward "23.2")
+ (if (fboundp 'subword-mode)
+ (progn
+ (require 'subword)
+ (subword-forward arg))
+ (require 'cc-subword)
+ (c-forward-subword arg)))
+(make-obsolete 'c-forward-into-nomenclature
+ (if (fboundp 'subword-mode) 'subword-forward 'c-forward-subword)
+ "23.2")
(defun c-backward-into-nomenclature (&optional arg)
"Compatibility alias for `c-backward-subword'."
(interactive "p")
- (require 'subword)
- (subword-backward arg))
-(make-obsolete 'c-backward-into-nomenclature 'subword-backward "23.2")
+ (if (fboundp 'subword-mode)
+ (progn
+ (require 'subword)
+ (subword-backward arg))
+ (require 'cc-subword)
+ (c-forward-backword arg)))
+(make-obsolete
+ 'c-backward-into-nomenclature
+ (if (fboundp 'subword-mode) 'subword-backward 'c-backward-subword) "23.2")
(defun c-scope-operator ()
"Insert a double colon scope operator at point.
@@ -1408,18 +1443,20 @@
;; Kluge so that c-beginning-of-decl-1 won't go back if we're already
;; at a declaration.
(if (or (and (eolp) (not (eobp))) ; EOL is matched by "\\s>"
- (not (looking-at
-"\\([;#]\\|\\'\\|\\s(\\|\\s)\\|\\s\"\\|\\s\\\\|\\s$\\|\\s<\\|\\s>\\|\\s!\\)")))
+ (not (c-looking-at-non-alphnumspace)))
(forward-char))
(setq kluge-start (point))
(setq decl-result
(car (c-beginning-of-decl-1
;; NOTE: If we're in a K&R region, this might be the start
;; of a parameter declaration, not the actual function.
+ ;; It might also leave us at a label or "label" like
+ ;; "private:".
(and least-enclosing ; LIMIT for c-b-of-decl-1
(c-safe-position least-enclosing paren-state)))))
;; Has the declaration we've gone back to got braces?
+ (or (eq decl-result 'label)
(setq brace-decl-p
(save-excursion
(and (c-syntactic-re-search-forward "[;{]" nil t t)
@@ -1429,10 +1466,11 @@
;; ';' in a K&R argdecl. In
;; that case the declaration
;; should contain a block.
- (c-in-knr-argdecl))))))
+ (c-in-knr-argdecl)))))))
(cond
- ((= (point) kluge-start) ; might be BOB or unbalanced parens.
+ ((or (eq decl-result 'label) ; e.g. "private:" or invalid syntax.
+ (= (point) kluge-start)) ; might be BOB or unbalanced parens.
'outwith-function)
((eq decl-result 'same)
(if brace-decl-p
@@ -1808,7 +1846,7 @@
(looking-at c-symbol-key))
(match-string-no-properties 0))
- ((looking-at "DEFUN\\_>")
+ ((looking-at "DEFUN\\s-*(") ;"DEFUN\\_>") think of XEmacs!
;; DEFUN ("file-name-directory", Ffile_name_directory, Sfile_name_directory, ...) ==> Ffile_name_directory
;; DEFUN(POSIX::STREAM-LOCK, stream lockp &key BLOCK SHARED START LENGTH) ==> POSIX::STREAM-LOCK
(down-list 1)
@@ -2001,7 +2039,7 @@
(eq last-command 'c-mark-function)))
(push-mark-p (and (eq this-command 'c-mark-function)
(not extend-region-p)
- (not (and transient-mark-mode mark-active)))))
+ (not (c-region-is-active-p)))))
(if push-mark-p (push-mark (point)))
(if extend-region-p
(progn
@@ -3338,7 +3376,7 @@
starting on the current line.
Otherwise reindent just the current line."
(interactive
- (list current-prefix-arg (use-region-p)))
+ (list current-prefix-arg (c-region-is-active-p)))
(if region
(c-indent-region (region-beginning) (region-end))
(c-indent-command arg)))
=== modified file 'lisp/progmodes/cc-defs.el'
--- lisp/progmodes/cc-defs.el 2014-09-10 21:38:11 +0000
+++ lisp/progmodes/cc-defs.el 2014-09-26 15:12:06 +0000
@@ -48,12 +48,16 @@
;; Silence the compiler.
(cc-bytecomp-defvar c-enable-xemacs-performance-kludge-p) ; In cc-vars.el
+(cc-bytecomp-defun buffer-syntactic-context-depth) ; XEmacs
(cc-bytecomp-defun region-active-p) ; XEmacs
+(cc-bytecomp-defvar zmacs-region-stays) ; XEmacs
+(cc-bytecomp-defvar zmacs-regions) ; XEmacs
(cc-bytecomp-defvar mark-active) ; Emacs
(cc-bytecomp-defvar deactivate-mark) ; Emacs
(cc-bytecomp-defvar inhibit-point-motion-hooks) ; Emacs
(cc-bytecomp-defvar parse-sexp-lookup-properties) ; Emacs
(cc-bytecomp-defvar text-property-default-nonsticky) ; Emacs 21
+(cc-bytecomp-defvar lookup-syntax-properties) ; XEmacs
(cc-bytecomp-defun string-to-syntax) ; Emacs 21
\f
@@ -64,15 +68,14 @@
(not (fboundp 'push)))
(cc-load "cc-fix")))
-; (eval-after-load "font-lock" ; 2006-07-09. font-lock is now preloaded
-; '
-(if (and (featurep 'xemacs) ; There is now (2005/12) code in GNU Emacs CVS
+(when (featurep 'xemacs) ; There is now (2005/12) code in GNU Emacs CVS
; to make the call to f-l-c-k throw an error.
- (not (featurep 'cc-fix)) ; only load the file once.
+ (eval-after-load "font-lock"
+ '(if (and (not (featurep 'cc-fix)) ; only load the file once.
(let (font-lock-keywords)
(font-lock-compile-keywords '("\\<\\>"))
font-lock-keywords)) ; did the previous call foul this up?
- (load "cc-fix")) ;)
+ (load "cc-fix"))))
;; The above takes care of the delayed loading, but this is necessary
;; to ensure correct byte compilation.
@@ -86,10 +89,15 @@
font-lock-keywords)))
(cc-load "cc-fix")))
+;; XEmacs 21.4 doesn't have `delete-dups'.
+(eval-and-compile
+ (if (and (not (fboundp 'delete-dups))
+ (not (featurep 'cc-fix)))
+ (cc-load "cc-fix")))
\f
;;; Variables also used at compile time.
-(defconst c-version "5.32.5"
+(defconst c-version "5.33"
"CC Mode version number.")
(defconst c-version-sym (intern c-version))
@@ -169,6 +177,10 @@
(put 'cc-eval-when-compile 'lisp-indent-hook 0))
+(eval-and-compile
+ (defalias 'c--macroexpand-all
+ (if (fboundp 'macroexpand-all)
+ 'macroexpand-all 'cl-macroexpand-all)))
\f
;;; Macros.
@@ -327,21 +339,28 @@
(t (error "Unknown buffer position requested: %s" position))))
(point))))
+(defmacro c-next-single-property-change (position prop &optional object limit)
+ ;; See the doc string for either of the defuns expanded to.
+ (if (and (featurep 'xemacs)
+ (fboundp 'next-single-char-property-change))
+ ;; XEmacs >= 2005-01-25
+ `(next-single-char-property-change ,position ,prop ,object ,limit)
+ ;; Emacs and earlier XEmacs
+ `(next-single-property-change ,position ,prop ,object ,limit)))
+
(defmacro c-region-is-active-p ()
;; Return t when the region is active. The determination of region
;; activeness is different in both Emacs and XEmacs.
- ;; FIXME? Emacs has region-active-p since 23.1, so maybe this test
- ;; should be updated.
- (if (cc-bytecomp-boundp 'mark-active)
- ;; Emacs.
- 'mark-active
+ (if (cc-bytecomp-fboundp 'region-active-p)
;; XEmacs.
- '(region-active-p)))
+ '(region-active-p)
+ ;; Old Emacs.
+ 'mark-active))
(defmacro c-set-region-active (activate)
;; Activate the region if ACTIVE is non-nil, deactivate it
;; otherwise. Covers the differences between Emacs and XEmacs.
- (if (fboundp 'zmacs-activate-region)
+ (if (cc-bytecomp-fboundp 'zmacs-activate-region)
;; XEmacs.
`(if ,activate
(zmacs-activate-region)
@@ -438,6 +457,7 @@
(put 'c-save-buffer-state 'lisp-indent-function 1)
(defmacro c-tentative-buffer-changes (&rest body)
+ ;; FIXME: Use atomic-change-group!
"Eval BODY and optionally restore the buffer contents to the state it
was in before BODY. Any changes are kept if the last form in BODY
returns non-nil. Otherwise it's undone using the undo facility, and
@@ -705,9 +725,9 @@
;; `c-parse-state'.
`(progn
- (if (and ,(fboundp 'buffer-syntactic-context-depth)
+ (if (and ,(cc-bytecomp-fboundp 'buffer-syntactic-context-depth)
c-enable-xemacs-performance-kludge-p)
- ,(when (fboundp 'buffer-syntactic-context-depth)
+ ,(when (cc-bytecomp-fboundp 'buffer-syntactic-context-depth)
;; XEmacs only. This can improve the performance of
;; c-parse-state to between 3 and 60 times faster when
;; braces are hung. It can also degrade performance by
@@ -913,6 +933,12 @@
(cc-bytecomp-fboundp 'delete-extent)
(cc-bytecomp-fboundp 'map-extents))))
+(defconst c-<-as-paren-syntax '(4 . ?>))
+(put 'c-<-as-paren-syntax 'syntax-table c-<-as-paren-syntax)
+
+(defconst c->-as-paren-syntax '(5 . ?<))
+(put 'c->-as-paren-syntax 'syntax-table c->-as-paren-syntax)
+
;; `c-put-char-property' is complex enough in XEmacs and Emacs < 21 to
;; make it a function.
(defalias 'c-put-char-property-fun
@@ -966,6 +992,21 @@
`(let ((-pos- ,pos))
(put-text-property -pos- (1+ -pos-) ',property ,value))))
+(eval-and-compile
+ ;; Constant to decide at compilation time whether to use category
+ ;; properties. Currently (2010-03) they're available only on GNU Emacs.
+ (defconst c-use-category
+ (with-temp-buffer
+ (let ((parse-sexp-lookup-properties t)
+ (lookup-syntax-properties t))
+ (set-syntax-table (make-syntax-table))
+ (insert "<()>")
+ (c-put-char-property (point-min) 'category 'c-<-as-paren-syntax)
+ (c-put-char-property (+ 3 (point-min)) 'category 'c->-as-paren-syntax)
+ (goto-char (point-min))
+ (forward-sexp)
+ (= (point) (+ 4 (point-min)))))))
+
(defmacro c-get-char-property (pos property)
;; Get the value of the given property on the character at POS if
;; it's been put there by `c-put-char-property'. PROPERTY is
@@ -1046,8 +1087,8 @@
(while
(and
(< place ,(or limit '(point-max)))
- (not (equal (get-text-property place ,property) ,value)))
- (setq place (next-single-property-change
+ (not (equal (c-get-char-property place ,property) ,value)))
+ (setq place (c-next-single-property-change
place ,property nil ,(or limit '(point-max)))))
(when (< place ,(or limit '(point-max)))
(goto-char place)
@@ -1065,10 +1106,15 @@
(while
(and
(> place ,(or limit '(point-min)))
- (not (equal (get-text-property (1- place) ,property) ,value)))
- (setq place (previous-single-property-change
+ (not (equal (c-get-char-property (1- place) ,property) ,value)))
+ (setq place (,(if (and (featurep 'xemacs)
+ (fboundp 'previous-single-char-property-change))
+ ;; XEmacs > 2005-01-25.
+ 'previous-single-char-property-change
+ ;; Emacs and earlier XEmacs.
+ 'previous-single-property-change)
place ,property nil ,(or limit '(point-min)))))
- (when (> place ,(or limit '(point-max)))
+ (when (> place ,(or limit '(point-min)))
(goto-char place)
(search-backward-regexp ".") ; to set the match-data.
(point))))
@@ -1085,9 +1131,9 @@
(and
(< place to)
(not (equal (get-text-property place property) value)))
- (setq place (next-single-property-change place property nil to)))
+ (setq place (c-next-single-property-change place property nil to)))
(< place to))
- (setq end-place (next-single-property-change place property nil to))
+ (setq end-place (c-next-single-property-change place property nil to))
(remove-text-properties place end-place (cons property nil))
;; Do we have to do anything with stickiness here?
(setq place end-place))))
@@ -1104,7 +1150,7 @@
(if (equal (extent-property ext -property-) val)
(delete-extent ext)))
nil ,from ,to ,value nil -property-))
- ;; Gnu Emacs
+ ;; GNU Emacs
`(c-clear-char-property-with-value-function ,from ,to ,property ,value)))
\f
;; Macros to put overlays (Emacs) or extents (XEmacs) on buffer text.
@@ -1188,42 +1234,43 @@
(if (< (point) start)
(goto-char (point-max)))))
-(defconst c-<-as-paren-syntax '(4 . ?>))
-(put 'c-<-as-paren-syntax 'syntax-table c-<-as-paren-syntax)
-
-(defsubst c-mark-<-as-paren (pos)
+(defmacro c-mark-<-as-paren (pos)
;; Mark the "<" character at POS as a template opener using the
- ;; `syntax-table' property via the `category' property.
+ ;; `syntax-table' property either directly (XEmacs) or via a `category'
+ ;; property (GNU Emacs).
;;
;; This function does a hidden buffer change. Note that we use
;; indirection through the `category' text property. This allows us to
;; toggle the property in all template brackets simultaneously and
;; cheaply. We use this, for instance, in `c-parse-state'.
- (c-put-char-property pos 'category 'c-<-as-paren-syntax))
-
-(defconst c->-as-paren-syntax '(5 . ?<))
-(put 'c->-as-paren-syntax 'syntax-table c->-as-paren-syntax)
-
-(defsubst c-mark->-as-paren (pos)
+ (if c-use-category
+ `(c-put-char-property ,pos 'category 'c-<-as-paren-syntax)
+ `(c-put-char-property ,pos 'syntax-table c-<-as-paren-syntax)))
+
+
+(defmacro c-mark->-as-paren (pos)
;; Mark the ">" character at POS as an sexp list closer using the
- ;; syntax-table property.
+ ;; `syntax-table' property either directly (XEmacs) or via a `category'
+ ;; property (GNU Emacs).
;;
;; This function does a hidden buffer change. Note that we use
;; indirection through the `category' text property. This allows us to
;; toggle the property in all template brackets simultaneously and
;; cheaply. We use this, for instance, in `c-parse-state'.
- (c-put-char-property pos 'category 'c->-as-paren-syntax))
+ (if c-use-category
+ `(c-put-char-property ,pos 'category 'c->-as-paren-syntax)
+ `(c-put-char-property ,pos 'syntax-table c->-as-paren-syntax)))
-(defsubst c-unmark-<->-as-paren (pos)
- ;; Unmark the "<" or "<" character at POS as an sexp list opener using
- ;; the syntax-table property indirectly through the `category' text
- ;; property.
+(defmacro c-unmark-<->-as-paren (pos)
+ ;; Unmark the "<" or "<" character at POS as an sexp list opener using the
+ ;; `syntax-table' property either directly or indirectly through a
+ ;; `category' text property.
;;
- ;; This function does a hidden buffer change. Note that we use
+ ;; This function does a hidden buffer change. Note that we try to use
;; indirection through the `category' text property. This allows us to
;; toggle the property in all template brackets simultaneously and
;; cheaply. We use this, for instance, in `c-parse-state'.
- (c-clear-char-property pos 'category))
+ `(c-clear-char-property ,pos ,(if c-use-category ''category ''syntax-table)))
(defsubst c-suppress-<->-as-parens ()
;; Suppress the syntactic effect of all marked < and > as parens. Note
@@ -1304,6 +1351,122 @@
(widen)
(c-set-cpp-delimiters ,beg ,end)))))
\f
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; The following macros are to be used only in `c-parse-state' and its
+;; subroutines. Their main purpose is to simplify the handling of C++/Java
+;; template delimiters and CPP macros. In GNU Emacs, this is done slickly by
+;; the judicious use of 'category properties. These don't exist in XEmacs.
+;;
+;; Note: in the following macros, there is no special handling for parentheses
+;; inside CPP constructs. That is because CPPs are always syntactically
+;; balanced, thanks to `c-neutralize-CPP-line' in cc-mode.el.
+(defmacro c-sc-scan-lists-no-category+1+1 (from)
+ ;; Do a (scan-lists FROM 1 1). Any finishing position which either (i) is
+ ;; determined by and angle bracket; or (ii) is inside a macro whose start
+ ;; isn't POINT-MACRO-START doesn't count as a finishing position.
+ `(let ((here (point))
+ (pos (scan-lists ,from 1 1)))
+ (while (eq (char-before pos) ?>)
+ (setq pos (scan-lists pos 1 1)))
+ pos))
+
+(defmacro c-sc-scan-lists-no-category+1-1 (from)
+ ;; Do a (scan-lists FROM 1 -1). Any finishing position which either (i) is
+ ;; determined by an angle bracket; or (ii) is inside a macro whose start
+ ;; isn't POINT-MACRO-START doesn't count as a finishing position.
+ `(let ((here (point))
+ (pos (scan-lists ,from 1 -1)))
+ (while (eq (char-before pos) ?<)
+ (setq pos (scan-lists pos 1 1))
+ (setq pos (scan-lists pos 1 -1)))
+ pos))
+
+(defmacro c-sc-scan-lists-no-category-1+1 (from)
+ ;; Do a (scan-lists FROM -1 1). Any finishing position which either (i) is
+ ;; determined by and angle bracket; or (ii) is inside a macro whose start
+ ;; isn't POINT-MACRO-START doesn't count as a finishing position.
+ `(let ((here (point))
+ (pos (scan-lists ,from -1 1)))
+ (while (eq (char-after pos) ?<)
+ (setq pos (scan-lists pos -1 1)))
+ pos))
+
+(defmacro c-sc-scan-lists-no-category-1-1 (from)
+ ;; Do a (scan-lists FROM -1 -1). Any finishing position which either (i) is
+ ;; determined by and angle bracket; or (ii) is inside a macro whose start
+ ;; isn't POINT-MACRO-START doesn't count as a finishing position.
+ `(let ((here (point))
+ (pos (scan-lists ,from -1 -1)))
+ (while (eq (char-after pos) ?>)
+ (setq pos (scan-lists pos -1 1))
+ (setq pos (scan-lists pos -1 -1)))
+ pos))
+
+(defmacro c-sc-scan-lists (from count depth)
+ (if c-use-category
+ `(scan-lists ,from ,count ,depth)
+ (cond
+ ((and (eq count 1) (eq depth 1))
+ `(c-sc-scan-lists-no-category+1+1 ,from))
+ ((and (eq count 1) (eq depth -1))
+ `(c-sc-scan-lists-no-category+1-1 ,from))
+ ((and (eq count -1) (eq depth 1))
+ `(c-sc-scan-lists-no-category-1+1 ,from))
+ ((and (eq count -1) (eq depth -1))
+ `(c-sc-scan-lists-no-category-1-1 ,from))
+ (t (error "Invalid parameter(s) to c-sc-scan-lists")))))
+
+
+(defun c-sc-parse-partial-sexp-no-category (from to targetdepth stopbefore
+ oldstate)
+ ;; Do a parse-partial-sexp using the supplied arguments, disregarding
+ ;; template/generic delimiters < > and disregarding macros other than the
+ ;; one at POINT-MACRO-START.
+ ;;
+ ;; NOTE that STOPBEFORE must be nil. TARGETDEPTH should be one less than
+ ;; the depth in OLDSTATE. This function is thus a SPECIAL PURPOSE variation
+ ;; on parse-partial-sexp, designed for calling from
+ ;; `c-remove-stale-state-cache'.
+ ;;
+ ;; Any finishing position which is determined by an angle bracket delimiter
+ ;; doesn't count as a finishing position.
+ ;;
+ ;; Note there is no special handling of CPP constructs here, since these are
+ ;; always syntactically balanced (thanks to `c-neutralize-CPP-line').
+ (let ((state
+ (parse-partial-sexp from to targetdepth stopbefore oldstate)))
+ (while
+ (and (< (point) to)
+ ;; We must have hit targetdepth.
+ (or (eq (char-before) ?<)
+ (eq (char-before) ?>)))
+ (setcar state
+ (if (memq (char-before) '(?> ?\) ?\} ?\]))
+ (1+ (car state))
+ (1- (car state))))
+ (setq state
+ (parse-partial-sexp (point) to targetdepth stopbefore oldstate)))
+ state))
+
+(defmacro c-sc-parse-partial-sexp (from to &optional targetdepth stopbefore
+ oldstate)
+ (if c-use-category
+ `(parse-partial-sexp ,from ,to ,targetdepth ,stopbefore ,oldstate)
+ `(c-sc-parse-partial-sexp-no-category ,from ,to ,targetdepth ,stopbefore
+ ,oldstate)))
+
+\f
+(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.
+
+\f
(defsubst c-intersect-lists (list alist)
;; return the element of ALIST that matches the first element found
;; in LIST. Uses assq.
@@ -1419,8 +1582,8 @@
(defun c-make-keywords-re (adorn list &optional mode)
"Make a regexp that matches all the strings the list.
-Duplicates and nil elements in the list are removed. The resulting
-regexp may contain zero or more submatch expressions.
+Duplicates and nil elements in the list are removed. The
+resulting regexp may contain zero or more submatch expressions.
If ADORN is t there will be at least one submatch and the first
surrounds the matched alternative, and the regexp will also not match
@@ -1438,11 +1601,7 @@
when it's needed. The default is the current language taken from
`c-buffer-is-cc-mode'."
- (let (unique)
- (dolist (elt list)
- (unless (member elt unique)
- (push elt unique)))
- (setq list (delete nil unique)))
+ (setq list (delete nil (delete-dups list)))
(if list
(let (re)
@@ -1556,7 +1715,11 @@
(cc-bytecomp-defvar open-paren-in-column-0-is-defun-start)
-(defvar lookup-syntax-properties) ;XEmacs.
+(defalias 'c--make-local-hook
+ (let ((tmphook (make-symbol "tmphook")))
+ ;; Check if `add-hook' makes the hook buffer-local.
+ (add-hook tmphook 'foo nil t)
+ (if (local-variable-p tmphook) 'ignore 'make-local-hook)))
(defconst c-emacs-features
(let (list)
@@ -1609,6 +1772,9 @@
(not (end-of-defun))))
(setq list (cons 'argumentative-bod-function list))))
+ ;; Record whether the `category' text property works.
+ (if c-use-category (setq list (cons 'category-properties list)))
+
(let ((buf (generate-new-buffer " test"))
parse-sexp-lookup-properties
parse-sexp-ignore-comments
@@ -1638,13 +1804,13 @@
"support for the `syntax-table' text property "
"is required.")))
- ;; Find out if generic comment delimiters work.
+ ;; Find out if "\\s!" (generic comment delimiters) work.
(c-safe
(modify-syntax-entry ?x "!")
(if (string-match "\\s!" "x")
(setq list (cons 'gen-comment-delim list))))
- ;; Find out if generic string delimiters work.
+ ;; Find out if "\\s|" (generic string delimiters) work.
(c-safe
(modify-syntax-entry ?x "|")
(if (string-match "\\s|" "x")
@@ -1691,7 +1857,8 @@
(kill-buffer buf))
;; See if `parse-partial-sexp' returns the eighth element.
- (if (c-safe (>= (length (save-excursion (parse-partial-sexp (point) (point))))
+ (if (c-safe (>= (length (save-excursion
+ (parse-partial-sexp (point) (point))))
10))
(setq list (cons 'pps-extended-state list))
(error (concat
@@ -1707,13 +1874,14 @@
'8-bit 8 bit syntax entry flags (XEmacs style).
'1-bit 1 bit syntax entry flags (Emacs style).
-'argumentative-bod-function beginning-of-defun passes ARG through
- to a non-null beginning-of-defun-function. It is assumed
- the end-of-defun does the same thing.
+'argumentative-bod-function beginning-of-defun and end-of-defun pass
+ ARG through to beginning/end-of-defun-function.
'syntax-properties It works to override the syntax for specific characters
in the buffer with the 'syntax-table property. It's
always set - CC Mode no longer works in emacsen without
this feature.
+'category-properties Syntax routines can add a level of indirection to text
+ properties using the 'category property.
'gen-comment-delim Generic comment delimiters work
(i.e. the syntax class `!').
'gen-string-delim Generic string delimiters work
@@ -1803,18 +1971,18 @@
(error "Unknown base mode `%s'" base-mode))
(put mode 'c-fallback-mode base-mode))
-(defvar c-lang-constants (make-vector 151 0)
- "Obarray used as a cache to keep track of the language constants.
-The constants stored are those defined by `c-lang-defconst' and the values
-computed by `c-lang-const'. It's mostly used at compile time but it's not
-stored in compiled files.
+(defvar c-lang-constants (make-vector 151 0))
+;; Obarray used as a cache to keep track of the language constants.
+;; The constants stored are those defined by `c-lang-defconst' and the values
+;; computed by `c-lang-const'. It's mostly used at compile time but it's not
+;; stored in compiled files.
-The obarray contains all the language constants as symbols. The
-value cells hold the evaluated values as alists where each car is
-the mode name symbol and the corresponding cdr is the evaluated
-value in that mode. The property lists hold the source definitions
-and other miscellaneous data. The obarray might also contain
-various other symbols, but those don't have any variable bindings.")
+;; The obarray contains all the language constants as symbols. The
+;; value cells hold the evaluated values as alists where each car is
+;; the mode name symbol and the corresponding cdr is the evaluated
+;; value in that mode. The property lists hold the source definitions
+;; and other miscellaneous data. The obarray might also contain
+;; various other symbols, but those don't have any variable bindings.
(defvar c-lang-const-expansion nil)
@@ -1831,7 +1999,9 @@
(t
;; Being evaluated interactively.
(buffer-file-name)))))
- (and file (file-name-base file))))
+ (and file
+ (file-name-sans-extension
+ (file-name-nondirectory file)))))
(defmacro c-lang-defconst-eval-immediately (form)
"Can be used inside a VAL in `c-lang-defconst' to evaluate FORM
@@ -1945,7 +2115,7 @@
;; reason, but we also use this expansion handle
;; `c-lang-defconst-eval-immediately' and to register
;; dependencies on the `c-lang-const's in VAL.)
- (setq val (macroexpand-all val))
+ (setq val (c--macroexpand-all val))
(setq bindings `(cons (cons ',assigned-mode (lambda () ,val)) ,bindings)
args (cdr args))))
@@ -1963,10 +2133,9 @@
,@(and pre-files `(',pre-files))))))
(put 'c-lang-defconst 'lisp-indent-function 1)
-;(eval-after-load "edebug" ; 2006-07-09: def-edebug-spec is now in subr.el.
-; '
-(def-edebug-spec c-lang-defconst
- (&define name [&optional stringp] [&rest sexp def-form]))
+(eval-after-load "edebug"
+ '(def-edebug-spec c-lang-defconst
+ (&define name [&optional stringp] [&rest sexp def-form])))
(defun c-define-lang-constant (name bindings &optional pre-files)
;; Used by `c-lang-defconst'.
=== modified file 'lisp/progmodes/cc-engine.el'
--- lisp/progmodes/cc-engine.el 2014-09-11 19:44:25 +0000
+++ lisp/progmodes/cc-engine.el 2014-09-25 20:11:21 +0000
@@ -147,18 +147,24 @@
(cc-require-when-compile 'cc-langs)
(cc-require 'cc-vars)
+(eval-when-compile (require 'cl))
+
+;; Silence the compiler.
+(cc-bytecomp-defun buffer-syntactic-context) ; XEmacs
+(cc-bytecomp-defun c-fontify-recorded-types-and-refs)
+(cc-bytecomp-defvar c-maybe-stale-found-type)
+
\f
;; Make declarations for all the `c-lang-defvar' variables in cc-langs.
(defmacro c-declare-lang-variables ()
`(progn
- ,@(apply 'nconc
- (mapcar (lambda (init)
- `(,(if (elt init 2)
- `(defvar ,(car init) nil ,(elt init 2))
- `(defvar ,(car init) nil))
- (make-variable-buffer-local ',(car init))))
- (cdr c-lang-variable-inits)))))
+ ,@(mapcan (lambda (init)
+ `(,(if (elt init 2)
+ `(defvar ,(car init) nil ,(elt init 2))
+ `(defvar ,(car init) nil))
+ (make-variable-buffer-local ',(car init))))
+ (cdr c-lang-variable-inits))))
(c-declare-lang-variables)
\f
@@ -514,7 +520,7 @@
(while (progn
(when (eq (get-text-property (point) 'c-type) value)
(c-clear-char-property (point) 'c-type))
- (goto-char (next-single-property-change (point) 'c-type nil to))
+ (goto-char (c-next-single-property-change (point) 'c-type nil to))
(< (point) to)))))
\f
@@ -826,7 +832,6 @@
;; Record this as the first token if not starting inside it.
(setq tok start))
-
;; The following while loop goes back one sexp (balanced parens,
;; etc. with contents, or symbol or suchlike) each iteration. This
;; movement is accomplished with a call to c-backward-sexp approx 170
@@ -1370,8 +1375,9 @@
;; Emacs includes the ending newline in a b-style (c++)
;; comment, but XEmacs doesn't. We depend on the Emacs
;; behavior (which also is symmetric).
- (if (and (eolp) (elt (parse-partial-sexp start (point)) 7))
- (condition-case nil (forward-char 1)))
+ (when (featurep 'xemacs)
+ (if (and (eolp) (elt (parse-partial-sexp start (point)) 7))
+ (condition-case nil (forward-char 1))))
t))))
@@ -1704,7 +1710,7 @@
;; the cases when the marked rung is complete.
;; (`next-single-property-change' is certain to move at least one
;; step forward.)
- (setq rung-pos (1- (next-single-property-change
+ (setq rung-pos (1- (c-next-single-property-change
rung-is-marked 'c-is-sws nil rung-end-pos)))
;; Got no marked rung here. Since the simple ws might have started
;; inside a line comment or cpp directive we must set `rung-pos' as
@@ -1720,7 +1726,7 @@
;; The following search is the main reason that `c-in-sws'
;; and `c-is-sws' aren't combined to one property.
- (goto-char (next-single-property-change
+ (goto-char (c-next-single-property-change
(point) 'c-in-sws nil (point-max)))
(unless (get-text-property (point) 'c-is-sws)
;; If the `c-in-sws' region extended past the last
@@ -1842,7 +1848,7 @@
;; possible since we can't be in the ending ws of a line comment or
;; cpp directive now.
(if (setq rung-is-marked next-rung-is-marked)
- (setq rung-pos (1- (next-single-property-change
+ (setq rung-pos (1- (c-next-single-property-change
rung-is-marked 'c-is-sws nil rung-end-pos)))
(setq rung-pos next-rung-pos))
(setq safe-start t)))
@@ -1920,7 +1926,7 @@
(unless (get-text-property (point) 'c-is-sws)
;; If the `c-in-sws' region extended past the first
;; `c-is-sws' char we have to go forward a bit.
- (goto-char (next-single-property-change
+ (goto-char (c-next-single-property-change
(point) 'c-is-sws)))
(c-debug-sws-msg
@@ -2159,7 +2165,6 @@
;; the middle of the desert, as long as it is not within a brace pair
;; recorded in `c-state-cache' or a paren/bracket pair.
-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; We maintain a simple cache of positions which aren't in a literal, so as to
;; speed up testing for non-literality.
@@ -2530,7 +2535,7 @@
(setq pos here+)
(c-safe
(while
- (setq ren+1 (scan-lists pos 1 1)) ; might signal
+ (setq ren+1 (c-sc-scan-lists pos 1 1)) ; might signal
(setq lonely-rens (cons ren+1 lonely-rens)
pos ren+1)))))
@@ -2542,7 +2547,7 @@
(c-safe
(while
(and lonely-rens ; actual values aren't used.
- (setq pa (scan-lists pos -1 1)))
+ (setq pa (c-sc-scan-lists pos -1 1)))
(setq pos pa)
(setq lonely-rens (cdr lonely-rens)))))
pos))
@@ -2698,8 +2703,8 @@
(progn
(c-safe
(while
- (and (setq ce (scan-lists bra -1 -1)) ; back past )/]/}; might signal
- (setq bra (scan-lists ce -1 1)) ; back past (/[/{; might signal
+ (and (setq ce (c-sc-scan-lists bra -1 -1)) ; back past )/]/}; might signal
+ (setq bra (c-sc-scan-lists ce -1 1)) ; back past (/[/{; might signal
(or (> bra here) ;(> ce here)
(and
(< ce here)
@@ -2751,7 +2756,7 @@
(not (c-beginning-of-macro))))
(setq c-state-cache
(cons (cons (1- bra+1)
- (scan-lists bra+1 1 1))
+ (c-sc-scan-lists bra+1 1 1))
(if (consp (car c-state-cache))
(cdr c-state-cache)
c-state-cache)))
@@ -2780,7 +2785,7 @@
paren+1 ; Pos after some opening or closing paren.
paren+1s ; A list of `paren+1's; used to determine a
; good-pos.
- bra+1 ce+1 ; just after L/R bra-ces.
+ bra+1 ; just after L bra-ce.
bra+1s ; list of OLD values of bra+1.
mstart) ; start of a macro.
@@ -2801,9 +2806,9 @@
;; are no more b/b/p's to scan.
(c-safe
(while t
- (setq pa+1 (scan-lists ren+1 1 -1) ; Into (/{/[; might signal
+ (setq pa+1 (c-sc-scan-lists ren+1 1 -1) ; Into (/{/[; might signal
paren+1s (cons pa+1 paren+1s))
- (setq ren+1 (scan-lists pa+1 1 1)) ; Out of )/}/]; might signal
+ (setq ren+1 (c-sc-scan-lists pa+1 1 1)) ; Out of )/}/]; might signal
(if (and (eq (char-before pa+1) ?{)) ; Check for a macro later.
(setq bra+1 pa+1))
(setcar paren+1s ren+1)))
@@ -2827,7 +2832,7 @@
;; finished - we just need to check for having found an
;; unmatched )/}/], which we ignore. Such a )/}/] can't be in a
;; macro, due the action of `c-neutralize-syntax-in-CPP'.
- (c-safe (setq ren+1 (scan-lists ren+1 1 1)))))) ; acts as loop control.
+ (c-safe (setq ren+1 (c-sc-scan-lists ren+1 1 1)))))) ; acts as loop control.
;; Record the final, innermost, brace-pair if there is one.
(c-state-push-any-brace-pair bra+1 macro-start-or-here)
@@ -2954,7 +2959,7 @@
;; Scan!
(setq pps-state
- (parse-partial-sexp
+ (c-sc-parse-partial-sexp
(point) (if (< (point) pps-point) pps-point here)
target-depth
nil pps-state))
@@ -2985,9 +2990,10 @@
)))
(if (< (point) pps-point)
- (setq pps-state (parse-partial-sexp (point) pps-point
- nil nil ; TARGETDEPTH, STOPBEFORE
- pps-state)))
+ (setq pps-state (c-sc-parse-partial-sexp
+ (point) pps-point
+ nil nil ; TARGETDEPTH, STOPBEFORE
+ pps-state)))
;; If the last paren pair we moved out of was actually a brace pair,
;; insert it into `c-state-cache'.
@@ -3108,12 +3114,15 @@
(save-restriction
(narrow-to-region here-bol (point-max))
(setq pos here-lit-start)
- (c-safe (while (setq pa (scan-lists pos -1 1))
+ (c-safe (while (setq pa (c-sc-scan-lists pos -1 1))
(setq pos pa)))) ; might signal
nil)) ; for the cond
- ((setq ren (c-safe-scan-lists pos -1 -1 too-far-back))
- ;; CASE 3: After a }/)/] before `here''s BOL.
+ ((save-restriction
+ (narrow-to-region too-far-back (point-max))
+ (setq ren (c-safe (c-sc-scan-lists pos -1 -1))))
+
+ ;; CASE 3: After a }/)/] before `here''s BOL.
(list (1+ ren) (and dropped-cons pos) nil)) ; Return value
(t
@@ -3335,15 +3344,19 @@
;; of all parens in preprocessor constructs, except for any such construct
;; containing point. We can then call `c-invalidate-state-cache-1' without
;; worrying further about macros and template delimiters.
- (c-with-<->-as-parens-suppressed
- (if (and c-state-old-cpp-beg
- (< c-state-old-cpp-beg here))
- (c-with-all-but-one-cpps-commented-out
- c-state-old-cpp-beg
- (min c-state-old-cpp-end here)
- (c-invalidate-state-cache-1 here))
- (c-with-cpps-commented-out
- (c-invalidate-state-cache-1 here)))))
+ (if (eval-when-compile (memq 'category-properties c-emacs-features))
+ ;; Emacs
+ (c-with-<->-as-parens-suppressed
+ (if (and c-state-old-cpp-beg
+ (< c-state-old-cpp-beg here))
+ (c-with-all-but-one-cpps-commented-out
+ c-state-old-cpp-beg
+ (min c-state-old-cpp-end here)
+ (c-invalidate-state-cache-1 here))
+ (c-with-cpps-commented-out
+ (c-invalidate-state-cache-1 here))))
+ ;; XEmacs
+ (c-invalidate-state-cache-1 here)))
(defmacro c-state-maybe-marker (place marker)
;; If PLACE is non-nil, return a marker marking it, otherwise nil.
@@ -3371,13 +3384,17 @@
;; FIXME!!! Put in a `condition-case' here to protect the integrity of the
;; subsystem.
(prog1
- (c-with-<->-as-parens-suppressed
- (if (and here-cpp-beg (> here-cpp-end here-cpp-beg))
- (c-with-all-but-one-cpps-commented-out
- here-cpp-beg here-cpp-end
- (c-parse-state-1))
- (c-with-cpps-commented-out
- (c-parse-state-1))))
+ (if (eval-when-compile (memq 'category-properties c-emacs-features))
+ ;; Emacs
+ (c-with-<->-as-parens-suppressed
+ (if (and here-cpp-beg (> here-cpp-end here-cpp-beg))
+ (c-with-all-but-one-cpps-commented-out
+ here-cpp-beg here-cpp-end
+ (c-parse-state-1))
+ (c-with-cpps-commented-out
+ (c-parse-state-1))))
+ ;; XEmacs
+ (c-parse-state-1))
(setq c-state-old-cpp-beg
(c-state-maybe-marker here-cpp-beg c-state-old-cpp-beg-marker)
c-state-old-cpp-end
@@ -3392,6 +3409,7 @@
(defvar c-parse-state-point nil)
(defvar c-parse-state-state nil)
+(make-variable-buffer-local 'c-parse-state-state)
(defun c-record-parse-state-state ()
(setq c-parse-state-point (point))
(setq c-parse-state-state
@@ -3399,9 +3417,9 @@
(lambda (arg)
(let ((val (symbol-value arg)))
(cons arg
- (if (consp val)
- (copy-tree val)
- val))))
+ (cond ((consp val) (copy-tree val))
+ ((markerp val) (copy-marker val))
+ (t val)))))
'(c-state-cache
c-state-cache-good-pos
c-state-nonlit-pos-cache
@@ -3421,7 +3439,11 @@
(concat "(setq "
(mapconcat
(lambda (arg)
- (format "%s %s%s" (car arg) (if (atom (cdr arg)) "" "'") (cdr arg)))
+ (format "%s %s%s" (car arg)
+ (if (atom (cdr arg)) "" "'")
+ (if (markerp (cdr arg))
+ (format "(copy-marker %s)" (marker-position (cdr arg)))
+ (cdr arg))))
c-parse-state-state " ")
")")))
@@ -4156,8 +4178,7 @@
(goto-char bound))
nil)))
-(defvar safe-pos-list) ; bound in c-syntactic-skip-backward
-
+(cc-bytecomp-defvar safe-pos-list) ; bound in c-syntactic-skip-backward
(defsubst c-ssb-lit-begin ()
;; Return the start of the literal point is in, or nil.
;; We read and write the variables `safe-pos', `safe-pos-list', `state'
@@ -4166,7 +4187,7 @@
;; Use `parse-partial-sexp' from a safe position down to the point to check
;; if it's outside comments and strings.
(save-excursion
- (let ((pos (point)) safe-pos state pps-end-pos)
+ (let ((pos (point)) safe-pos state)
;; Pick a safe position as close to the point as possible.
;;
;; FIXME: Consult `syntax-ppss' here if our cache doesn't give a good
@@ -4765,7 +4786,7 @@
(unless cfd-prop-match
(save-excursion
(while (progn
- (goto-char (next-single-property-change
+ (goto-char (c-next-single-property-change
(point) 'c-type nil cfd-limit))
(and (< (point) cfd-limit)
(not (eq (c-get-char-property (1- (point)) 'c-type)
@@ -4805,7 +4826,7 @@
;; Pseudo match inside a comment or string literal. Skip out
;; of comments and string literals.
(while (progn
- (goto-char (next-single-property-change
+ (goto-char (c-next-single-property-change
(point) 'face nil cfd-limit))
(and (< (point) cfd-limit)
(c-got-face-at (point) c-literal-faces))))
@@ -4860,14 +4881,17 @@
;; it should return non-nil to ensure that the next search will find them.
;;
;; Such a spot is:
- ;; o The first token after bob.
- ;; o The first token after the end of submatch 1 in
- ;; `c-decl-prefix-or-start-re' when that submatch matches.
- ;; o The start of each `c-decl-prefix-or-start-re' match when
- ;; submatch 1 doesn't match.
- ;; o The first token after the end of each occurrence of the
- ;; `c-type' text property with the value `c-decl-end', provided
- ;; `c-type-decl-end-used' is set.
+ ;; o The first token after bob.
+ ;; o The first token after the end of submatch 1 in
+ ;; `c-decl-prefix-or-start-re' when that submatch matches. This
+ ;; submatch is typically a (L or R) brace or paren, a ;, or a ,.
+ ;; o The start of each `c-decl-prefix-or-start-re' match when
+ ;; submatch 1 doesn't match. This is, for example, the keyword
+ ;; "class" in Pike.
+ ;; o The start of a previously recognized declaration; "recognized"
+ ;; means that the last char of the previous token has a `c-type'
+ ;; text property with the value `c-decl-end'; this only holds
+ ;; when `c-type-decl-end-used' is set.
;;
;; Only a spot that match CFD-DECL-RE and whose face is in the
;; CFD-FACE-CHECKLIST list causes CFD-FUN to be called. The face
@@ -4899,7 +4923,7 @@
;;
;; This function might do hidden buffer changes.
- (let ((cfd-start-pos (point))
+ (let ((cfd-start-pos (point)) ; never changed
(cfd-buffer-end (point-max))
;; The end of the token preceding the decl spot last found
;; with `c-decl-prefix-or-start-re'. `cfd-limit' if there's
@@ -4913,7 +4937,16 @@
;; `c-find-decl-prefix-search'. `cfd-limit' if there's no
;; match. If searching for the property isn't needed then we
;; disable it by setting it to `cfd-limit' directly.
- (cfd-prop-match (unless c-type-decl-end-used cfd-limit))
+ (cfd-prop-match
+ (if c-type-decl-end-used
+ (save-excursion
+ (c-backward-syntactic-ws)
+ (and
+ (not (bobp))
+ (eq (c-get-char-property (1- (point)) 'c-type)
+ 'c-decl-end)
+ (point)))
+ cfd-limit))
;; The end of the token preceding the decl spot last found by
;; `c-find-decl-prefix-search'. 0 for the implicit match at
;; bob. `cfd-limit' if there's no match. In other words,
@@ -4938,10 +4971,20 @@
;; statement or declaration, which is earlier than the first
;; returned match.
+ ;; This `cond' moves back over any literals or macros. It has special
+ ;; handling for when the region being searched is entirely within a
+ ;; macro. It sets `cfd-continue-pos' (unless we've reached
+ ;; `cfd-limit').
(cond
;; First we need to move to a syntactically relevant position.
;; Begin by backing out of comment or string literals.
+ ;;
+ ;; This arm of the cond actually triggers if we're in a literal,
+ ;; and cfd-limit is at most at BONL.
((and
+ ;; This arm of the `and' moves backwards out of a literal when
+ ;; the face at point is a literal face. In this case, its value
+ ;; is always non-nil.
(when (c-got-face-at (point) c-literal-faces)
;; Try to use the faces to back up to the start of the
;; literal. FIXME: What if the point is on a declaration
@@ -4970,7 +5013,7 @@
(let ((range (c-literal-limits)))
(if range (goto-char (car range)))))
- (setq start-in-literal (point)))
+ (setq start-in-literal (point))) ; end of `and' arm.
;; The start is in a literal. If the limit is in the same
;; one we don't have to find a syntactic position etc. We
@@ -4981,22 +5024,22 @@
(save-excursion
(goto-char cfd-start-pos)
(while (progn
- (goto-char (next-single-property-change
+ (goto-char (c-next-single-property-change
(point) 'face nil cfd-limit))
(and (< (point) cfd-limit)
(c-got-face-at (point) c-literal-faces))))
- (= (point) cfd-limit)))
+ (= (point) cfd-limit))) ; end of `cond' arm condition
;; Completely inside a literal. Set up variables to trig the
;; (< cfd-continue-pos cfd-start-pos) case below and it'll
;; find a suitable start position.
- (setq cfd-continue-pos start-in-literal))
+ (setq cfd-continue-pos start-in-literal)) ; end of `cond' arm
;; Check if the region might be completely inside a macro, to
;; optimize that like the completely-inside-literal above.
((save-excursion
(and (= (forward-line 1) 0)
- (bolp) ; forward-line has funny behavior at eob.
+ (bolp) ; forward-line has funny behavior at eob.
(>= (point) cfd-limit)
(progn (backward-char)
(eq (char-before) ?\\))))
@@ -5006,6 +5049,8 @@
(setq cfd-continue-pos (1- cfd-start-pos)
start-in-macro t))
+ ;; The default arm of the `cond' moves back over any macro we're in
+ ;; and over any syntactic WS. It sets `c-find-decl-syntactic-pos'.
(t
;; Back out of any macro so we don't miss any declaration
;; that could follow after it.
@@ -5052,10 +5097,10 @@
(< (point) cfd-limit))
;; Do an initial search now. In the bob case above it's
;; only done to search for a `c-decl-end' spot.
- (c-find-decl-prefix-search))
+ (c-find-decl-prefix-search)) ; sets cfd-continue-pos
(setq c-find-decl-match-pos (and (< cfd-match-pos cfd-start-pos)
- cfd-match-pos)))))
+ cfd-match-pos))))) ; end of `cond'
;; Advance `cfd-continue-pos' if it's before the start position.
;; The closest continue position that might have effect at or
@@ -5114,7 +5159,7 @@
;; `cfd-match-pos' so we can continue at the start position.
;; (Note that we don't get here if the first match is below
;; it.)
- (goto-char cfd-start-pos)))
+ (goto-char cfd-start-pos))) ; end of `cond'
;; Delete found matches if they are before our new continue
;; position, so that `c-find-decl-prefix-search' won't back up
@@ -5123,7 +5168,7 @@
(when (and cfd-re-match (< cfd-re-match cfd-continue-pos))
(setq cfd-re-match nil))
(when (and cfd-prop-match (< cfd-prop-match cfd-continue-pos))
- (setq cfd-prop-match nil)))
+ (setq cfd-prop-match nil))) ; end of `when'
(if syntactic-pos
;; This is the normal case and we got a proper syntactic
@@ -5144,9 +5189,10 @@
;; good start position for the search, so do it.
(c-find-decl-prefix-search)))
- ;; Now loop. Round what? (ACM, 2006/7/5). We already got the first match.
-
+ ;; Now loop, one decl spot per iteration. We already have the first
+ ;; match in `cfd-match-pos'.
(while (progn
+ ;; Go foward over "false matches", one per iteration.
(while (and
(< cfd-match-pos cfd-limit)
@@ -5187,10 +5233,10 @@
(goto-char cfd-continue-pos)
t)))
- (< (point) cfd-limit))
- (c-find-decl-prefix-search))
+ (< (point) cfd-limit)) ; end of "false matches" condition
+ (c-find-decl-prefix-search)) ; end of "false matches" loop
- (< (point) cfd-limit))
+ (< (point) cfd-limit)) ; end of condition for "decl-spot" while
(when (and
(>= (point) cfd-start-pos)
@@ -5218,7 +5264,7 @@
;; The matched token was the last thing in the macro,
;; so the whole match is bogus.
(setq cfd-macro-end 0)
- nil))))
+ nil)))) ; end of when condition
(c-debug-put-decl-spot-faces cfd-match-pos (point))
(if (funcall cfd-fun cfd-match-pos (/= cfd-macro-end 0))
@@ -5398,8 +5444,8 @@
(c-go-list-forward))
(when (equal (c-get-char-property (1- (point)) 'syntax-table)
c->-as-paren-syntax) ; should always be true.
- (c-clear-char-property (1- (point)) 'category))
- (c-clear-char-property pos 'category))))
+ (c-unmark-<->-as-paren (1- (point))))
+ (c-unmark-<->-as-paren pos))))
(defun c-clear->-pair-props (&optional pos)
;; POS (default point) is at a > character. If it is marked with
@@ -5415,8 +5461,8 @@
(c-go-up-list-backward))
(when (equal (c-get-char-property (point) 'syntax-table)
c-<-as-paren-syntax) ; should always be true.
- (c-clear-char-property (point) 'category))
- (c-clear-char-property pos 'category))))
+ (c-unmark-<->-as-paren (point)))
+ (c-unmark-<->-as-paren pos))))
(defun c-clear-<>-pair-props (&optional pos)
;; POS (default point) is at a < or > character. If it has an
@@ -5505,9 +5551,10 @@
(c-syntactic-skip-backward "^;{}" (c-determine-limit 512))
(setq new-beg (point))
- ;; Remove the syntax-table properties from each pertinent <...> pair.
- ;; Firsly, the ones with the < before beg and > after beg.
- (while (c-search-forward-char-property 'category 'c-<-as-paren-syntax beg)
+ ;; Remove the syntax-table/category properties from each pertinent <...>
+ ;; pair. Firsly, the ones with the < before beg and > after beg.
+ (while
+ (c-search-forward-char-property 'syntax-table c-<-as-paren-syntax beg)
(if (c-clear-<-pair-props-if-match-after beg (1- (point)))
(setq need-new-beg t)))
@@ -5518,7 +5565,7 @@
;; Remove syntax-table properties from the remaining pertinent <...>
;; pairs, those with a > after end and < before end.
- (while (c-search-backward-char-property 'category 'c->-as-paren-syntax end)
+ (while (c-search-backward-char-property 'syntax-table c->-as-paren-syntax end)
(if (c-clear->-pair-props-if-match-before end)
(setq need-new-end t)))
@@ -5531,8 +5578,6 @@
(when need-new-end
(and (> new-end c-new-END) (setq c-new-END new-end))))))
-
-
(defun c-after-change-check-<>-operators (beg end)
;; This is called from `after-change-functions' when
;; c-recognize-<>-arglists' is set. It ensures that no "<" or ">"
@@ -5867,7 +5912,6 @@
;; Recursive part of `c-forward-<>-arglist'.
;;
;; This function might do hidden buffer changes.
-
(let ((start (point)) res pos tmp
;; Cover this so that any recorded found type ranges are
;; automatically lost if it turns out to not be an angle
@@ -5903,32 +5947,31 @@
(while (and
(progn
(c-forward-syntactic-ws)
- (let ((orig-record-found-types c-record-found-types))
- (when (or (and c-record-type-identifiers all-types)
- (c-major-mode-is 'java-mode))
- ;; All encountered identifiers are types, so set the
- ;; promote flag and parse the type.
- (progn
- (c-forward-syntactic-ws)
- (if (looking-at "\\?")
- (forward-char)
- (when (looking-at c-identifier-start)
- (let ((c-promote-possible-types t)
- (c-record-found-types t))
- (c-forward-type))))
-
- (c-forward-syntactic-ws)
-
- (when (or (looking-at "extends")
- (looking-at "super"))
- (forward-word)
- (c-forward-syntactic-ws)
+ (when (or (and c-record-type-identifiers all-types)
+ (c-major-mode-is 'java-mode))
+ ;; All encountered identifiers are types, so set the
+ ;; promote flag and parse the type.
+ (progn
+ (c-forward-syntactic-ws)
+ (if (looking-at "\\?")
+ (forward-char)
+ (when (looking-at c-identifier-start)
(let ((c-promote-possible-types t)
(c-record-found-types t))
- (c-forward-type)
- (c-forward-syntactic-ws))))))
-
- (setq pos (point)) ; e.g. first token inside the '<'
+ (c-forward-type))))
+
+ (c-forward-syntactic-ws)
+
+ (when (or (looking-at "extends")
+ (looking-at "super"))
+ (forward-word)
+ (c-forward-syntactic-ws)
+ (let ((c-promote-possible-types t)
+ (c-record-found-types t))
+ (c-forward-type)
+ (c-forward-syntactic-ws)))))
+
+ (setq pos (point)) ; e.g. first token inside the '<'
;; Note: These regexps exploit the match order in \| so
;; that "<>" is matched by "<" rather than "[^>:-]>".
@@ -5993,7 +6036,6 @@
(c-keyword-member
(c-keyword-sym (match-string 1))
'c-<>-type-kwds)))))))
-
;; It was an angle bracket arglist.
(setq c-record-found-types subres)
@@ -6449,6 +6491,7 @@
(goto-char (match-end 1))
(c-forward-syntactic-ws)
(setq res t)))
+
;; Step over any type suffix operator. Do not let the existence
;; of these alter the classification of the found type, since
;; these operators typically are allowed in normal expressions
@@ -7100,36 +7143,35 @@
(catch 'at-decl-or-cast
;; CASE 1
- (when (> paren-depth 0)
- ;; Encountered something inside parens that isn't matched by
- ;; the `c-type-decl-*' regexps, so it's not a type decl
- ;; expression. Try to skip out to the same paren depth to
- ;; not confuse the cast check below.
- (c-safe (goto-char (scan-lists (point) 1 paren-depth)))
- ;; If we've found a specifier keyword then it's a
- ;; declaration regardless.
- (throw 'at-decl-or-cast (eq at-decl-or-cast t)))
-
- (setq at-decl-end
- (looking-at (cond ((eq context '<>) "[,>]")
- (context "[,\)]")
- (t "[,;]"))))
-
- ;; Now we've collected info about various characteristics of
- ;; the construct we're looking at. Below follows a decision
- ;; tree based on that. It's ordered to check more certain
- ;; signs before less certain ones.
-
- (if got-identifier
- (progn
-
- ;; CASE 2
- (when (and (or at-type maybe-typeless)
- (not (or got-prefix got-parens)))
- ;; Got another identifier directly after the type, so it's a
- ;; declaration.
- (throw 'at-decl-or-cast t))
-
+ (when (> paren-depth 0)
+ ;; Encountered something inside parens that isn't matched by
+ ;; the `c-type-decl-*' regexps, so it's not a type decl
+ ;; expression. Try to skip out to the same paren depth to
+ ;; not confuse the cast check below.
+ (c-safe (goto-char (scan-lists (point) 1 paren-depth)))
+ ;; If we've found a specifier keyword then it's a
+ ;; declaration regardless.
+ (throw 'at-decl-or-cast (eq at-decl-or-cast t)))
+
+ (setq at-decl-end
+ (looking-at (cond ((eq context '<>) "[,>]")
+ (context "[,\)]")
+ (t "[,;]"))))
+
+ ;; Now we've collected info about various characteristics of
+ ;; the construct we're looking at. Below follows a decision
+ ;; tree based on that. It's ordered to check more certain
+ ;; signs before less certain ones.
+
+ (if got-identifier
+ (progn
+
+ ;; CASE 2
+ (when (and (or at-type maybe-typeless)
+ (not (or got-prefix got-parens)))
+ ;; Got another identifier directly after the type, so it's a
+ ;; declaration.
+ (throw 'at-decl-or-cast t))
(when (and got-parens
(not got-prefix)
@@ -7151,9 +7193,9 @@
(c-fdoc-shift-type-backward)))
;; Found no identifier.
- (if backup-at-type
- (progn
+ (if backup-at-type
+ (progn
;; CASE 3
(when (= (point) start)
@@ -7176,251 +7218,251 @@
(setq backup-if-not-cast t)
(throw 'at-decl-or-cast t)))
- ;; CASE 4
- (when (and got-suffix
- (not got-prefix)
- (not got-parens))
- ;; Got a plain list of identifiers followed by some suffix.
- ;; If this isn't a cast then the last identifier probably is
- ;; the declared one and we should back up to the previous
- ;; type.
- (setq backup-if-not-cast t)
- (throw 'at-decl-or-cast t)))
-
- ;; CASE 5
- (when (eq at-type t)
- ;; If the type is known we know that there can't be any
- ;; identifier somewhere else, and it's only in declarations in
- ;; e.g. function prototypes and in casts that the identifier may
- ;; be left out.
- (throw 'at-decl-or-cast t))
-
- (when (= (point) start)
- ;; Only got a single identifier (parsed as a type so far).
- ;; CASE 6
- (if (and
- ;; Check that the identifier isn't at the start of an
- ;; expression.
- at-decl-end
- (cond
- ((eq context 'decl)
- ;; Inside an arglist that contains declarations. If K&R
- ;; style declarations and parenthesis style initializers
- ;; aren't allowed then the single identifier must be a
- ;; type, else we require that it's known or found
- ;; (primitive types are handled above).
- (or (and (not c-recognize-knr-p)
- (not c-recognize-paren-inits))
- (memq at-type '(known found))))
- ((eq context '<>)
- ;; Inside a template arglist. Accept known and found
- ;; types; other identifiers could just as well be
- ;; constants in C++.
- (memq at-type '(known found)))))
- (throw 'at-decl-or-cast t)
- ;; CASE 7
- ;; Can't be a valid declaration or cast, but if we've found a
- ;; specifier it can't be anything else either, so treat it as
- ;; an invalid/unfinished declaration or cast.
- (throw 'at-decl-or-cast at-decl-or-cast))))
-
- (if (and got-parens
- (not got-prefix)
- (not context)
- (not (eq at-type t))
- (or backup-at-type
- maybe-typeless
- backup-maybe-typeless
- (when c-recognize-typeless-decls
- (or (not got-suffix)
- (not (looking-at
- c-after-suffixed-type-maybe-decl-key))))))
- ;; Got an empty paren pair and a preceding type that probably
- ;; really is the identifier. Shift the type backwards to make
- ;; the last one the identifier. This is analogous to the
- ;; "backtracking" done inside the `c-type-decl-suffix-key' loop
- ;; above.
- ;;
- ;; Exception: In addition to the conditions in that
- ;; "backtracking" code, do not shift backward if we're not
- ;; looking at either `c-after-suffixed-type-decl-key' or "[;,]".
- ;; Since there's no preceding type, the shift would mean that
- ;; the declaration is typeless. But if the regexp doesn't match
- ;; then we will simply fall through in the tests below and not
- ;; recognize it at all, so it's better to try it as an abstract
- ;; declarator instead.
- (c-fdoc-shift-type-backward)
-
- ;; Still no identifier.
- ;; CASE 8
- (when (and got-prefix (or got-parens got-suffix))
- ;; Require `got-prefix' together with either `got-parens' or
- ;; `got-suffix' to recognize it as an abstract declarator:
- ;; `got-parens' only is probably an empty function call.
- ;; `got-suffix' only can build an ordinary expression together
- ;; with the preceding identifier which we've taken as a type.
- ;; We could actually accept on `got-prefix' only, but that can
- ;; easily occur temporarily while writing an expression so we
- ;; avoid that case anyway. We could do a better job if we knew
- ;; the point when the fontification was invoked.
- (throw 'at-decl-or-cast t))
-
- ;; CASE 9
- (when (and at-type
- (not got-prefix)
- (not got-parens)
- got-suffix-after-parens
- (eq (char-after got-suffix-after-parens) ?\())
- ;; Got a type, no declarator but a paren suffix. I.e. it's a
- ;; normal function call after all (or perhaps a C++ style object
- ;; instantiation expression).
- (throw 'at-decl-or-cast nil))))
-
- ;; CASE 10
- (when at-decl-or-cast
- ;; By now we've located the type in the declaration that we know
- ;; we're in.
- (throw 'at-decl-or-cast t))
-
- ;; CASE 11
- (when (and got-identifier
- (not context)
- (looking-at c-after-suffixed-type-decl-key)
- (if (and got-parens
- (not got-prefix)
- (not got-suffix)
- (not (eq at-type t)))
- ;; Shift the type backward in the case that there's a
- ;; single identifier inside parens. That can only
- ;; occur in K&R style function declarations so it's
- ;; more likely that it really is a function call.
- ;; Therefore we only do this after
- ;; `c-after-suffixed-type-decl-key' has matched.
- (progn (c-fdoc-shift-type-backward) t)
- got-suffix-after-parens))
- ;; A declaration according to `c-after-suffixed-type-decl-key'.
- (throw 'at-decl-or-cast t))
-
- ;; CASE 12
- (when (and (or got-prefix (not got-parens))
- (memq at-type '(t known)))
- ;; It's a declaration if a known type precedes it and it can't be a
- ;; function call.
- (throw 'at-decl-or-cast t))
-
- ;; If we get here we can't tell if this is a type decl or a normal
- ;; expression by looking at it alone. (That's under the assumption
- ;; that normal expressions always can look like type decl expressions,
- ;; which isn't really true but the cases where it doesn't hold are so
- ;; uncommon (e.g. some placements of "const" in C++) it's not worth
- ;; the effort to look for them.)
+ ;; CASE 4
+ (when (and got-suffix
+ (not got-prefix)
+ (not got-parens))
+ ;; Got a plain list of identifiers followed by some suffix.
+ ;; If this isn't a cast then the last identifier probably is
+ ;; the declared one and we should back up to the previous
+ ;; type.
+ (setq backup-if-not-cast t)
+ (throw 'at-decl-or-cast t)))
+
+ ;; CASE 5
+ (when (eq at-type t)
+ ;; If the type is known we know that there can't be any
+ ;; identifier somewhere else, and it's only in declarations in
+ ;; e.g. function prototypes and in casts that the identifier may
+ ;; be left out.
+ (throw 'at-decl-or-cast t))
+
+ (when (= (point) start)
+ ;; Only got a single identifier (parsed as a type so far).
+ ;; CASE 6
+ (if (and
+ ;; Check that the identifier isn't at the start of an
+ ;; expression.
+ at-decl-end
+ (cond
+ ((eq context 'decl)
+ ;; Inside an arglist that contains declarations. If K&R
+ ;; style declarations and parenthesis style initializers
+ ;; aren't allowed then the single identifier must be a
+ ;; type, else we require that it's known or found
+ ;; (primitive types are handled above).
+ (or (and (not c-recognize-knr-p)
+ (not c-recognize-paren-inits))
+ (memq at-type '(known found))))
+ ((eq context '<>)
+ ;; Inside a template arglist. Accept known and found
+ ;; types; other identifiers could just as well be
+ ;; constants in C++.
+ (memq at-type '(known found)))))
+ (throw 'at-decl-or-cast t)
+ ;; CASE 7
+ ;; Can't be a valid declaration or cast, but if we've found a
+ ;; specifier it can't be anything else either, so treat it as
+ ;; an invalid/unfinished declaration or cast.
+ (throw 'at-decl-or-cast at-decl-or-cast))))
+
+ (if (and got-parens
+ (not got-prefix)
+ (not context)
+ (not (eq at-type t))
+ (or backup-at-type
+ maybe-typeless
+ backup-maybe-typeless
+ (when c-recognize-typeless-decls
+ (or (not got-suffix)
+ (not (looking-at
+ c-after-suffixed-type-maybe-decl-key))))))
+ ;; Got an empty paren pair and a preceding type that probably
+ ;; really is the identifier. Shift the type backwards to make
+ ;; the last one the identifier. This is analogous to the
+ ;; "backtracking" done inside the `c-type-decl-suffix-key' loop
+ ;; above.
+ ;;
+ ;; Exception: In addition to the conditions in that
+ ;; "backtracking" code, do not shift backward if we're not
+ ;; looking at either `c-after-suffixed-type-decl-key' or "[;,]".
+ ;; Since there's no preceding type, the shift would mean that
+ ;; the declaration is typeless. But if the regexp doesn't match
+ ;; then we will simply fall through in the tests below and not
+ ;; recognize it at all, so it's better to try it as an abstract
+ ;; declarator instead.
+ (c-fdoc-shift-type-backward)
+
+ ;; Still no identifier.
+ ;; CASE 8
+ (when (and got-prefix (or got-parens got-suffix))
+ ;; Require `got-prefix' together with either `got-parens' or
+ ;; `got-suffix' to recognize it as an abstract declarator:
+ ;; `got-parens' only is probably an empty function call.
+ ;; `got-suffix' only can build an ordinary expression together
+ ;; with the preceding identifier which we've taken as a type.
+ ;; We could actually accept on `got-prefix' only, but that can
+ ;; easily occur temporarily while writing an expression so we
+ ;; avoid that case anyway. We could do a better job if we knew
+ ;; the point when the fontification was invoked.
+ (throw 'at-decl-or-cast t))
+
+ ;; CASE 9
+ (when (and at-type
+ (not got-prefix)
+ (not got-parens)
+ got-suffix-after-parens
+ (eq (char-after got-suffix-after-parens) ?\())
+ ;; Got a type, no declarator but a paren suffix. I.e. it's a
+ ;; normal function call after all (or perhaps a C++ style object
+ ;; instantiation expression).
+ (throw 'at-decl-or-cast nil))))
+
+ ;; CASE 10
+ (when at-decl-or-cast
+ ;; By now we've located the type in the declaration that we know
+ ;; we're in.
+ (throw 'at-decl-or-cast t))
+
+ ;; CASE 11
+ (when (and got-identifier
+ (not context)
+ (looking-at c-after-suffixed-type-decl-key)
+ (if (and got-parens
+ (not got-prefix)
+ (not got-suffix)
+ (not (eq at-type t)))
+ ;; Shift the type backward in the case that there's a
+ ;; single identifier inside parens. That can only
+ ;; occur in K&R style function declarations so it's
+ ;; more likely that it really is a function call.
+ ;; Therefore we only do this after
+ ;; `c-after-suffixed-type-decl-key' has matched.
+ (progn (c-fdoc-shift-type-backward) t)
+ got-suffix-after-parens))
+ ;; A declaration according to `c-after-suffixed-type-decl-key'.
+ (throw 'at-decl-or-cast t))
+
+ ;; CASE 12
+ (when (and (or got-prefix (not got-parens))
+ (memq at-type '(t known)))
+ ;; It's a declaration if a known type precedes it and it can't be a
+ ;; function call.
+ (throw 'at-decl-or-cast t))
+
+ ;; If we get here we can't tell if this is a type decl or a normal
+ ;; expression by looking at it alone. (That's under the assumption
+ ;; that normal expressions always can look like type decl expressions,
+ ;; which isn't really true but the cases where it doesn't hold are so
+ ;; uncommon (e.g. some placements of "const" in C++) it's not worth
+ ;; the effort to look for them.)
;;; 2008-04-16: commented out the next form, to allow the function to recognize
;;; "foo (int bar)" in CC (an implicit type (in class foo) without a semicolon)
;;; as a(n almost complete) declaration, enabling it to be fontified.
- ;; CASE 13
- ;; (unless (or at-decl-end (looking-at "=[^=]"))
- ;; If this is a declaration it should end here or its initializer(*)
- ;; should start here, so check for allowed separation tokens. Note
- ;; that this rule doesn't work e.g. with a K&R arglist after a
- ;; function header.
- ;;
- ;; *) Don't check for C++ style initializers using parens
- ;; since those already have been matched as suffixes.
- ;;
- ;; If `at-decl-or-cast' is then we've found some other sign that
- ;; it's a declaration or cast, so then it's probably an
- ;; invalid/unfinished one.
- ;; (throw 'at-decl-or-cast at-decl-or-cast))
-
- ;; Below are tests that only should be applied when we're certain to
- ;; not have parsed halfway through an expression.
-
- ;; CASE 14
- (when (memq at-type '(t known))
- ;; The expression starts with a known type so treat it as a
- ;; declaration.
- (throw 'at-decl-or-cast t))
-
- ;; CASE 15
- (when (and (c-major-mode-is 'c++-mode)
- ;; In C++ we check if the identifier is a known type, since
- ;; (con|de)structors use the class name as identifier.
- ;; We've always shifted over the identifier as a type and
- ;; then backed up again in this case.
- identifier-type
- (or (memq identifier-type '(found known))
- (and (eq (char-after identifier-start) ?~)
- ;; `at-type' probably won't be 'found for
- ;; destructors since the "~" is then part of the
- ;; type name being checked against the list of
- ;; known types, so do a check without that
- ;; operator.
- (or (save-excursion
- (goto-char (1+ identifier-start))
- (c-forward-syntactic-ws)
- (c-with-syntax-table
- c-identifier-syntax-table
- (looking-at c-known-type-key)))
- (save-excursion
- (goto-char (1+ identifier-start))
- ;; We have already parsed the type earlier,
- ;; so it'd be possible to cache the end
- ;; position instead of redoing it here, but
- ;; then we'd need to keep track of another
- ;; position everywhere.
- (c-check-type (point)
- (progn (c-forward-type)
- (point))))))))
- (throw 'at-decl-or-cast t))
-
- (if got-identifier
- (progn
- ;; CASE 16
- (when (and got-prefix-before-parens
- at-type
- (or at-decl-end (looking-at "=[^=]"))
- (not context)
- (not got-suffix))
- ;; Got something like "foo * bar;". Since we're not inside an
- ;; arglist it would be a meaningless expression because the
- ;; result isn't used. We therefore choose to recognize it as
- ;; a declaration. Do not allow a suffix since it could then
- ;; be a function call.
- (throw 'at-decl-or-cast t))
-
- ;; CASE 17
- (when (and (or got-suffix-after-parens
- (looking-at "=[^=]"))
- (eq at-type 'found)
- (not (eq context 'arglist)))
- ;; Got something like "a (*b) (c);" or "a (b) = c;". It could
- ;; be an odd expression or it could be a declaration. Treat
- ;; it as a declaration if "a" has been used as a type
- ;; somewhere else (if it's a known type we won't get here).
- (throw 'at-decl-or-cast t)))
-
- ;; CASE 18
- (when (and context
- (or got-prefix
- (and (eq context 'decl)
- (not c-recognize-paren-inits)
- (or got-parens got-suffix))))
- ;; Got a type followed by an abstract declarator. If `got-prefix'
- ;; is set it's something like "a *" without anything after it. If
- ;; `got-parens' or `got-suffix' is set it's "a()", "a[]", "a()[]",
- ;; or similar, which we accept only if the context rules out
- ;; expressions.
- (throw 'at-decl-or-cast t)))
-
- ;; If we had a complete symbol table here (which rules out
- ;; `c-found-types') we should return t due to the disambiguation rule
- ;; (in at least C++) that anything that can be parsed as a declaration
- ;; is a declaration. Now we're being more defensive and prefer to
- ;; highlight things like "foo (bar);" as a declaration only if we're
- ;; inside an arglist that contains declarations.
- ;; CASE 19
- (eq context 'decl))))
+ ;; CASE 13
+ ;; (unless (or at-decl-end (looking-at "=[^=]"))
+ ;; If this is a declaration it should end here or its initializer(*)
+ ;; should start here, so check for allowed separation tokens. Note
+ ;; that this rule doesn't work e.g. with a K&R arglist after a
+ ;; function header.
+ ;;
+ ;; *) Don't check for C++ style initializers using parens
+ ;; since those already have been matched as suffixes.
+ ;;
+ ;; If `at-decl-or-cast' is then we've found some other sign that
+ ;; it's a declaration or cast, so then it's probably an
+ ;; invalid/unfinished one.
+ ;; (throw 'at-decl-or-cast at-decl-or-cast))
+
+ ;; Below are tests that only should be applied when we're certain to
+ ;; not have parsed halfway through an expression.
+
+ ;; CASE 14
+ (when (memq at-type '(t known))
+ ;; The expression starts with a known type so treat it as a
+ ;; declaration.
+ (throw 'at-decl-or-cast t))
+
+ ;; CASE 15
+ (when (and (c-major-mode-is 'c++-mode)
+ ;; In C++ we check if the identifier is a known type, since
+ ;; (con|de)structors use the class name as identifier.
+ ;; We've always shifted over the identifier as a type and
+ ;; then backed up again in this case.
+ identifier-type
+ (or (memq identifier-type '(found known))
+ (and (eq (char-after identifier-start) ?~)
+ ;; `at-type' probably won't be 'found for
+ ;; destructors since the "~" is then part of the
+ ;; type name being checked against the list of
+ ;; known types, so do a check without that
+ ;; operator.
+ (or (save-excursion
+ (goto-char (1+ identifier-start))
+ (c-forward-syntactic-ws)
+ (c-with-syntax-table
+ c-identifier-syntax-table
+ (looking-at c-known-type-key)))
+ (save-excursion
+ (goto-char (1+ identifier-start))
+ ;; We have already parsed the type earlier,
+ ;; so it'd be possible to cache the end
+ ;; position instead of redoing it here, but
+ ;; then we'd need to keep track of another
+ ;; position everywhere.
+ (c-check-type (point)
+ (progn (c-forward-type)
+ (point))))))))
+ (throw 'at-decl-or-cast t))
+
+ (if got-identifier
+ (progn
+ ;; CASE 16
+ (when (and got-prefix-before-parens
+ at-type
+ (or at-decl-end (looking-at "=[^=]"))
+ (not context)
+ (not got-suffix))
+ ;; Got something like "foo * bar;". Since we're not inside an
+ ;; arglist it would be a meaningless expression because the
+ ;; result isn't used. We therefore choose to recognize it as
+ ;; a declaration. Do not allow a suffix since it could then
+ ;; be a function call.
+ (throw 'at-decl-or-cast t))
+
+ ;; CASE 17
+ (when (and (or got-suffix-after-parens
+ (looking-at "=[^=]"))
+ (eq at-type 'found)
+ (not (eq context 'arglist)))
+ ;; Got something like "a (*b) (c);" or "a (b) = c;". It could
+ ;; be an odd expression or it could be a declaration. Treat
+ ;; it as a declaration if "a" has been used as a type
+ ;; somewhere else (if it's a known type we won't get here).
+ (throw 'at-decl-or-cast t)))
+
+ ;; CASE 18
+ (when (and context
+ (or got-prefix
+ (and (eq context 'decl)
+ (not c-recognize-paren-inits)
+ (or got-parens got-suffix))))
+ ;; Got a type followed by an abstract declarator. If `got-prefix'
+ ;; is set it's something like "a *" without anything after it. If
+ ;; `got-parens' or `got-suffix' is set it's "a()", "a[]", "a()[]",
+ ;; or similar, which we accept only if the context rules out
+ ;; expressions.
+ (throw 'at-decl-or-cast t)))
+
+ ;; If we had a complete symbol table here (which rules out
+ ;; `c-found-types') we should return t due to the disambiguation rule
+ ;; (in at least C++) that anything that can be parsed as a declaration
+ ;; is a declaration. Now we're being more defensive and prefer to
+ ;; highlight things like "foo (bar);" as a declaration only if we're
+ ;; inside an arglist that contains declarations.
+ ;; CASE 19
+ (eq context 'decl))))
;; The point is now after the type decl expression.
@@ -7609,10 +7651,10 @@
(c-put-c-type-property (1- (point)) 'c-decl-end)
t)
- ;; It's an unfinished label. We consider the keyword enough
- ;; to recognize it as a label, so that it gets fontified.
- ;; Leave the point at the end of it, but don't put any
- ;; `c-decl-end' marker.
+ ;; It's an unfinished label. We consider the keyword enough
+ ;; to recognize it as a label, so that it gets fontified.
+ ;; Leave the point at the end of it, but don't put any
+ ;; `c-decl-end' marker.
(goto-char kwd-end)
t))))
@@ -7797,69 +7839,69 @@
;;
;; This function might do hidden buffer changes.
- (let ((start (point))
- start-char
- (c-promote-possible-types t)
- lim
- ;; Turn off recognition of angle bracket arglists while parsing
- ;; types here since the protocol reference list might then be
- ;; considered part of the preceding name or superclass-name.
- c-recognize-<>-arglists)
-
- (if (or
- (when (looking-at
- (eval-when-compile
- (c-make-keywords-re t
- (append (c-lang-const c-protection-kwds objc)
- '("@end"))
- 'objc-mode)))
- (goto-char (match-end 1))
- t)
-
- (and
- (looking-at
- (eval-when-compile
- (c-make-keywords-re t
- '("@interface" "@implementation" "@protocol")
- 'objc-mode)))
-
- ;; Handle the name of the class itself.
- (progn
-; (c-forward-token-2) ; 2006/1/13 This doesn't move if the token's
-; at EOB.
- (goto-char (match-end 0))
- (setq lim (point))
- (c-skip-ws-forward)
- (c-forward-type))
-
- (catch 'break
- ;; Look for ": superclass-name" or "( category-name )".
- (when (looking-at "[:\(]")
- (setq start-char (char-after))
- (forward-char)
- (c-forward-syntactic-ws)
- (unless (c-forward-type) (throw 'break nil))
- (when (eq start-char ?\()
- (unless (eq (char-after) ?\)) (throw 'break nil))
- (forward-char)
- (c-forward-syntactic-ws)))
-
- ;; Look for a protocol reference list.
- (if (eq (char-after) ?<)
- (let ((c-recognize-<>-arglists t)
- (c-parse-and-markup-<>-arglists t)
- c-restricted-<>-arglists)
- (c-forward-<>-arglist t))
- t))))
-
- (progn
- (c-backward-syntactic-ws lim)
- (c-clear-c-type-property start (1- (point)) 'c-decl-end)
- (c-put-c-type-property (1- (point)) 'c-decl-end)
- t)
-
- (c-clear-c-type-property start (point) 'c-decl-end)
- nil)))
+ (let ((start (point))
+ start-char
+ (c-promote-possible-types t)
+ lim
+ ;; Turn off recognition of angle bracket arglists while parsing
+ ;; types here since the protocol reference list might then be
+ ;; considered part of the preceding name or superclass-name.
+ c-recognize-<>-arglists)
+
+ (if (or
+ (when (looking-at
+ (eval-when-compile
+ (c-make-keywords-re t
+ (append (c-lang-const c-protection-kwds objc)
+ '("@end"))
+ 'objc-mode)))
+ (goto-char (match-end 1))
+ t)
+
+ (and
+ (looking-at
+ (eval-when-compile
+ (c-make-keywords-re t
+ '("@interface" "@implementation" "@protocol")
+ 'objc-mode)))
+
+ ;; Handle the name of the class itself.
+ (progn
+ ;; (c-forward-token-2) ; 2006/1/13 This doesn't move if the token's
+ ;; at EOB.
+ (goto-char (match-end 0))
+ (setq lim (point))
+ (c-skip-ws-forward)
+ (c-forward-type))
+
+ (catch 'break
+ ;; Look for ": superclass-name" or "( category-name )".
+ (when (looking-at "[:\(]")
+ (setq start-char (char-after))
+ (forward-char)
+ (c-forward-syntactic-ws)
+ (unless (c-forward-type) (throw 'break nil))
+ (when (eq start-char ?\()
+ (unless (eq (char-after) ?\)) (throw 'break nil))
+ (forward-char)
+ (c-forward-syntactic-ws)))
+
+ ;; Look for a protocol reference list.
+ (if (eq (char-after) ?<)
+ (let ((c-recognize-<>-arglists t)
+ (c-parse-and-markup-<>-arglists t)
+ c-restricted-<>-arglists)
+ (c-forward-<>-arglist t))
+ t))))
+
+ (progn
+ (c-backward-syntactic-ws lim)
+ (c-clear-c-type-property start (1- (point)) 'c-decl-end)
+ (c-put-c-type-property (1- (point)) 'c-decl-end)
+ t)
+
+ (c-clear-c-type-property start (point) 'c-decl-end)
+ nil)))
(defun c-beginning-of-inheritance-list (&optional lim)
;; Go to the first non-whitespace after the colon that starts a
@@ -7946,7 +7988,7 @@
;;
;; This function might do hidden buffer changes.
- (let ((beg (point)) end id-start)
+ (let ((beg (point)) id-start)
(and
(eq (c-beginning-of-statement-1 lim) 'same)
@@ -8036,54 +8078,54 @@
(throw 'knr nil)))
(if after-rparen
- ;; We're inside a paren. Could it be our argument list....?
- (if
- (and
- (progn
- (goto-char after-rparen)
- (unless (c-go-list-backward) (throw 'knr nil)) ;
- ;; FIXME!!! What about macros between the parens? 2007/01/20
- (setq before-lparen (point)))
-
- ;; It can't be the arg list if next token is ; or {
- (progn (goto-char after-rparen)
- (c-forward-syntactic-ws)
- (not (memq (char-after) '(?\; ?\{ ?\=))))
-
- ;; Is the thing preceding the list an identifier (the
- ;; function name), or a macro expansion?
- (progn
- (goto-char before-lparen)
- (eq (c-backward-token-2) 0)
- (or (eq (c-on-identifier) (point))
- (and (eq (char-after) ?\))
- (c-go-up-list-backward)
- (eq (c-backward-token-2) 0)
- (eq (c-on-identifier) (point)))))
-
- ;; Have we got a non-empty list of comma-separated
- ;; identifiers?
- (progn
- (goto-char before-lparen)
- (c-forward-token-2) ; to first token inside parens
- (and
- (c-on-identifier)
- (c-forward-token-2)
- (catch 'id-list
- (while (eq (char-after) ?\,)
- (c-forward-token-2)
- (unless (c-on-identifier) (throw 'id-list nil))
- (c-forward-token-2))
- (eq (char-after) ?\))))))
-
- ;; ...Yes. We've identified the function's argument list.
- (throw 'knr
- (progn (goto-char after-rparen)
- (c-forward-syntactic-ws)
- (point)))
-
- ;; ...No. The current parens aren't the function's arg list.
- (goto-char before-lparen))
+ ;; We're inside a paren. Could it be our argument list....?
+ (if
+ (and
+ (progn
+ (goto-char after-rparen)
+ (unless (c-go-list-backward) (throw 'knr nil)) ;
+ ;; FIXME!!! What about macros between the parens? 2007/01/20
+ (setq before-lparen (point)))
+
+ ;; It can't be the arg list if next token is ; or {
+ (progn (goto-char after-rparen)
+ (c-forward-syntactic-ws)
+ (not (memq (char-after) '(?\; ?\{ ?\=))))
+
+ ;; Is the thing preceding the list an identifier (the
+ ;; function name), or a macro expansion?
+ (progn
+ (goto-char before-lparen)
+ (eq (c-backward-token-2) 0)
+ (or (eq (c-on-identifier) (point))
+ (and (eq (char-after) ?\))
+ (c-go-up-list-backward)
+ (eq (c-backward-token-2) 0)
+ (eq (c-on-identifier) (point)))))
+
+ ;; Have we got a non-empty list of comma-separated
+ ;; identifiers?
+ (progn
+ (goto-char before-lparen)
+ (c-forward-token-2) ; to first token inside parens
+ (and
+ (c-on-identifier)
+ (c-forward-token-2)
+ (catch 'id-list
+ (while (eq (char-after) ?\,)
+ (c-forward-token-2)
+ (unless (c-on-identifier) (throw 'id-list nil))
+ (c-forward-token-2))
+ (eq (char-after) ?\))))))
+
+ ;; ...Yes. We've identified the function's argument list.
+ (throw 'knr
+ (progn (goto-char after-rparen)
+ (c-forward-syntactic-ws)
+ (point)))
+
+ ;; ...No. The current parens aren't the function's arg list.
+ (goto-char before-lparen))
(or (c-go-list-backward) ; backwards over [ .... ]
(throw 'knr nil)))))))))
@@ -8289,7 +8331,7 @@
(and
(progn
(while ; keep going back to "[;={"s until we either find
- ; no more, or get to one which isn't an "operator ="
+ ; no more, or get to one which isn't an "operator ="
(and (c-syntactic-re-search-forward "[;={]" start t t t)
(eq (char-before) ?=)
c-overloadable-operators-regexp
@@ -8403,10 +8445,7 @@
(when (and c-recognize-<>-arglists
(eq (char-before) ?>))
;; Could be at the end of a template arglist.
- (let ((c-parse-and-markup-<>-arglists t)
- (c-disallow-comma-in-<>-arglists
- (and containing-sexp
- (not (eq (char-after containing-sexp) ?{)))))
+ (let ((c-parse-and-markup-<>-arglists t))
(while (and
(c-backward-<>-arglist nil limit)
(progn
@@ -8612,86 +8651,86 @@
(while (and (not bufpos)
containing-sexp)
(when paren-state
- (if (consp (car paren-state))
- (setq lim (cdr (car paren-state))
- paren-state (cdr paren-state))
- (setq lim (car paren-state)))
- (when paren-state
- (setq next-containing (car paren-state)
- paren-state (cdr paren-state))))
- (goto-char containing-sexp)
- (if (c-looking-at-inexpr-block next-containing next-containing)
- ;; We're in an in-expression block of some kind. Do not
- ;; check nesting. We deliberately set the limit to the
- ;; containing sexp, so that c-looking-at-inexpr-block
- ;; doesn't check for an identifier before it.
- (setq containing-sexp nil)
- ;; see if the open brace is preceded by = or [...] in
- ;; this statement, but watch out for operator=
- (setq braceassignp 'dontknow)
- (c-backward-token-2 1 t lim)
- ;; Checks to do only on the first sexp before the brace.
- (when (and c-opt-inexpr-brace-list-key
- (eq (char-after) ?\[))
- ;; In Java, an initialization brace list may follow
- ;; directly after "new Foo[]", so check for a "new"
- ;; earlier.
- (while (eq braceassignp 'dontknow)
- (setq braceassignp
- (cond ((/= (c-backward-token-2 1 t lim) 0) nil)
- ((looking-at c-opt-inexpr-brace-list-key) t)
- ((looking-at "\\sw\\|\\s_\\|[.[]")
- ;; Carry on looking if this is an
- ;; identifier (may contain "." in Java)
- ;; or another "[]" sexp.
- 'dontknow)
- (t nil)))))
- ;; Checks to do on all sexps before the brace, up to the
- ;; beginning of the statement.
- (while (eq braceassignp 'dontknow)
- (cond ((eq (char-after) ?\;)
- (setq braceassignp nil))
- ((and class-key
- (looking-at class-key))
- (setq braceassignp nil))
- ((eq (char-after) ?=)
- ;; We've seen a =, but must check earlier tokens so
- ;; that it isn't something that should be ignored.
- (setq braceassignp 'maybe)
- (while (and (eq braceassignp 'maybe)
- (zerop (c-backward-token-2 1 t lim)))
- (setq braceassignp
- (cond
- ;; Check for operator =
- ((and c-opt-op-identifier-prefix
- (looking-at c-opt-op-identifier-prefix))
- nil)
- ;; Check for `<opchar>= in Pike.
- ((and (c-major-mode-is 'pike-mode)
- (or (eq (char-after) ?`)
- ;; Special case for Pikes
- ;; `[]=, since '[' is not in
- ;; the punctuation class.
- (and (eq (char-after) ?\[)
- (eq (char-before) ?`))))
- nil)
- ((looking-at "\\s.") 'maybe)
- ;; make sure we're not in a C++ template
- ;; argument assignment
- ((and
- (c-major-mode-is 'c++-mode)
- (save-excursion
- (let ((here (point))
- (pos< (progn
- (skip-chars-backward "^<>")
- (point))))
- (and (eq (char-before) ?<)
- (not (c-crosses-statement-barrier-p
- pos< here))
- (not (c-in-literal))
- ))))
- nil)
- (t t))))))
+ (if (consp (car paren-state))
+ (setq lim (cdr (car paren-state))
+ paren-state (cdr paren-state))
+ (setq lim (car paren-state)))
+ (when paren-state
+ (setq next-containing (car paren-state)
+ paren-state (cdr paren-state))))
+ (goto-char containing-sexp)
+ (if (c-looking-at-inexpr-block next-containing next-containing)
+ ;; We're in an in-expression block of some kind. Do not
+ ;; check nesting. We deliberately set the limit to the
+ ;; containing sexp, so that c-looking-at-inexpr-block
+ ;; doesn't check for an identifier before it.
+ (setq containing-sexp nil)
+ ;; see if the open brace is preceded by = or [...] in
+ ;; this statement, but watch out for operator=
+ (setq braceassignp 'dontknow)
+ (c-backward-token-2 1 t lim)
+ ;; Checks to do only on the first sexp before the brace.
+ (when (and c-opt-inexpr-brace-list-key
+ (eq (char-after) ?\[))
+ ;; In Java, an initialization brace list may follow
+ ;; directly after "new Foo[]", so check for a "new"
+ ;; earlier.
+ (while (eq braceassignp 'dontknow)
+ (setq braceassignp
+ (cond ((/= (c-backward-token-2 1 t lim) 0) nil)
+ ((looking-at c-opt-inexpr-brace-list-key) t)
+ ((looking-at "\\sw\\|\\s_\\|[.[]")
+ ;; Carry on looking if this is an
+ ;; identifier (may contain "." in Java)
+ ;; or another "[]" sexp.
+ 'dontknow)
+ (t nil)))))
+ ;; Checks to do on all sexps before the brace, up to the
+ ;; beginning of the statement.
+ (while (eq braceassignp 'dontknow)
+ (cond ((eq (char-after) ?\;)
+ (setq braceassignp nil))
+ ((and class-key
+ (looking-at class-key))
+ (setq braceassignp nil))
+ ((eq (char-after) ?=)
+ ;; We've seen a =, but must check earlier tokens so
+ ;; that it isn't something that should be ignored.
+ (setq braceassignp 'maybe)
+ (while (and (eq braceassignp 'maybe)
+ (zerop (c-backward-token-2 1 t lim)))
+ (setq braceassignp
+ (cond
+ ;; Check for operator =
+ ((and c-opt-op-identifier-prefix
+ (looking-at c-opt-op-identifier-prefix))
+ nil)
+ ;; Check for `<opchar>= in Pike.
+ ((and (c-major-mode-is 'pike-mode)
+ (or (eq (char-after) ?`)
+ ;; Special case for Pikes
+ ;; `[]=, since '[' is not in
+ ;; the punctuation class.
+ (and (eq (char-after) ?\[)
+ (eq (char-before) ?`))))
+ nil)
+ ((looking-at "\\s.") 'maybe)
+ ;; make sure we're not in a C++ template
+ ;; argument assignment
+ ((and
+ (c-major-mode-is 'c++-mode)
+ (save-excursion
+ (let ((here (point))
+ (pos< (progn
+ (skip-chars-backward "^<>")
+ (point))))
+ (and (eq (char-before) ?<)
+ (not (c-crosses-statement-barrier-p
+ pos< here))
+ (not (c-in-literal))
+ ))))
+ nil)
+ (t t))))))
(if (and (eq braceassignp 'dontknow)
(/= (c-backward-token-2 1 t lim) 0))
(setq braceassignp nil)))
@@ -9214,7 +9253,7 @@
(max (c-point 'boi paren-pos) (point))))
(t (c-add-syntax 'defun-block-intro nil))))
- (c-add-syntax 'statement-block-intro nil)))
+ (c-add-syntax 'statement-block-intro nil)))
(if (= paren-pos boi)
;; Always done if the open brace was at boi. The
@@ -10327,7 +10366,6 @@
(c-add-syntax 'topmost-intro-cont (c-point 'boi)))
))
-
;; (CASE 6 has been removed.)
;; CASE 7: line is an expression, not a statement. Most
=== modified file 'lisp/progmodes/cc-fonts.el'
--- lisp/progmodes/cc-fonts.el 2014-09-10 21:38:11 +0000
+++ lisp/progmodes/cc-fonts.el 2014-09-25 20:19:06 +0000
@@ -176,6 +176,7 @@
'font-lock-negation-char-face))
(cc-bytecomp-defun face-inverse-video-p) ; Only in Emacs.
+(cc-bytecomp-defun face-property-instance) ; Only in XEmacs.
(defun c-make-inverse-face (oldface newface)
;; Emacs and XEmacs have completely different face manipulation
@@ -266,7 +267,7 @@
;; This function might do hidden buffer changes.
(when (c-got-face-at (point) c-literal-faces)
(while (progn
- (goto-char (next-single-property-change
+ (goto-char (c-next-single-property-change
(point) 'face nil limit))
(and (< (point) limit)
(c-got-face-at (point) c-literal-faces))))
@@ -366,39 +367,7 @@
(parse-sexp-lookup-properties
(cc-eval-when-compile
(boundp 'parse-sexp-lookup-properties))))
-
- ;; (while (re-search-forward ,regexp limit t)
- ;; (unless (progn
- ;; (goto-char (match-beginning 0))
- ;; (c-skip-comments-and-strings limit))
- ;; (goto-char (match-end 0))
- ;; ,@(mapcar
- ;; (lambda (highlight)
- ;; (if (integerp (car highlight))
- ;; (progn
- ;; (unless (eq (nth 2 highlight) t)
- ;; (error
- ;; "The override flag must currently be t in %s"
- ;; highlight))
- ;; (when (nth 3 highlight)
- ;; (error
- ;; "The laxmatch flag may currently not be set in %s"
- ;; highlight))
- ;; `(save-match-data
- ;; (c-put-font-lock-face
- ;; (match-beginning ,(car highlight))
- ;; (match-end ,(car highlight))
- ;; ,(elt highlight 1))))
- ;; (when (nth 3 highlight)
- ;; (error "Match highlights currently not supported in %s"
- ;; highlight))
- ;; `(progn
- ;; ,(nth 1 highlight)
- ;; (save-match-data ,(car highlight))
- ;; ,(nth 2 highlight))))
- ;; highlights)))
,(c-make-font-lock-search-form regexp highlights))
-
nil)))
(defun c-make-font-lock-BO-decl-search-function (regexp &rest highlights)
@@ -591,8 +560,7 @@
(progn
(c-mark-<-as-paren beg)
(c-mark->-as-paren end))
- ;; (c-clear-char-property beg 'syntax-table)
- (c-clear-char-property beg 'category)))
+ (c-unmark-<->-as-paren beg)))
nil)))))))
;; #define.
@@ -716,7 +684,11 @@
(let ((start (1- (point))))
(save-excursion
(and (eq (elt (parse-partial-sexp start (c-point 'eol)) 8) start)
- (if (integerp c-multiline-string-start-char)
+ (if (if (eval-when-compile (integerp ?c))
+ ;; Emacs
+ (integerp c-multiline-string-start-char)
+ ;; XEmacs
+ (characterp c-multiline-string-start-char))
;; There's no multiline string start char before the
;; string, so newlines aren't allowed.
(not (eq (char-before start) c-multiline-string-start-char))
@@ -771,6 +743,13 @@
`(,(concat "\\<" (c-lang-const c-regular-keywords-regexp))
1 font-lock-keyword-face))
+ ;; The following must come before c-font-lock-enclosing-decls in
+ ;; c-complex-decl-matchers. It fontifies java @annotations.
+ ,@(when (c-major-mode-is 'java-mode)
+ `((eval . (list "\\<\\(@[a-zA-Z0-9]+\\)\\>" 1
+ c-annotation-face
+ ))))
+
;; Fontify leading identifiers in fully qualified names like
;; "foo::bar" in languages that supports such things.
,@(when (c-lang-const c-opt-identifier-concat-key)
@@ -1151,7 +1130,6 @@
(when list
;; Jump past any initializer or function prototype to see if
;; there's a ',' to continue at.
-
(cond ((eq id-face 'font-lock-function-name-face)
;; Skip a parenthesized initializer (C++) or a function
;; prototype.
@@ -1219,8 +1197,8 @@
;; o - nil, if not in an arglist at all. This includes the
;; parenthesized condition which follows "if", "while", etc.
context
- ;; The position of the next token after the closing paren of
- ;; the last detected cast.
+ ;; A list of starting positions of possible type declarations, or of
+ ;; the typedef preceding one, if any.
last-cast-end
;; The result from `c-forward-decl-or-cast-1'.
decl-or-cast
@@ -1564,9 +1542,7 @@
;; Note that this function won't attempt to fontify beyond the end of the
;; current enum block, if any.
(let* ((paren-state (c-parse-state))
- (encl-pos (c-most-enclosing-brace paren-state))
- (start (point))
- )
+ (encl-pos (c-most-enclosing-brace paren-state)))
(when (and
encl-pos
(eq (char-after encl-pos) ?\{)
@@ -1948,11 +1924,7 @@
"\\)\\>")
'((c-fontify-types-and-refs ((c-promote-possible-types t))
(c-forward-keyword-clause 1)
- (if (> (point) limit) (goto-char limit))))))))
-
- ,@(when (c-major-mode-is 'java-mode)
- `((eval . (list "\\<\\(@[a-zA-Z0-9]+\\)\\>" 1 c-annotation-face))))
- ))
+ (if (> (point) limit) (goto-char limit))))))))))
(c-lang-defconst c-matchers-1
t (c-lang-const c-cpp-matchers))
=== modified file 'lisp/progmodes/cc-guess.el'
--- lisp/progmodes/cc-guess.el 2014-06-26 07:13:13 +0000
+++ lisp/progmodes/cc-guess.el 2014-09-25 18:27:32 +0000
@@ -75,6 +75,9 @@
(cc-require 'cc-defs)
(cc-require 'cc-engine)
(cc-require 'cc-styles)
+(cc-bytecomp-defvar make-progress-reporter)
+(cc-bytecomp-defvar progress-reporter-update)
+(cc-bytecomp-defvar progress-reporter-done)
\f
@@ -519,7 +522,8 @@
(goto-char (point-min))
(when (search-forward (concat "("
(symbol-name (car needs-markers))
- " ") nil t)
+ " ")
+ nil t)
(move-end-of-line 1)
(comment-dwim nil)
(insert " Guessed value"))
=== modified file 'lisp/progmodes/cc-langs.el'
--- lisp/progmodes/cc-langs.el 2014-09-10 21:38:11 +0000
+++ lisp/progmodes/cc-langs.el 2014-09-26 15:07:26 +0000
@@ -130,9 +130,7 @@
;; This file is not always loaded. See note above.
-;; Except it is always loaded - see bug#17463.
-;;;(cc-external-require 'cl)
-(require 'cl-lib)
+(cc-external-require 'cl)
\f
;;; Setup for the `c-lang-defvar' system.
@@ -253,14 +251,14 @@
(unless xlate
(setq xlate 'identity))
(c-with-syntax-table (c-lang-const c-mode-syntax-table)
- (cl-delete-duplicates
- (cl-mapcan (lambda (opgroup)
+ (delete-duplicates
+ (mapcan (lambda (opgroup)
(when (if (symbolp (car opgroup))
(when (funcall opgroup-filter (car opgroup))
(setq opgroup (cdr opgroup))
t)
t)
- (cl-mapcan (lambda (op)
+ (mapcan (lambda (op)
(when (funcall op-filter op)
(let ((res (funcall xlate op)))
(if (listp res) res (list res)))))
@@ -301,7 +299,8 @@
["Set Style..." c-set-style t]
["Show Current Style Name" (message
"Style Name: %s"
- c-indentation-style) t]
+ c-indentation-style)
+ t]
["Guess Style from this Buffer" c-guess-buffer-no-install t]
["Install the Last Guessed Style..." c-guess-install
(and c-guess-guessed-offsets-alist
@@ -319,9 +318,9 @@
:style toggle :selected c-auto-newline]
["Hungry delete" c-toggle-hungry-state
:style toggle :selected c-hungry-delete-key]
- ["Subword mode" subword-mode
- :style toggle :selected (and (boundp 'subword-mode)
- subword-mode)])))
+ ["Subword mode" c-subword-mode
+ :style toggle :selected (and (boundp 'c-subword-mode)
+ c-subword-mode)])))
\f
;;; Syntax tables.
@@ -578,6 +577,15 @@
(c c++ objc) t)
(c-lang-defvar c-has-bitfields (c-lang-const c-has-bitfields))
+(c-lang-defconst c-modified-constant
+ "Regexp that matches a \"modified\" constant literal such as \"L'a'\",
+a \"long character\". In particular, this recognizes forms of constant
+which `c-backward-sexp' needs to be called twice to move backwards over."
+ t nil
+ (c c++ objc) "L'\\([^\\'\t\f\n\r]\\|\\\\.\\)'")
+;; FIXME!!! Extend this to cover strings, if needed. 2008-04-11
+(c-lang-defvar c-modified-constant (c-lang-const c-modified-constant))
+
(c-lang-defconst c-symbol-start
"Regexp that matches the start of a symbol, i.e. any identifier or
keyword. It's unspecified how far it matches. Does not contain a \\|
@@ -1144,7 +1152,8 @@
c++ (append '("&" "<%" "%>" "<:" ":>" "%:" "%:%:")
(c-lang-const c-other-op-syntax-tokens))
objc (append '("#" "##" ; Used by cpp.
- "+" "-") (c-lang-const c-other-op-syntax-tokens))
+ "+" "-")
+ (c-lang-const c-other-op-syntax-tokens))
idl (append '("#" "##") ; Used by cpp.
(c-lang-const c-other-op-syntax-tokens))
pike (append '("..")
@@ -1155,7 +1164,7 @@
(c-lang-defconst c-all-op-syntax-tokens
;; List of all tokens in the punctuation and parenthesis syntax
;; classes.
- t (cl-delete-duplicates (append (c-lang-const c-other-op-syntax-tokens)
+ t (delete-duplicates (append (c-lang-const c-other-op-syntax-tokens)
(c-lang-const c-operator-list))
:test 'string-equal))
@@ -1587,13 +1596,14 @@
(c-lang-defvar c-syntactic-eol (c-lang-const c-syntactic-eol))
\f
-;;; Defun functions
+;;; Defun handling.
-;; The Emacs variables beginning-of-defun-function and
-;; end-of-defun-function will be set so that commands like
-;; `mark-defun' and `narrow-to-defun' work right. The key sequences
-;; C-M-a and C-M-e are, however, bound directly to the CC Mode
-;; functions, allowing optimization for large n.
+;; The Emacs variables beginning-of-defun-function and end-of-defun-function
+;; will be set so that commands like `mark-defun' and `narrow-to-defun' work
+;; right. In older Emacsen, the key sequences C-M-a and C-M-e are, however,
+;; bound directly to the CC Mode functions, allowing optimisation for large n.
+;; From Emacs 23, this isn't necessary any more, since n is passed to the two
+;; functions.
(c-lang-defconst beginning-of-defun-function
"Function to which beginning-of-defun-function will be set."
t 'c-beginning-of-defun
@@ -1754,7 +1764,7 @@
(c-lang-defconst c-type-start-kwds
;; All keywords that can start a type (i.e. are either a type prefix
;; or a complete type).
- t (cl-delete-duplicates (append (c-lang-const c-primitive-type-kwds)
+ t (delete-duplicates (append (c-lang-const c-primitive-type-kwds)
(c-lang-const c-type-prefix-kwds)
(c-lang-const c-type-modifier-kwds))
:test 'string-equal))
@@ -1998,7 +2008,7 @@
;; something is a type or just some sort of macro in front of the
;; declaration. They might be ambiguous with types or type
;; prefixes.
- t (cl-delete-duplicates (append (c-lang-const c-class-decl-kwds)
+ t (delete-duplicates (append (c-lang-const c-class-decl-kwds)
(c-lang-const c-brace-list-decl-kwds)
(c-lang-const c-other-block-decl-kwds)
(c-lang-const c-typedef-decl-kwds)
@@ -2192,7 +2202,7 @@
pike '("array" "function" "int" "mapping" "multiset" "object" "program"))
(c-lang-defconst c-paren-any-kwds
- t (cl-delete-duplicates (append (c-lang-const c-paren-nontype-kwds)
+ t (delete-duplicates (append (c-lang-const c-paren-nontype-kwds)
(c-lang-const c-paren-type-kwds))
:test 'string-equal))
@@ -2218,7 +2228,7 @@
(c-lang-defconst c-<>-sexp-kwds
;; All keywords that can be followed by an angle bracket sexp.
- t (cl-delete-duplicates (append (c-lang-const c-<>-type-kwds)
+ t (delete-duplicates (append (c-lang-const c-<>-type-kwds)
(c-lang-const c-<>-arglist-kwds))
:test 'string-equal))
@@ -2278,7 +2288,7 @@
(c-lang-defconst c-block-stmt-kwds
;; Union of `c-block-stmt-1-kwds' and `c-block-stmt-2-kwds'.
- t (cl-delete-duplicates (append (c-lang-const c-block-stmt-1-kwds)
+ t (delete-duplicates (append (c-lang-const c-block-stmt-1-kwds)
(c-lang-const c-block-stmt-2-kwds))
:test 'string-equal))
@@ -2382,7 +2392,7 @@
(c-lang-defconst c-expr-kwds
;; Keywords that can occur anywhere in expressions. Built from
;; `c-primary-expr-kwds' and all keyword operators in `c-operators'.
- t (cl-delete-duplicates
+ t (delete-duplicates
(append (c-lang-const c-primary-expr-kwds)
(c-filter-ops (c-lang-const c-operator-list)
t
@@ -2486,7 +2496,7 @@
(c-lang-defconst c-keywords
;; All keywords as a list.
- t (cl-delete-duplicates
+ t (delete-duplicates
(c-lang-defconst-eval-immediately
`(append ,@(mapcar (lambda (kwds-lang-const)
`(c-lang-const ,kwds-lang-const))
@@ -2826,7 +2836,7 @@
(c-lang-defvar c-block-prefix-charset (c-lang-const c-block-prefix-charset))
(c-lang-defconst c-type-decl-prefix-key
- "Regexp matching the declarator operators that might precede the
+ "Regexp matching any declarator operator that might precede the
identifier in a declaration, e.g. the \"*\" in \"char *argv\". This
regexp should match \"(\" if parentheses are valid in declarators.
The end of the first submatch is taken as the end of the operator.
@@ -2971,17 +2981,15 @@
(when (boundp (c-mode-symbol "font-lock-extra-types"))
(c-mode-var "font-lock-extra-types")))
(regexp-strings
- (apply 'nconc
- (mapcar (lambda (re)
- (when (string-match "[][.*+?^$\\]" re)
- (list re)))
- extra-types)))
+ (delq nil (mapcar (lambda (re)
+ (when (string-match "[][.*+?^$\\]" re)
+ re))
+ extra-types)))
(plain-strings
- (apply 'nconc
- (mapcar (lambda (re)
- (unless (string-match "[][.*+?^$\\]" re)
- (list re)))
- extra-types))))
+ (delq nil (mapcar (lambda (re)
+ (unless (string-match "[][.*+?^$\\]" re)
+ re))
+ extra-types))))
(concat "\\<\\("
(c-concat-separated
(append (list (c-make-keywords-re nil
@@ -3025,7 +3033,8 @@
expression is considered to be a type."
t (or (consp (c-lang-const c-<>-type-kwds))
(consp (c-lang-const c-<>-arglist-kwds)))
- java t)
+ java t) ; 2008-10-19. This is crude. The syntax for java
+ ; generics is not yet coded in CC Mode.
(c-lang-defvar c-recognize-<>-arglists (c-lang-const c-recognize-<>-arglists))
(c-lang-defconst c-enums-contain-decls
@@ -3249,10 +3258,10 @@
;; `c-lang-const' will expand to the evaluated
;; constant immediately in `macroexpand-all'
;; below.
- (cl-mapcan
+ (mapcan
(lambda (init)
`(current-var ',(car init)
- ,(car init) ,(macroexpand-all
+ ,(car init) ,(c--macroexpand-all
(elt init 1))))
;; Note: The following `append' copies the
;; first argument. That list is small, so
=== modified file 'lisp/progmodes/cc-menus.el'
--- lisp/progmodes/cc-menus.el 2014-01-01 07:43:34 +0000
+++ lisp/progmodes/cc-menus.el 2014-09-25 18:32:58 +0000
@@ -45,6 +45,7 @@
(cc-bytecomp-defvar imenu-case-fold-search)
(cc-bytecomp-defvar imenu-generic-expression)
(cc-bytecomp-defvar imenu-create-index-function)
+(cc-bytecomp-defun imenu-progress-message)
\f
;; imenu integration
@@ -361,7 +362,7 @@
p (1+ p))
(cond
;; Is CHAR part of a objc token?
- ((and (not inargvar) ; Ignore if CHAR is part of an argument variable.
+ ((and (not inargvar) ; Ignore if CHAR is part of an argument variable.
(eq 0 betweenparen) ; Ignore if CHAR is in parentheses.
(or (and (<= ?a char) (<= char ?z))
(and (<= ?A char) (<= char ?Z))
=== modified file 'lisp/progmodes/cc-mode.el'
--- lisp/progmodes/cc-mode.el 2014-09-10 21:38:11 +0000
+++ lisp/progmodes/cc-mode.el 2014-09-25 20:30:37 +0000
@@ -97,7 +97,11 @@
;; Silence the compiler.
(cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs
+(cc-bytecomp-defun set-keymap-parents) ; XEmacs
(cc-bytecomp-defun run-mode-hooks) ; Emacs 21.1
+(cc-bytecomp-defvar normal-erase-is-backspace)
+(cc-bytecomp-defvar file-local-variables-alist)
+(cc-bytecomp-defvar dir-local-variables-alist)
;; We set these variables during mode init, yet we don't require
;; font-lock.
@@ -108,11 +112,6 @@
;; with your version of Emacs, you are incompatible!
(cc-external-require 'easymenu)
-;; Autoload directive for emacsen that doesn't have an older CC Mode
-;; version in the dist.
-(autoload 'subword-mode "subword"
- "Mode enabling subword movement and editing keys." t)
-
;; Load cc-fonts first after font-lock is loaded, since it isn't
;; necessary until font locking is requested.
; (eval-after-load "font-lock" ; 2006-07-09: font-lock is now preloaded.
@@ -185,8 +184,7 @@
(run-hooks 'c-initialization-hook)
;; Fix obsolete variables.
(if (boundp 'c-comment-continuation-stars)
- (setq c-block-comment-prefix
- (symbol-value 'c-comment-continuation-stars)))
+ (setq c-block-comment-prefix c-comment-continuation-stars))
(add-hook 'change-major-mode-hook 'c-leave-cc-mode-mode)
(setq c-initialization-ok t)
;; Connect up with Emacs's electric-indent-mode, for >= Emacs 24.4
@@ -380,7 +378,7 @@
;; conflicts with OOBR
;;(define-key c-mode-base-map "\C-c\C-v" 'c-version)
;; (define-key c-mode-base-map "\C-c\C-y" 'c-toggle-hungry-state) Commented out by ACM, 2005-11-22.
- (define-key c-mode-base-map "\C-c\C-w" 'subword-mode)
+ (define-key c-mode-base-map "\C-c\C-w" 'c-subword-mode)
)
;; We don't require the outline package, but we configure it a bit anyway.
@@ -472,6 +470,14 @@
(defvar c-maybe-stale-found-type nil)
(make-variable-buffer-local 'c-maybe-stale-found-type)
+(defvar c-just-done-before-change nil)
+(make-variable-buffer-local 'c-just-done-before-change)
+;; This variable is set to t by `c-before-change' and to nil by
+;; `c-after-change'. It is used to detect a spurious invocation of
+;; `before-change-functions' directly following on from a correct one. This
+;; happens in some Emacsen, for example when `basic-save-buffer' does (insert
+;; ?\n) when `require-final-newline' is non-nil.
+
(defun c-basic-common-init (mode default-style)
"Do the necessary initialization for the syntax handling routines
and the line breaking/filling code. Intended to be used by other
@@ -542,10 +548,11 @@
;; Use this in Emacs 21+ to avoid meddling with the rear-nonsticky
;; property on each character.
(when (boundp 'text-property-default-nonsticky)
+ (make-local-variable 'text-property-default-nonsticky)
(mapc (lambda (tprop)
(unless (assq tprop text-property-default-nonsticky)
- (set (make-local-variable 'text-property-default-nonsticky)
- (cons `(,tprop . t) text-property-default-nonsticky))))
+ (setq text-property-default-nonsticky
+ (cons `(,tprop . t) text-property-default-nonsticky))))
'(syntax-table category c-type)))
;; In Emacs 21 and later it's possible to turn off the ad-hoc
@@ -601,14 +608,15 @@
;; Install the functions that ensure that various internal caches
;; don't become invalid due to buffer changes.
- (when (featurep 'xemacs)
- (make-local-hook 'before-change-functions)
- (make-local-hook 'after-change-functions))
+ (c--make-local-hook 'before-change-functions)
(add-hook 'before-change-functions 'c-before-change nil t)
+ (setq c-just-done-before-change nil)
+ (c--make-local-hook 'after-change-functions)
(add-hook 'after-change-functions 'c-after-change nil t)
- (set (make-local-variable 'font-lock-extend-after-change-region-function)
- 'c-extend-after-change-region)) ; Currently (2009-05) used by all
- ; languages with #define (C, C++,; ObjC), and by AWK.
+ (when (boundp 'font-lock-extend-after-change-region-function)
+ (set (make-local-variable 'font-lock-extend-after-change-region-function)
+ 'c-extend-after-change-region))) ; Currently (2009-05) used by all
+ ; languages with #define (C, C++,; ObjC), and by AWK.
(defun c-setup-doc-comment-style ()
"Initialize the variables that depend on the value of `c-doc-comment-style'."
@@ -669,9 +677,11 @@
(or (c-cpp-define-name) (c-defun-name))))
(let ((rfn (assq mode c-require-final-newline)))
(when rfn
- (and (cdr rfn)
- (set (make-local-variable 'require-final-newline)
- mode-require-final-newline)))))
+ (if (boundp 'mode-require-final-newline)
+ (and (cdr rfn)
+ (set (make-local-variable 'require-final-newline)
+ mode-require-final-newline))
+ (set (make-local-variable 'require-final-newline) (cdr rfn))))))
(defun c-count-cfss (lv-alist)
;; LV-ALIST is an alist like `file-local-variables-alist'. Count how many
@@ -948,8 +958,11 @@
c-new-END (min (cdr new-bounds) (c-determine-+ve-limit 500 endd)))
;; Clear all old relevant properties.
(c-clear-char-property-with-value c-new-BEG c-new-END 'syntax-table '(1))
- (c-clear-char-property-with-value c-new-BEG c-new-END 'category 'c-cpp-delimiter)
- ;; FIXME!!! What about the "<" and ">" category properties? 2009-11-16
+
+ ;; CPP "comment" markers:
+ (if (eval-when-compile (memq 'category-properties c-emacs-features));Emacs.
+ (c-clear-char-property-with-value
+ c-new-BEG c-new-END 'category 'c-cpp-delimiter))
;; Add needed properties to each CPP construct in the region.
(goto-char c-new-BEG)
@@ -967,8 +980,10 @@
(setq mbeg (point))
(if (> (c-syntactic-end-of-macro) mbeg)
(progn
- (c-neutralize-CPP-line mbeg (point))
- (c-set-cpp-delimiters mbeg (point)))
+ (c-neutralize-CPP-line mbeg (point)) ; "punctuation" properties
+ (if (eval-when-compile
+ (memq 'category-properties c-emacs-features)) ;Emacs.
+ (c-set-cpp-delimiters mbeg (point)))) ; "comment" markers
(forward-line)) ; no infinite loop with, e.g., "#//"
)))))
@@ -988,64 +1003,67 @@
;; it/them from the cache. Don't worry about being inside a string
;; or a comment - "wrongly" removing a symbol from `c-found-types'
;; isn't critical.
- (setq c-maybe-stale-found-type nil)
- (save-restriction
- (save-match-data
- (widen)
- (save-excursion
- ;; Are we inserting/deleting stuff in the middle of an identifier?
- (c-unfind-enclosing-token beg)
- (c-unfind-enclosing-token end)
- ;; Are we coalescing two tokens together, e.g. "fo o" -> "foo"?
- (when (< beg end)
- (c-unfind-coalesced-tokens beg end))
- ;; Are we (potentially) disrupting the syntactic context which
- ;; makes a type a type? E.g. by inserting stuff after "foo" in
- ;; "foo bar;", or before "foo" in "typedef foo *bar;"?
- ;;
- ;; We search for appropriate c-type properties "near" the change.
- ;; First, find an appropriate boundary for this property search.
- (let (lim
- type type-pos
- marked-id term-pos
- (end1
- (or (and (eq (get-text-property end 'face) 'font-lock-comment-face)
- (previous-single-property-change end 'face))
- end)))
- (when (>= end1 beg) ; Don't hassle about changes entirely in comments.
- ;; Find a limit for the search for a `c-type' property
- (while
- (and (/= (skip-chars-backward "^;{}") 0)
- (> (point) (point-min))
- (memq (c-get-char-property (1- (point)) 'face)
- '(font-lock-comment-face font-lock-string-face))))
- (setq lim (max (point-min) (1- (point))))
-
- ;; Look for the latest `c-type' property before end1
- (when (and (> end1 (point-min))
- (setq type-pos
- (if (get-text-property (1- end1) 'c-type)
- end1
- (previous-single-property-change end1 'c-type nil lim))))
- (setq type (get-text-property (max (1- type-pos) lim) 'c-type))
-
- (when (memq type '(c-decl-id-start c-decl-type-start))
- ;; Get the identifier, if any, that the property is on.
- (goto-char (1- type-pos))
- (setq marked-id
- (when (looking-at "\\(\\sw\\|\\s_\\)")
- (c-beginning-of-current-token)
- (buffer-substring-no-properties (point) type-pos)))
-
- (goto-char end1)
- (skip-chars-forward "^;{}") ; FIXME!!! loop for comment, maybe
- (setq lim (point))
- (setq term-pos
- (or (next-single-property-change end 'c-type nil lim) lim))
- (setq c-maybe-stale-found-type
- (list type marked-id
- type-pos term-pos
- (buffer-substring-no-properties type-pos term-pos)
+ (unless c-just-done-before-change ; guard against a spurious second
+ ; invocation of before-change-functions.
+ (setq c-just-done-before-change t)
+ (setq c-maybe-stale-found-type nil)
+ (save-restriction
+ (save-match-data
+ (widen)
+ (save-excursion
+ ;; Are we inserting/deleting stuff in the middle of an identifier?
+ (c-unfind-enclosing-token beg)
+ (c-unfind-enclosing-token end)
+ ;; Are we coalescing two tokens together, e.g. "fo o" -> "foo"?
+ (when (< beg end)
+ (c-unfind-coalesced-tokens beg end))
+ ;; Are we (potentially) disrupting the syntactic context which
+ ;; makes a type a type? E.g. by inserting stuff after "foo" in
+ ;; "foo bar;", or before "foo" in "typedef foo *bar;"?
+ ;;
+ ;; We search for appropriate c-type properties "near" the change.
+ ;; First, find an appropriate boundary for this property search.
+ (let (lim
+ type type-pos
+ marked-id term-pos
+ (end1
+ (or (and (eq (get-text-property end 'face) 'font-lock-comment-face)
+ (previous-single-property-change end 'face))
+ end)))
+ (when (>= end1 beg) ; Don't hassle about changes entirely in comments.
+ ;; Find a limit for the search for a `c-type' property
+ (while
+ (and (/= (skip-chars-backward "^;{}") 0)
+ (> (point) (point-min))
+ (memq (c-get-char-property (1- (point)) 'face)
+ '(font-lock-comment-face font-lock-string-face))))
+ (setq lim (max (point-min) (1- (point))))
+
+ ;; Look for the latest `c-type' property before end1
+ (when (and (> end1 (point-min))
+ (setq type-pos
+ (if (get-text-property (1- end1) 'c-type)
+ end1
+ (previous-single-property-change end1 'c-type nil lim))))
+ (setq type (get-text-property (max (1- type-pos) lim) 'c-type))
+
+ (when (memq type '(c-decl-id-start c-decl-type-start))
+ ;; Get the identifier, if any, that the property is on.
+ (goto-char (1- type-pos))
+ (setq marked-id
+ (when (looking-at "\\(\\sw\\|\\s_\\)")
+ (c-beginning-of-current-token)
+ (buffer-substring-no-properties (point) type-pos)))
+
+ (goto-char end1)
+ (skip-chars-forward "^;{}") ; FIXME!!! loop for comment, maybe
+ (setq lim (point))
+ (setq term-pos
+ (or (c-next-single-property-change end 'c-type nil lim) lim))
+ (setq c-maybe-stale-found-type
+ (list type marked-id
+ type-pos term-pos
+ (buffer-substring-no-properties type-pos term-pos)
(buffer-substring-no-properties beg end)))))))
(if c-get-state-before-change-functions
@@ -1056,7 +1074,7 @@
)))
;; The following must be done here rather than in `c-after-change' because
;; newly inserted parens would foul up the invalidation algorithm.
- (c-invalidate-state-cache beg))
+ (c-invalidate-state-cache beg)))
(defvar c-in-after-change-fontification nil)
(make-variable-buffer-local 'c-in-after-change-fontification)
@@ -1077,6 +1095,7 @@
;; This calls the language variable c-before-font-lock-functions, if non nil.
;; This typically sets `syntax-table' properties.
+ (setq c-just-done-before-change nil)
(c-save-buffer-state (case-fold-search open-paren-in-column-0-is-defun-start)
;; When `combine-after-change-calls' is used we might get calls
;; with regions outside the current narrowing. This has been
@@ -1097,11 +1116,12 @@
;; C-y is capable of spuriously converting category properties
;; c-</>-as-paren-syntax and c-cpp-delimiter into hard syntax-table
;; properties. Remove these when it happens.
- (c-clear-char-property-with-value beg end 'syntax-table
- c-<-as-paren-syntax)
- (c-clear-char-property-with-value beg end 'syntax-table
- c->-as-paren-syntax)
- (c-clear-char-property-with-value beg end 'syntax-table nil)
+ (when (eval-when-compile (memq 'category-properties c-emacs-features))
+ (c-clear-char-property-with-value beg end 'syntax-table
+ c-<-as-paren-syntax)
+ (c-clear-char-property-with-value beg end 'syntax-table
+ c->-as-paren-syntax)
+ (c-clear-char-property-with-value beg end 'syntax-table nil))
(c-trim-found-types beg end old-len) ; maybe we don't need all of these.
(c-invalidate-sws-region-after beg end)
@@ -1235,10 +1255,10 @@
(make-local-variable 'font-lock-fontify-region-function)
(setq font-lock-fontify-region-function 'c-font-lock-fontify-region)
- (if (featurep 'xemacs)
- (make-local-hook 'font-lock-mode-hook))
+ (c--make-local-hook 'font-lock-mode-hook)
(add-hook 'font-lock-mode-hook 'c-after-font-lock-init nil t))
+;; Emacs 22 and later.
(defun c-extend-after-change-region (_beg _end _old-len)
"Extend the region to be fontified, if necessary."
;; Note: the parameters are ignored here. This somewhat indirect
@@ -1252,6 +1272,21 @@
;; function.
(cons c-new-BEG c-new-END))
+;; Emacs < 22 and XEmacs
+(defmacro c-advise-fl-for-region (function)
+ `(defadvice ,function (before get-awk-region activate)
+ ;; Make sure that any string/regexp is completely font-locked.
+ (when c-buffer-is-cc-mode
+ (save-excursion
+ (ad-set-arg 1 c-new-END) ; end
+ (ad-set-arg 0 c-new-BEG))))) ; beg
+
+(unless (boundp 'font-lock-extend-after-change-region-function)
+ (c-advise-fl-for-region font-lock-after-change-function)
+ (c-advise-fl-for-region jit-lock-after-change)
+ (c-advise-fl-for-region lazy-lock-defer-rest-after-change)
+ (c-advise-fl-for-region lazy-lock-defer-line-after-change))
+
;; Connect up to `electric-indent-mode' (Emacs 24.4 and later).
(defun c-electric-indent-mode-hook ()
;; Emacs has en/disabled `electric-indent-mode'. Propagate this through to
@@ -1322,6 +1357,7 @@
;;;###autoload (add-to-list 'auto-mode-alist '("\\.i\\'" . c-mode))
;;;###autoload (add-to-list 'auto-mode-alist '("\\.ii\\'" . c++-mode))
+(unless (fboundp 'prog-mode) (defalias 'prog-mode 'fundamental-mode))
;;;###autoload
(define-derived-mode c-mode prog-mode "C"
=== modified file 'lisp/progmodes/cc-styles.el'
--- lisp/progmodes/cc-styles.el 2014-01-01 07:43:34 +0000
+++ lisp/progmodes/cc-styles.el 2014-09-25 18:44:14 +0000
@@ -645,7 +645,7 @@
(mapc func varsyms)
;; Hooks must be handled specially
(if this-buf-only-p
- (if (featurep 'xemacs) (make-local-hook 'c-special-indent-hook))
+ (c--make-local-hook 'c-special-indent-hook)
(with-no-warnings (make-variable-buffer-local 'c-special-indent-hook))
(setq c-style-variables-are-local-p t))
))
=== modified file 'lisp/progmodes/cc-vars.el'
--- lisp/progmodes/cc-vars.el 2014-01-01 07:43:34 +0000
+++ lisp/progmodes/cc-vars.el 2014-09-25 21:16:12 +0000
@@ -42,6 +42,9 @@
(cc-require 'cc-defs)
+;; Silence the compiler.
+(cc-bytecomp-defun get-char-table) ; XEmacs
+
(cc-eval-when-compile
(require 'custom)
(require 'widget))
@@ -185,14 +188,14 @@
`c-style-alist') when a CC Mode buffer is initialized. Otherwise,
the value set here overrides the style system (there is a variable
`c-old-style-variable-behavior' that changes this, though)."))
- (typ (eval (plist-get args :type)))
+ (typ (eval (c-safe (plist-get args :type))))
(type (if (consp typ) typ (list typ)))
(head (car type))
(tail (cdr type))
- (newt (append (unless (plist-get tail :tag)
+ (newt (append (unless (c-safe (plist-get tail :tag))
'(:tag "Override style settings"))
- (unless (plist-get tail :value)
- `(:value ,(eval val)))
+ (unless (c-safe (plist-get tail :value))
+ `(:value ,val))
tail))
(aggregate `'(radio
(const :tag "Use style settings" set-from-style)
@@ -275,13 +278,18 @@
"*Controls the operation of the TAB key.
If t, hitting TAB always just indents the current line. If nil, hitting
TAB indents the current line if point is at the left margin or in the
-line's indentation, otherwise it calls `c-insert-tab-function' to
-insert a `real' tab character. If some other value (neither nil nor t),
-then inserts a tab only within literals (comments and strings), but
-always reindents the line.
-
-Note: the variable `c-comment-only-line-offset' also controls the
-indentation of lines containing only comments."
+line's indentation, otherwise it inserts a `real' tab character \(see
+note\). If some other value (not nil or t), then tab is inserted only
+within literals \(comments and strings), but the line is always
+reindented.
+
+Note: The value of `indent-tabs-mode' will determine whether a real
+tab character will be inserted, or the equivalent number of spaces.
+When inserting a tab, actually the function stored in the variable
+`c-insert-tab-function' is called.
+
+Note: indentation of lines containing only comments is also controlled
+by the `c-comment-only-line-offset' variable."
:type '(radio
(const :tag "TAB key always indents, never inserts TAB" t)
(const :tag "TAB key indents in left margin, otherwise inserts TAB" nil)
@@ -456,7 +463,8 @@
:group 'c)
(make-obsolete-variable 'c-comment-continuation-stars
- 'c-block-comment-prefix "21.1")
+ 'c-block-comment-prefix
+ nil)
;; Although c-comment-continuation-stars is obsolete, we look at it in
;; some places in CC Mode anyway, so make the compiler ignore it
@@ -920,7 +928,7 @@
(defcustom c-special-indent-hook nil
"*Hook for user defined special indentation adjustments.
This hook gets called after each line is indented by the mode. It is only
-called if `c-syntactic-indentation' is non-nil."
+called when `c-syntactic-indentation' is non-nil."
:type 'hook
:group 'c)
@@ -1689,7 +1697,8 @@
;; It isn't possible to specify a doc-string without specifying an
;; initial value with `defvar', so the following two variables have been
;; given doc-strings by setting the property `variable-documentation'
-;; directly. It's really good not to have an initial value for
+;; directly. C-h v will read this documentation only for versions of GNU
+;; Emacs from 22.1. It's really good not to have an initial value for
;; variables like these that always should be dynamically bound, so it's
;; worth the inconvenience.
next prev parent reply other threads:[~2014-09-26 19:19 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-02 5:26 POC: customizable cc-mode keywords Daniel Colascione
2014-05-10 23:13 ` Daniel Colascione
2014-05-11 21:13 ` Alan Mackenzie
2014-05-11 21:23 ` Daniel Colascione
2014-05-16 17:52 ` Alan Mackenzie
2014-05-16 18:06 ` Daniel Colascione
2014-05-18 21:33 ` Alan Mackenzie
2014-05-18 22:28 ` Daniel Colascione
2014-05-19 2:25 ` Stefan Monnier
2014-05-25 18:08 ` Alan Mackenzie
2014-09-08 17:28 ` Stefan Monnier
2014-09-11 13:55 ` Further CC-mode changes Stefan Monnier
2014-09-12 23:59 ` Alan Mackenzie
2014-09-13 1:09 ` Ivan Andrus
2014-09-13 10:04 ` Alan Mackenzie
2014-09-13 3:04 ` Stefan Monnier
2014-09-13 15:10 ` Alan Mackenzie
2014-09-13 19:24 ` Stefan Monnier
2014-09-13 23:08 ` Syntax-propertize and CC-mode [Was: Further CC-mode changes] Alan Mackenzie
2014-09-14 4:04 ` Stefan Monnier
2014-09-16 17:30 ` Sync'ing cc-mode Stefan Monnier
2014-09-26 19:19 ` Stefan Monnier [this message]
[not found] ` <jwv4mvmjl0c.fsf-monnier+emacs@gnu.org>
[not found] ` <jwv4mvkqy4g.fsf-monnier+emacs@gnu.org>
[not found] ` <jwv4mv3mn2a.fsf-monnier+emacs@gnu.org>
[not found] ` <jwv38a644p7.fsf-monnier+emacs@gnu.org>
[not found] ` <jwvppd2wx7o.fsf-monnier+emacs@gnu.org>
[not found] ` <20141106104534.GA3385@acm.acm>
2014-11-06 14:06 ` bug#18022: " Stefan Monnier
2014-09-15 20:24 ` Further CC-mode changes Glenn Morris
2014-09-16 3:07 ` Stephen J. Turnbull
2014-09-16 13:39 ` Stefan Monnier
2014-09-16 14:22 ` David Kastrup
2014-09-16 23:40 ` Stephen J. Turnbull
2014-09-17 1:02 ` Stefan Monnier
2014-09-17 1:48 ` Stephen J. Turnbull
2014-09-17 5:22 ` David Kastrup
2014-09-17 13:00 ` Stefan Monnier
2014-09-17 18:31 ` Glenn Morris
2014-09-17 19:12 ` David Kastrup
2014-09-17 5:24 ` Eli Zaretskii
2014-09-17 6:54 ` Stephen J. Turnbull
2014-09-17 7:20 ` Eli Zaretskii
2014-09-17 7:30 ` David Kastrup
2014-09-17 13:04 ` Stefan Monnier
2014-09-17 18:25 ` Glenn Morris
2014-09-18 5:20 ` Stephen J. Turnbull
2014-09-18 9:44 ` Emilio Lopes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvzjdm9pb6.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=acm@muc.de \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.