]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/cc-cmds.el
Merge from mainline.
[gnu-emacs] / lisp / progmodes / cc-cmds.el
index 391e8b2cb56fb65bd91a8ed7ac81518ba039ff17..5ac30bc28ce1e94fbf286bf0802dc921025304c1 100644 (file)
@@ -1,18 +1,17 @@
 ;;; cc-cmds.el --- user level commands for CC Mode
 
-;; Copyright (C) 1985, 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-;;   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
-;;   Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1987, 1992-2011  Free Software Foundation, Inc.
 
 ;; Authors:    2003- Alan Mackenzie
 ;;             1998- Martin Stjernholm
 ;;             1992-1999 Barry A. Warsaw
-;;             1987 Dave Detlefs and Stewart Clamen
+;;             1987 Dave Detlefs
+;;             1987 Stewart Clamen
 ;;             1985 Richard M. Stallman
 ;; Maintainer: bug-cc-mode@gnu.org
 ;; Created:    22-Apr-1997 (split from cc-mode.el)
-;; Version:    See cc-mode.el
-;; Keywords:   c languages oop
+;; Keywords:   c languages
+;; Package:    cc-mode
 
 ;; This file is part of GNU Emacs.
 
@@ -49,8 +48,6 @@
 (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)
@@ -262,13 +259,15 @@ With universal argument, inserts the analysis as a comment on that line."
                         "a" "")
                     (if c-hungry-delete-key "h" "")
                     (if (and
-                         ;; cc-subword might not be loaded.
-                         (boundp 'c-subword-mode)
-                         (symbol-value 'c-subword-mode))
+                         ;; subword might not be loaded.
+                         (boundp 'subword-mode)
+                         (symbol-value 'subword-mode))
                         "w"
                       "")))
+        ;; FIXME: Derived modes might want to use something else
+        ;; than a string for `mode-name'.
        (bare-mode-name (if (string-match "\\(^[^/]*\\)/" mode-name)
-                           (substring mode-name (match-beginning 1) (match-end 1))
+                           (match-string 1 mode-name)
                          mode-name)))
 ;;     (setq c-submode-indicators
 ;;       (if (> (length fmt) 1)
@@ -321,7 +320,7 @@ after special characters such as brace, comma, semi-colon, and colon."
   (c-keep-region-active))
 
 (defalias 'c-toggle-auto-state 'c-toggle-auto-newline)
-(make-obsolete 'c-toggle-auto-state 'c-toggle-auto-newline)
+(make-obsolete 'c-toggle-auto-state 'c-toggle-auto-newline "22.1")
 
 (defun c-toggle-hungry-state (&optional arg)
   "Toggle hungry-delete-key feature.
@@ -476,7 +475,7 @@ inside a literal or a macro, nothing special happens."
          (bolp (bolp)))
       (beginning-of-line)
       (delete-horizontal-space)
-      (insert last-command-char)
+      (insert last-command-event)
       (and (not bolp)
           (goto-char (- (point-max) pos)))
       )))
@@ -522,7 +521,7 @@ inside a literal or a macro, nothing special happens."
        ;; This is the list of brace syntactic symbols that can hang.
        ;; If any new ones are added to c-offsets-alist, they should be
        ;; added here as well.
-       ;; 
+       ;;
        ;; The order of this list is important; if SYNTAX has several
        ;; elements, the element that "wins" is the earliest in SYMS.
        '(arglist-cont-nonempty         ; e.g. an array literal.
@@ -735,7 +734,7 @@ settings of `c-cleanup-list' are done."
              ;; `}': clean up empty defun braces
              (when (c-save-buffer-state ()
                      (and (memq 'empty-defun-braces c-cleanup-list)
-                          (eq last-command-char ?\})
+                          (eq last-command-event ?\})
                           (c-intersect-lists '(defun-close class-close inline-close)
                                              syntax)
                           (progn
@@ -751,14 +750,14 @@ settings of `c-cleanup-list' are done."
              ;; `}': compact to a one-liner defun?
              (save-match-data
                (when
-                   (and (eq last-command-char ?\})
+                   (and (eq last-command-event ?\})
                         (memq 'one-liner-defun c-cleanup-list)
                         (c-intersect-lists '(defun-close) syntax)
                         (c-try-one-liner))
                  (setq here (- (point-max) pos))))
 
              ;; `{': clean up brace-else-brace and brace-elseif-brace
-             (when (eq last-command-char ?\{)
+             (when (eq last-command-event ?\{)
                (cond
                 ((and (memq 'brace-else-brace c-cleanup-list)
                       (re-search-backward
@@ -812,7 +811,7 @@ settings of `c-cleanup-list' are done."
            ))))
 
     ;; blink the paren
-    (and (eq last-command-char ?\})
+    (and (eq last-command-event ?\})
         (not executing-kbd-macro)
         old-blink-paren
         (save-excursion
@@ -849,7 +848,7 @@ is inhibited."
     (when (and (not arg)
               (eq literal 'c)
               (memq 'comment-close-slash c-cleanup-list)
-              (eq last-command-char ?/)
+              (eq last-command-event ?/)
               (looking-at (concat "[ \t]*\\("
                                   (regexp-quote comment-end) "\\)?$"))
        ; (eq c-block-comment-ender "*/") ; C-style comments ALWAYS end in */
@@ -865,7 +864,7 @@ is inhibited."
     (setq indentp (and (not arg)
                       c-syntactic-indentation
                       c-electric-flag
-                      (eq last-command-char ?/)
+                      (eq last-command-event ?/)
                       (eq (char-before) (if literal ?* ?/))))
     (self-insert-command (prefix-numeric-value arg))
     (if indentp
@@ -939,10 +938,10 @@ settings of `c-cleanup-list'."
          (let ((pos (- (point-max) (point))))
            (if (c-save-buffer-state ()
                  (and (or (and
-                           (eq last-command-char ?,)
+                           (eq last-command-event ?,)
                            (memq 'list-close-comma c-cleanup-list))
                           (and
-                           (eq last-command-char ?\;)
+                           (eq last-command-event ?\;)
                            (memq 'defun-close-semi c-cleanup-list)))
                       (progn
                         (forward-char -1)
@@ -1087,104 +1086,76 @@ numeric argument is supplied, or the point is inside a literal."
 
   (interactive "*P")
   (let ((c-echo-syntactic-information-p nil)
-       final-pos close-paren-inserted)
+       final-pos close-paren-inserted found-delim)
 
     (self-insert-command (prefix-numeric-value arg))
     (setq final-pos (point))
 
-    (c-save-buffer-state (c-parse-and-markup-<>-arglists
-                         c-restricted-<>-arglists
-                         <-pos)
+;;;; 2010-01-31: There used to be code here to put a syntax-table text
+;;;; property on the new < or > and its mate (if any) when they are template
+;;;; parens.  This is now done in an after-change function.
 
-      (when c-recognize-<>-arglists
-       (if (eq last-command-char ?<)
-           (when (and (progn
-                        (backward-char)
-                        (= (point)
-                           (progn
-                             (c-beginning-of-current-token)
-                             (point))))
+    ;; Indent the line if appropriate.
+    (when (and c-electric-flag c-syntactic-indentation c-recognize-<>-arglists)
+      (setq found-delim
+           (if (eq last-command-event ?<)
+               ;; If a <, basically see if it's got "template" before it .....
+               (or (and (progn
+                          (backward-char)
+                          (= (point)
+                             (progn (c-beginning-of-current-token) (point))))
+                        (progn
+                          (c-backward-token-2)
+                          (looking-at c-opt-<>-sexp-key)))
+                   ;; ..... or is a C++ << operator.
+                   (and (c-major-mode-is 'c++-mode)
+                        (progn
+                          (goto-char (1- final-pos))
+                          (c-beginning-of-current-token)
+                          (looking-at "<<"))
+                        (>= (match-end 0) final-pos)))
+
+             ;; It's a >.  Either a C++ >> operator. ......
+             (or (and (c-major-mode-is 'c++-mode)
                       (progn
-                        (c-backward-token-2)
-                        (looking-at c-opt-<>-sexp-key)))
-             (c-mark-<-as-paren (1- final-pos)))
-
-         ;; It's a ">".  Check if there's an earlier "<" which either has
-         ;; open paren syntax already or that can be recognized as an arglist
-         ;; together with this ">".  Note that this won't work in cases like
-         ;; "template <x, a < b, y>" but they ought to be rare.
-
-         (save-restriction
-           ;; Narrow to avoid that `c-forward-<>-arglist' below searches past
-           ;; our position.
-           (narrow-to-region (point-min) final-pos)
-
-           (while (and
-                   (progn
-                     (goto-char final-pos)
-                     (c-syntactic-skip-backward "^<;}" nil t)
-                     (eq (char-before) ?<))
-                   (progn
-                     (backward-char)
-                     ;; If the "<" already got open paren syntax we know we
-                     ;; have the matching closer.  Handle it and exit the
-                     ;; loop.
-                     (if (looking-at "\\s\(")
-                         (progn
-                           (c-mark->-as-paren (1- final-pos))
-                           (setq close-paren-inserted t)
-                           nil)
-                       t))
+                        (goto-char (1- final-pos))
+                        (c-beginning-of-current-token)
+                        (looking-at ">>"))
+                      (>= (match-end 0) final-pos))
+                 ;; ...., or search back for a < which isn't already marked as an
+                 ;; opening template delimiter.
+                 (save-restriction
+                   (widen)
+                   ;; Narrow to avoid `c-forward-<>-arglist' below searching past
+                   ;; our position.
+                   (narrow-to-region (point-min) final-pos)
+                   (goto-char final-pos)
+                   (while
+                       (and
+                        (progn
+                          (c-syntactic-skip-backward "^<;}" nil t)
+                          (eq (char-before) ?<))
+                        (progn
+                          (backward-char)
+                          (looking-at "\\s\("))))
+                   (and (eq (char-after) ?<)
+                        (not (looking-at "\\s\("))
+                        (progn (c-backward-syntactic-ws)
+                               (c-simple-skip-symbol-backward))
+                        (or (looking-at c-opt-<>-sexp-key)
+                            (not (looking-at c-keywords-regexp)))))))))
 
-                   (progn
-                     (setq <-pos (point))
-                     (c-backward-syntactic-ws)
-                     (c-simple-skip-symbol-backward))
-                   (or (looking-at c-opt-<>-sexp-key)
-                       (not (looking-at c-keywords-regexp)))
-
-                   (let ((c-parse-and-markup-<>-arglists t)
-                         c-restricted-<>-arglists
-                         (containing-sexp
-                          (c-most-enclosing-brace (c-parse-state))))
-                     (when (and containing-sexp
-                                (progn (goto-char containing-sexp)
-                                       (eq (char-after) ?\())
-                                (not (eq (get-text-property (point) 'c-type)
-                                         'c-decl-arg-start)))
-                       (setq c-restricted-<>-arglists t))
-                     (goto-char <-pos)
-                     (c-forward-<>-arglist nil))
-
-                   ;; Loop here if the "<" we found above belongs to a nested
-                   ;; angle bracket sexp.  When we start over we'll find the
-                   ;; previous or surrounding sexp.
-                   (if (< (point) final-pos)
-                       t
-                     (setq close-paren-inserted t)
-                     nil)))))))
     (goto-char final-pos)
-
-    ;; Indent the line if appropriate.
-    (when (and c-electric-flag c-syntactic-indentation)
-      (backward-char)
-      (when (prog1 (or (looking-at "\\s\(\\|\\s\)")
-                      (and (c-major-mode-is 'c++-mode)
-                           (progn
-                             (c-beginning-of-current-token)
-                             (looking-at "<<\\|>>"))
-                           (= (match-end 0) final-pos)))
-             (goto-char final-pos))
-       (indent-according-to-mode)))
-
-    (when (and close-paren-inserted
-              (not executing-kbd-macro)
-              blink-paren-function)
-      ;; Note: Most paren blink functions, such as the standard
-      ;; `blink-matching-open', currently doesn't handle paren chars
-      ;; marked with text properties very well.  Maybe we should avoid
-      ;; this call for the time being?
-      (funcall blink-paren-function))))
+    (when found-delim
+      (indent-according-to-mode)
+      (when (and (eq (char-before) ?>)
+                (not executing-kbd-macro)
+                blink-paren-function)
+           ;; Note: Most paren blink functions, such as the standard
+           ;; `blink-matching-open', currently doesn't handle paren chars
+           ;; marked with text properties very well.  Maybe we should avoid
+           ;; this call for the time being?
+           (funcall blink-paren-function)))))
 
 (defun c-electric-paren (arg)
   "Insert a parenthesis.
@@ -1220,7 +1191,7 @@ newline cleanups are done if appropriate; see the variable `c-cleanup-list'."
            ;; clean up brace-elseif-brace
            (when
                (and (memq 'brace-elseif-brace c-cleanup-list)
-                    (eq last-command-char ?\()
+                    (eq last-command-event ?\()
                     (re-search-backward
                      (concat "}"
                              "\\([ \t\n]\\|\\\\\n\\)*"
@@ -1238,7 +1209,7 @@ newline cleanups are done if appropriate; see the variable `c-cleanup-list'."
            ;; clean up brace-catch-brace
            (when
                (and (memq 'brace-catch-brace c-cleanup-list)
-                    (eq last-command-char ?\()
+                    (eq last-command-event ?\()
                     (re-search-backward
                      (concat "}"
                              "\\([ \t\n]\\|\\\\\n\\)*"
@@ -1259,7 +1230,7 @@ newline cleanups are done if appropriate; see the variable `c-cleanup-list'."
 
             ;; space-before-funcall clean-up?
             ((and (memq 'space-before-funcall c-cleanup-list)
-                  (eq last-command-char ?\()
+                  (eq last-command-event ?\()
                   (save-excursion
                     (backward-char)
                     (skip-chars-backward " \t")
@@ -1277,7 +1248,7 @@ newline cleanups are done if appropriate; see the variable `c-cleanup-list'."
             ;; compact-empty-funcall clean-up?
                  ((c-save-buffer-state ()
                     (and (memq 'compact-empty-funcall c-cleanup-list)
-                         (eq last-command-char ?\))
+                         (eq last-command-event ?\))
                          (save-excursion
                            (c-safe (backward-char 2))
                            (when (looking-at "()")
@@ -1306,7 +1277,7 @@ keyword on the line, the keyword is not inserted inside a literal, and
     (when (c-save-buffer-state ()
            (and c-electric-flag
                 c-syntactic-indentation
-                (not (eq last-command-char ?_))
+                (not (eq last-command-event ?_))
                 (= (save-excursion
                      (skip-syntax-backward "w")
                      (point))
@@ -1323,20 +1294,24 @@ keyword on the line, the keyword is not inserted inside a literal, and
        (delete-char -2)))))
 
 \f
+
+(declare-function subword-forward "subword" (&optional arg))
+(declare-function subword-backward "subword" (&optional arg))
+
 ;; "nomenclature" functions + c-scope-operator.
 (defun c-forward-into-nomenclature (&optional arg)
   "Compatibility alias for `c-forward-subword'."
   (interactive "p")
-  (require 'cc-subword)
-  (c-forward-subword arg))
-(make-obsolete 'c-forward-into-nomenclature 'c-forward-subword)
+  (require 'subword)
+  (subword-forward arg))
+(make-obsolete 'c-forward-into-nomenclature 'subword-forward "23.2")
 
 (defun c-backward-into-nomenclature (&optional arg)
   "Compatibility alias for `c-backward-subword'."
   (interactive "p")
-  (require 'cc-subword)
-  (c-backward-subword arg))
-(make-obsolete 'c-backward-into-nomenclature 'c-backward-subword)
+  (require 'subword)
+  (subword-backward arg))
+(make-obsolete 'c-backward-into-nomenclature 'subword-backward "23.2")
 
 (defun c-scope-operator ()
   "Insert a double colon scope operator at point.
@@ -1526,6 +1501,11 @@ defun."
   (interactive "p")
   (or arg (setq arg 1))
 
+  (or (not (eq this-command 'c-beginning-of-defun))
+      (eq last-command 'c-beginning-of-defun)
+      (and transient-mark-mode mark-active)
+      (push-mark))
+
   (c-save-buffer-state
       (beginning-of-defun-function end-of-defun-function
        (start (point))
@@ -1629,6 +1609,11 @@ the open-parenthesis that starts a defun; see `beginning-of-defun'."
   (interactive "p")
   (or arg (setq arg 1))
 
+  (or (not (eq this-command 'c-end-of-defun))
+      (eq last-command 'c-end-of-defun)
+      (and transient-mark-mode mark-active)
+      (push-mark))
+
   (c-save-buffer-state
       (beginning-of-defun-function end-of-defun-function
        (start (point))
@@ -1685,63 +1670,71 @@ with a brace block."
   (c-save-buffer-state
       (beginning-of-defun-function end-of-defun-function
        where pos name-end)
-    (save-excursion
-      ;; Move back out of any macro/comment/string we happen to be in.
-      (c-beginning-of-macro)
-      (setq pos (c-literal-limits))
-      (if pos (goto-char (car pos)))
 
-      (setq where (c-where-wrt-brace-construct))
+    (save-restriction
+      (widen)
+      (save-excursion
+       ;; Move back out of any macro/comment/string we happen to be in.
+       (c-beginning-of-macro)
+       (setq pos (c-literal-limits))
+       (if pos (goto-char (car pos)))
 
-      ;; Move to the beginning of the current defun, if any, if we're not
-      ;; already there.
-      (if (eq where 'outwith-function)
-         nil
-       (unless (eq where 'at-header)
-         (c-backward-to-nth-BOF-{ 1 where)
-         (c-beginning-of-decl-1))
+       (setq where (c-where-wrt-brace-construct))
 
-       ;; Pick out the defun name, according to the type of defun.
-       (cond
-        ((and (looking-at c-type-prefix-key)
-              (progn (c-forward-token-2 2) ; over "struct foo "
-                     (eq (char-after) ?\{)))
-         ;; struct, union, enum, or similar:
-         (c-backward-syntactic-ws)
-         (setq name-end (point))
-         (buffer-substring-no-properties
-          (progn
-            (c-backward-token-2 2)
-            (point))
-          name-end))
-
-        ((looking-at "DEFUN\\_>")
-         ;; 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)
-         (c-forward-syntactic-ws)
-         (when (eq (char-after) ?\")
-           (forward-sexp 1)
-           (c-forward-token-2))        ; over the comma and following WS.
-         (buffer-substring-no-properties
-          (point)
-          (progn
-            (c-forward-token-2)
-            (c-backward-syntactic-ws)
-            (point))))
-               
-        (t
-        ;; Normal function or initializer.
-         (when (c-syntactic-re-search-forward "[{(]" nil t)
-           (backward-char)
-           (c-backward-syntactic-ws)
-           (when (eq (char-before) ?\=) ; struct foo bar = {0, 0} ;
+       ;; Move to the beginning of the current defun, if any, if we're not
+       ;; already there.
+       (if (eq where 'outwith-function)
+           nil
+         (unless (eq where 'at-header)
+           (c-backward-to-nth-BOF-{ 1 where)
+           (c-beginning-of-decl-1))
+
+         ;; Pick out the defun name, according to the type of defun.
+         (cond
+          ;; struct, union, enum, or similar:
+          ((and (looking-at c-type-prefix-key)
+                (progn (c-forward-token-2 2) ; over "struct foo "
+                       (or (eq (char-after) ?\{)
+                           (looking-at c-symbol-key)))) ; "struct foo bar ..."
+           (save-match-data (c-forward-token-2))
+           (when (eq (char-after) ?\{)
+             (c-backward-token-2)
+             (looking-at c-symbol-key))
+           (match-string-no-properties 0))
+
+          ((looking-at "DEFUN\\_>")
+           ;; 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)
+           (c-forward-syntactic-ws)
+           (when (eq (char-after) ?\")
+             (forward-sexp 1)
+             (c-forward-token-2))      ; over the comma and following WS.
+           (buffer-substring-no-properties
+            (point)
+            (progn
+              (c-forward-token-2)
+              (when (looking-at ":")  ; CLISP: DEFUN(PACKAGE:LISP-SYMBOL,...)
+                (skip-chars-forward "^,"))
+              (c-backward-syntactic-ws)
+              (point))))
+
+          ((looking-at "DEF[a-zA-Z0-9_]* *( *\\([^, ]*\\) *,")
+           ;; DEFCHECKER(sysconf_arg,prefix=_SC,default=, ...) ==> sysconf_arg
+           ;; DEFFLAGSET(syslog_opt_flags,LOG_PID ...) ==> syslog_opt_flags
+           (match-string-no-properties 1))
+
+          (t
+           ;; Normal function or initializer.
+           (when (c-syntactic-re-search-forward "[{(]" nil t)
+             (backward-char)
+             (c-backward-syntactic-ws)
+             (when (eq (char-before) ?\=) ; struct foo bar = {0, 0} ;
+               (c-backward-token-2)
+               (c-backward-syntactic-ws))
+             (setq name-end (point))
              (c-backward-token-2)
-             (c-backward-syntactic-ws))
-           (setq name-end (point))
-           (c-backward-token-2)
-           (buffer-substring-no-properties (point) name-end))))))))
+             (buffer-substring-no-properties (point) name-end)))))))))
 
 (defun c-declaration-limits (near)
   ;; Return a cons of the beginning and end positions of the current
@@ -2447,13 +2440,15 @@ function does not require the declaration to contain a brace block."
          (goto-char last)
          (throw 'done '(nil . nil)))
 
-        ;; Stop if we encounter a preprocessor line.
-        ((and (not macro-end)
+        ;; Stop if we encounter a preprocessor line.  Continue if we
+        ;; hit a naked #
+        ((and c-opt-cpp-prefix
+              (not macro-end)
               (eq (char-after) ?#)
               (= (point) (c-point 'boi)))
-         (goto-char last)
-         ;(throw 'done (cons (eq (point) here) 'macro-boundary))) ; Changed 2003/3/26
-         (throw 'done '(t . macro-boundary)))
+         (if (= (point) here)          ; Not a macro, therefore naked #.
+             (forward-char)
+           (throw 'done '(t . macro-boundary))))
 
         ;; Stop after a ';', '}', or "};"
         ((looking-at ";\\|};?")
@@ -2567,14 +2562,21 @@ be more \"DWIM:ey\"."
                                    (c-backward-syntactic-ws))
                                  (or (bobp) (c-after-statement-terminator-p)))))))
                ;; Are we about to move backwards into or out of a
-               ;; preprocessor command?  If so, locate it's beginning.
+               ;; preprocessor command?  If so, locate its beginning.
                (when (eq (cdr res) 'macro-boundary)
-                 (save-excursion
-                   (beginning-of-line)
-                   (setq macro-fence
-                         (and (not (bobp))
-                              (progn (c-skip-ws-backward) (c-beginning-of-macro))
-                              (point)))))
+                 (setq macro-fence
+                       (save-excursion
+                         (if macro-fence
+                             (progn
+                               (end-of-line)
+                               (and (not (eobp))
+                                    (progn (c-skip-ws-forward)
+                                           (c-beginning-of-macro))
+                                    (progn (c-end-of-macro)
+                                           (point))))
+                           (and (not (eobp))
+                                (c-beginning-of-macro)
+                                (progn (c-end-of-macro) (point)))))))
                ;; Are we about to move backwards into a literal?
                (when (memq (cdr res) '(macro-boundary literal))
                  (setq range (c-ascertain-preceding-literal)))
@@ -2652,14 +2654,19 @@ sentence motion in or near comments and multiline strings."
                ;; Are we about to move forward into or out of a
                ;; preprocessor command?
                (when (eq (cdr res) 'macro-boundary)
-                 (save-excursion
-                   (end-of-line)
-                   (setq macro-fence
-                         (and (not (eobp))
-                              (progn (c-skip-ws-forward)
-                                     (c-beginning-of-macro))
-                              (progn (c-end-of-macro)
-                                     (point))))))
+                 (setq macro-fence
+                       (save-excursion
+                         (if macro-fence
+                             (progn
+                               (end-of-line)
+                               (and (not (eobp))
+                                    (progn (c-skip-ws-forward)
+                                           (c-beginning-of-macro))
+                                    (progn (c-end-of-macro)
+                                           (point))))
+                           (and (not (eobp))
+                                (c-beginning-of-macro)
+                                (progn (c-end-of-macro) (point)))))))
                ;; Are we about to move forward into a literal?
                (when (memq (cdr res) '(macro-boundary literal))
                  (setq range (c-ascertain-following-literal)))
@@ -2799,7 +2806,9 @@ move forward to the end of the containing preprocessor conditional.
 function stops at them when going backward, but not when going
 forward."
   (interactive "p")
-  (c-forward-conditional (- count) -1)
+  (let ((new-point (c-scan-conditionals (- count) -1)))
+    (push-mark)
+    (goto-char new-point))
   (c-keep-region-active))
 
 (defun c-up-conditional-with-else (count)
@@ -2807,7 +2816,9 @@ forward."
 Just like `c-up-conditional', except it also stops at \"#else\"
 directives."
   (interactive "p")
-  (c-forward-conditional (- count) -1 t)
+  (let ((new-point (c-scan-conditionals (- count) -1 t)))
+    (push-mark)
+    (goto-char new-point))
   (c-keep-region-active))
 
 (defun c-down-conditional (count)
@@ -2819,7 +2830,9 @@ move backward into the previous preprocessor conditional.
 function stops at them when going forward, but not when going
 backward."
   (interactive "p")
-  (c-forward-conditional count 1)
+  (let ((new-point (c-scan-conditionals count 1)))
+    (push-mark)
+    (goto-char new-point))
   (c-keep-region-active))
 
 (defun c-down-conditional-with-else (count)
@@ -2827,15 +2840,24 @@ backward."
 Just like `c-down-conditional', except it also stops at \"#else\"
 directives."
   (interactive "p")
-  (c-forward-conditional count 1 t)
+  (let ((new-point (c-scan-conditionals count 1 t)))
+    (push-mark)
+    (goto-char new-point))
   (c-keep-region-active))
 
 (defun c-backward-conditional (count &optional target-depth with-else)
   "Move back across a preprocessor conditional, leaving mark behind.
 A prefix argument acts as a repeat count.  With a negative argument,
-move forward across a preprocessor conditional."
+move forward across a preprocessor conditional.
+
+The optional arguments TARGET-DEPTH and WITH-ELSE are historical,
+and have the same meanings as in `c-scan-conditionals'.  If you
+are calling c-forward-conditional from a program, you might want
+to call `c-scan-conditionals' directly instead."
   (interactive "p")
-  (c-forward-conditional (- count) target-depth with-else)
+  (let ((new-point (c-scan-conditionals (- count) target-depth with-else)))
+    (push-mark)
+    (goto-char new-point))
   (c-keep-region-active))
 
 (defun c-forward-conditional (count &optional target-depth with-else)
@@ -2843,21 +2865,42 @@ move forward across a preprocessor conditional."
 A prefix argument acts as a repeat count.  With a negative argument,
 move backward across a preprocessor conditional.
 
+If there aren't enough conditionals after \(or before) point, an
+error is signalled.
+
+\"#elif\" is treated like \"#else\" followed by \"#if\", except that
+the nesting level isn't changed when tracking subconditionals.
+
+The optional arguments TARGET-DEPTH and WITH-ELSE are historical,
+and have the same meanings as in `c-scan-conditionals'.  If you
+are calling c-forward-conditional from a program, you might want
+to call `c-scan-conditionals' directly instead."
+  (interactive "p")
+  (let ((new-point (c-scan-conditionals count target-depth with-else)))
+    (push-mark)
+    (goto-char new-point)))
+
+(defun c-scan-conditionals (count &optional target-depth with-else)
+  "Scan forward across COUNT preprocessor conditionals.
+With a negative argument, scan backward across preprocessor
+conditionals.  Return the end position.  Point is not moved.
+
+If there aren't enough preprocessor conditionals, throw an error.
+
 \"#elif\" is treated like \"#else\" followed by \"#if\", except that
 the nesting level isn't changed when tracking subconditionals.
 
 The optional argument TARGET-DEPTH specifies the wanted nesting depth
-after each scan.  I.e. if TARGET-DEPTH is -1, the function will move
-out of the enclosing conditional.  A non-integer non-nil TARGET-DEPTH
+after each scan.  E.g. if TARGET-DEPTH is -1, the end position will be
+outside the enclosing conditional.  A non-integer non-nil TARGET-DEPTH
 counts as -1.
 
 If the optional argument WITH-ELSE is non-nil, \"#else\" directives
 are treated as conditional clause limits.  Normally they are ignored."
-  (interactive "p")
   (let* ((forward (> count 0))
         (increment (if forward -1 1))
         (search-function (if forward 're-search-forward 're-search-backward))
-        (new))
+        new)
     (unless (integerp target-depth)
       (setq target-depth (if target-depth -1 0)))
     (save-excursion
@@ -2926,9 +2969,8 @@ are treated as conditional clause limits.  Normally they are ignored."
              (error "No containing preprocessor conditional"))
          (goto-char (setq new found)))
        (setq count (+ count increment))))
-    (push-mark)
-    (goto-char new))
-  (c-keep-region-active))
+    (c-keep-region-active)
+    new))
 
 \f
 ;; commands to indent lines, regions, defuns, and expressions
@@ -3096,46 +3138,46 @@ non-nil."
                    (c-parsing-error nil)
                    ;; shut up any echo msgs on indiv lines
                    (c-echo-syntactic-information-p nil)
-                   (in-macro (and c-auto-align-backslashes
-                                  (c-save-buffer-state ()
-                                    (save-excursion (c-beginning-of-macro)))
-                                  start))
+                   (ml-macro-start     ; Start pos of multi-line macro.
+                    (and (c-save-buffer-state ()
+                           (save-excursion (c-beginning-of-macro)))
+                         (eq (char-before (c-point 'eol)) ?\\)
+                         start))
                    (c-fix-backslashes nil)
                    syntax)
                (unwind-protect
                    (progn
                      (c-progress-init start end 'c-indent-region)
-                     (while (and (bolp)
+
+                     (while (and (bolp) ;; One line each time round the loop.
                                  (not (eobp))
                                  (< (point) endmark))
                        ;; update progress
                        (c-progress-update)
                        ;; skip empty lines
-                       (skip-chars-forward " \t\n")
-                       (beginning-of-line)
-                       ;; Get syntax and indent.
-                       (c-save-buffer-state nil
-                         (setq syntax (c-guess-basic-syntax)))
-                       (if (and c-auto-align-backslashes
-                                (assq 'cpp-macro syntax))
-                           ;; Record macro start.
-                           (setq in-macro (point)))
-                       (if in-macro
-                           (if (looking-at "\\s *\\\\$")
-                               (forward-line)
-                             (c-indent-line syntax t t)
-                             (if (progn (end-of-line)
-                                        (not (eq (char-before) ?\\)))
-                                 (progn
-                                   ;; Fixup macro backslashes.
-                                   (forward-line)
-                                   (c-backslash-region in-macro (point) nil)
-                                   (setq in-macro nil))
-                               (forward-line)))
-                         (c-indent-line syntax t t)
-                         (forward-line)))
-                     (if in-macro
-                         (c-backslash-region in-macro (c-point 'bopl) nil t)))
+                       (unless (or (looking-at "\\s *$")
+                                   (and ml-macro-start (looking-at "\\s *\\\\$")))
+                         ;; Get syntax and indent.
+                         (c-save-buffer-state nil
+                           (setq syntax (c-guess-basic-syntax)))
+                         (c-indent-line syntax t t))
+
+                       (if ml-macro-start
+                           ;; End of current multi-line macro?
+                           (when (and c-auto-align-backslashes
+                                      (not (eq (char-before (c-point 'eol)) ?\\)))
+                             ;; Fixup macro backslashes.
+                             (c-backslash-region ml-macro-start (c-point 'bonl) nil)
+                             (setq ml-macro-start nil))
+                         ;; New multi-line macro?
+                         (if (and (assq 'cpp-macro syntax)
+                                  (eq (char-before (c-point 'eol)) ?\\))
+                           (setq ml-macro-start (point))))
+
+                       (forward-line))
+
+                     (if (and ml-macro-start c-auto-align-backslashes)
+                         (c-backslash-region ml-macro-start (c-point 'bopl) nil t)))
                  (set-marker endmark nil)
                  (c-progress-fini 'c-indent-region))
                (c-echo-parsing-error quiet))
@@ -3149,7 +3191,7 @@ non-nil."
 (defun c-indent-line-or-region (&optional arg region)
   "Indent active region, current line, or block starting on this line.
 In Transient Mark mode, when the region is active, reindent the region.
-Othewise, with a prefix argument, rigidly reindent the expression
+Otherwise, with a prefix argument, rigidly reindent the expression
 starting on the current line.
 Otherwise reindent just the current line."
   (interactive
@@ -3946,16 +3988,19 @@ command to conveniently insert and align the necessary backslashes."
                    ;; "Invalid search bound (wrong side of point)"
                    ;; error in the subsequent re-search.  Maybe
                    ;; another fix would be needed (2007-12-08).
-                   (and (> (- (cdr c-lit-limits) 2) (point))
-                        (search-forward-regexp
-                         (concat "\\=[ \t]*\\(" c-current-comment-prefix "\\)")
-                         (- (cdr c-lit-limits) 2) t)
-                        (not (search-forward-regexp
-                              "\\(\\s \\|\\sw\\)"
-                              (- (cdr c-lit-limits) 2) 'limit))
-                            ;; The comment ender IS on its own line.  Exclude
-                            ;; this line from the filling.
-                        (set-marker end (c-point 'bol))))
+;                  (or (<= (- (cdr c-lit-limits) 2) (point))
+; 2010-10-17  Construct removed.
+;                  (or (< (- (cdr c-lit-limits) 2) (point))
+                   (and 
+                    (search-forward-regexp
+                     (concat "\\=[ \t]*\\(" c-current-comment-prefix "\\)")
+                     (- (cdr c-lit-limits) 2) t)
+                    (not (search-forward-regexp
+                          "\\(\\s \\|\\sw\\)"
+                          (- (cdr c-lit-limits) 2) 'limit))
+                    ;; The comment ender IS on its own line.  Exclude this
+                    ;; line from the filling.
+                    (set-marker end (c-point 'bol))));)
 
                ;; The comment ender is hanging.  Replace all space between it
                ;; and the last word either by one or two 'x's (when
@@ -3972,6 +4017,14 @@ command to conveniently insert and align the necessary backslashes."
                                       (goto-char ender-start)
                                       (current-column)))
                       (point-rel (- ender-start here))
+                      (sentence-ends-comment
+                       (save-excursion
+                         (goto-char ender-start)
+                         (and (search-backward-regexp
+                               (c-sentence-end) (c-point 'bol) t)
+                              (goto-char (match-end 0))
+                         (looking-at "[ \t]*")
+                         (= (match-end 0) ender-start))))
                       spaces)
 
                  (save-excursion
@@ -4014,7 +4067,9 @@ command to conveniently insert and align the necessary backslashes."
                              (setq spaces
                                    (max
                                     (min spaces
-                                         (if sentence-end-double-space 2 1))
+                                         (if (and sentence-ends-comment
+                                                  sentence-end-double-space)
+                                             2 1))
                                     1)))
                          ;; Insert the filler first to keep marks right.
                          (insert-char ?x spaces t)
@@ -4193,8 +4248,7 @@ Warning: Regexp from `c-comment-prefix-regexp' doesn't match the comment prefix
          (forward-char (- hang-ender-stuck))
          (if (or fill-paragraph (not auto-fill-spaces))
              (insert-char ?\  hang-ender-stuck t)
-           (insert auto-fill-spaces)
-           (setq here (- here (- hang-ender-stuck (length auto-fill-spaces)))))
+           (insert auto-fill-spaces))
          (delete-char hang-ender-stuck)
          (goto-char here))
        (set-marker tmp-post nil))
@@ -4225,8 +4279,11 @@ Optional prefix ARG means justify paragraph as well."
   (let ((fill-paragraph-function
         ;; Avoid infinite recursion.
         (if (not (eq fill-paragraph-function 'c-fill-paragraph))
-            fill-paragraph-function)))
-    (c-mask-paragraph t nil 'fill-paragraph arg))
+            fill-paragraph-function))
+       (start-point (point-marker)))
+    (c-mask-paragraph
+     t nil (lambda () (fill-region-as-paragraph (point-min) (point-max) arg)))
+    (goto-char start-point))
   ;; Always return t.  This has the effect that if filling isn't done
   ;; above, it isn't done at all, and it's therefore effectively
   ;; disabled in normal code.
@@ -4423,7 +4480,7 @@ If a fill prefix is specified, it overrides all the above."
             (indent-to col))))))
 
 (defalias 'c-comment-line-break-function 'c-indent-new-comment-line)
-(make-obsolete 'c-comment-line-break-function 'c-indent-new-comment-line)
+(make-obsolete 'c-comment-line-break-function 'c-indent-new-comment-line "21.1")
 
 ;; advice for indent-new-comment-line for older Emacsen
 (unless (boundp 'comment-line-break-function)
@@ -4529,5 +4586,4 @@ normally bound to C-o.  See `c-context-line-break' for the details."
 \f
 (cc-provide 'cc-cmds)
 
-;; arch-tag: bf0611dc-d1f4-449e-9e45-4ec7c6936677
 ;;; cc-cmds.el ends here