]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/cc-defs.el
Handle initial comments.
[gnu-emacs] / lisp / progmodes / cc-defs.el
index 132019618c69036802dc02c69716d4d75bff8d55..ad8b8a92bffb021c81ca3797c23557de1de5a453 100644 (file)
               font-lock-keywords)))
       (cc-load "cc-fix")))
 
-(cc-external-require 'cl)
+(eval-when-compile (require 'cl))
 
 \f
 ;;; Variables also used at compile time.
 
-(defconst c-version "5.30.3"
+(defconst c-version "5.30.8"
   "CC Mode version number.")
 
 (defconst c-version-sym (intern c-version))
   "Non-nil for all buffers with a major mode derived from CC Mode.
 Otherwise, this variable is nil.  I.e. this variable is non-nil for
 `c-mode', `c++-mode', `objc-mode', `java-mode', `idl-mode',
-`pike-mode', and any other non-CC Mode mode that calls
-`c-initialize-cc-mode' (e.g. `awk-mode').  The value is the mode
-symbol itself (i.e. `c-mode' etc) of the original CC Mode mode, or
-just t if it's not known.")
+`pike-mode', `awk-mode', and any other non-CC Mode mode that calls
+`c-initialize-cc-mode'.  The value is the mode symbol itself
+\(i.e. `c-mode' etc) of the original CC Mode mode, or just t if it's
+not known.")
 (make-variable-buffer-local 'c-buffer-is-cc-mode)
 
 ;; Have to make `c-buffer-is-cc-mode' permanently local so that it
@@ -864,19 +864,57 @@ This function does not do any hidden buffer changes."
   ;; This function does not do any hidden buffer changes.
   (assq (car (c-intersect-lists list alist1)) alist2))
 
-(defsubst c-langelem-col (langelem &optional preserve-point)
-  "Convenience routine to return the column of LANGELEM's relpos.
-Leaves point at the relpos unless PRESERVE-POINT is non-nil.
+(defsubst c-langelem-sym (langelem)
+  "Return the syntactic symbol in LANGELEM.
+
+LANGELEM is a syntactic element, i.e. either a cons cell on the
+\"old\" form given as the first argument to lineup functions or a list
+on the \"new\" form as used in `c-syntactic-element'.
+
+This function does not do any hidden buffer changes."
+  (car langelem))
+
+(defsubst c-langelem-pos (langelem)
+  "Return the (primary) anchor position in LANGELEM, or nil if there is none.
+
+LANGELEM is a syntactic element, i.e. either a cons cell on the
+\"old\" form given as the first argument to lineup functions or a list
+on the \"new\" form as used in `c-syntactic-element'.
 
 This function does not do any hidden buffer changes."
-  (if (cdr langelem)
-      (let ((here (point)))
-       (goto-char (cdr langelem))
-       (prog1 (current-column)
-         (if preserve-point
-             (goto-char here))
-         ))
-    0))
+  (if (consp (cdr langelem))
+      (car-safe (cdr langelem))
+    (cdr langelem)))
+
+(defun c-langelem-col (langelem &optional preserve-point)
+  "Return the column of the (primary) anchor position in LANGELEM.
+Leave point at that position unless PRESERVE-POINT is non-nil.
+
+LANGELEM is a syntactic element, i.e. either a cons cell on the
+\"old\" form given as the first argument to lineup functions or a list
+on the \"new\" form as used in `c-syntactic-element'.
+
+This function does not do any hidden buffer changes."
+  (let ((pos (c-langelem-pos langelem))
+       (here (point)))
+    (if pos
+       (progn
+         (goto-char pos)
+         (prog1 (current-column)
+           (if preserve-point
+               (goto-char here))))
+      0)))
+
+(defsubst c-langelem-2nd-pos (langelem)
+  "Return the secondary position in LANGELEM, or nil if there is none.
+
+LANGELEM is a syntactic element, typically on the \"new\" form as used
+in `c-syntactic-element'.  It may be on the \"old\" form that is used
+as the first argument to lineup functions, but then the returned value
+always will be nil.
+
+This function does not do any hidden buffer changes."
+  (car-safe (cdr-safe (cdr-safe langelem))))
 
 (defsubst c-keep-region-active ()
   ;; Do whatever is necessary to keep the region active in XEmacs.
@@ -963,8 +1001,8 @@ This function does not do any hidden buffer changes."
 
 (defun c-make-keywords-re (adorn list &optional mode)
   "Make a regexp that matches all the strings the list.
-Duplicates in the list are removed.  The regexp may contain zero or
-more submatch expressions.
+Duplicates in the list are removed.  The resulting regexp may contain
+zero or more submatch expressions.
 
 If ADORN is non-nil there will be at least one submatch and the first
 matches the whole keyword, and the regexp will also not match a prefix
@@ -972,6 +1010,7 @@ of any identifier.  Adorned regexps cannot be appended.  The language
 variable `c-nonsymbol-key' is used to make the adornment.  The
 optional MODE specifies the language to get it in.  The default is the
 current language (taken from `c-buffer-is-cc-mode')."
+
   (let (unique)
     (dolist (elt list)
       (unless (member elt unique)
@@ -979,6 +1018,27 @@ current language (taken from `c-buffer-is-cc-mode')."
     (setq list unique))
   (if list
       (let ((re (c-regexp-opt list)))
+
+       ;; Emacs < 21 and XEmacs (all versions so far) has a buggy
+       ;; regexp-opt that doesn't always cope with strings containing
+       ;; newlines.  This kludge doesn't handle shy parens correctly
+       ;; so we can't advice regexp-opt directly with it.
+       (let (fail-list)
+         (while list
+           (and (string-match "\n" (car list)) ; To speed it up a little.
+                (not (string-match (concat "\\`\\(" re "\\)\\'")
+                                   (car list)))
+                (setq fail-list (cons (car list) fail-list)))
+           (setq list (cdr list)))
+         (when fail-list
+           (setq re (concat re
+                            "\\|"
+                            (mapconcat 'regexp-quote
+                                       (sort fail-list
+                                             (lambda (a b)
+                                               (> (length a) (length b))))
+                                       "\\|")))))
+
        ;; Add our own grouping parenthesis around re instead of
        ;; passing adorn to `regexp-opt', since in XEmacs it makes the
        ;; top level grouping "shy".
@@ -988,10 +1048,12 @@ current language (taken from `c-buffer-is-cc-mode')."
                    (c-get-lang-constant 'c-nonsymbol-key nil mode)
                    "\\|$\\)")
          re))
+
     ;; Produce a regexp that matches nothing.
     (if adorn
        "\\(\\<\\>\\)"
       "\\<\\>")))
+
 (put 'c-make-keywords-re 'lisp-indent-function 1)
 
 \f
@@ -1526,4 +1588,5 @@ This macro does not do any hidden buffer changes."
 \f
 (cc-provide 'cc-defs)
 
+;;; arch-tag: 3bb2629d-dd84-4ff0-ad39-584be0fe3cda
 ;;; cc-defs.el ends here