]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/cc-cmds.el
Merge from emacs--rel--22
[gnu-emacs] / lisp / progmodes / cc-cmds.el
index 070a690b7003e4f0b735414227eb3cdbc5ed46db..079ebb0262299ebb3744841807d6f2fe648e54ca 100644 (file)
@@ -78,8 +78,10 @@ indentation change \(in columns)."
               (save-excursion
                 (beginning-of-line)
                 (looking-at (if line-cont-backslash
-                                "\\(\\s *\\)\\\\$"
-                              "\\(\\s *\\)$")))
+                                ;; Don't use "\\s " - ^L doesn't count as WS
+                                ;; here
+                                "\\([ \t]*\\)\\\\$"
+                              "\\([ \t]*\\)$")))
               (<= (point) (match-end 1)))
       ;; Delete all whitespace after point if there's only whitespace
       ;; on the line, so that any code that does back-to-indentation
@@ -854,8 +856,8 @@ is inhibited."
                   (narrow-to-region (point-min) (point))
                   (back-to-indentation)
                   (looking-at (concat c-current-comment-prefix "[ \t]*$")))))
-      (kill-region (progn (forward-line 0) (point))
-                  (progn (end-of-line) (point)))
+      (delete-region (progn (forward-line 0) (point))
+                    (progn (end-of-line) (point)))
       (insert-char ?* 1)) ; the / comes later. ; Do I need a t (retain sticky properties) here?
 
     (setq indentp (and (not arg)
@@ -1260,11 +1262,11 @@ newline cleanups are done if appropriate; see the variable `c-cleanup-list'."
                     (backward-char)
                     (skip-chars-backward " \t")
                     (setq beg (point))
-                    (c-save-buffer-state () (c-on-identifier))
-                    ;; Don't add a space into #define FOO()....
-                    (not (and (c-beginning-of-macro)
-                              (c-forward-over-cpp-define-id)
-                              (eq (point) beg)))))
+                    (and (c-save-buffer-state () (c-on-identifier))
+                          ;; Don't add a space into #define FOO()....
+                          (not (and (c-beginning-of-macro)
+                                    (c-forward-over-cpp-define-id)
+                                    (eq (point) beg))))))
              (save-excursion
                (delete-region beg end)
                (goto-char beg)
@@ -1358,10 +1360,24 @@ No indentation or other \"electric\" behavior is performed."
   (and c-opt-block-decls-with-vars-key
        (save-excursion
         (c-syntactic-skip-backward "^;}" lim)
-        (and (eq (char-before) ?\})
-             (eq (car (c-beginning-of-decl-1 lim)) 'previous)
-             (looking-at c-opt-block-decls-with-vars-key)
-             (point)))))
+        (let ((eo-block (point))
+              bod)
+          (and (eq (char-before) ?\})
+               (eq (car (c-beginning-of-decl-1 lim)) 'previous)
+               (setq bod (point))
+               ;; Look for struct or union or ...  If we find one, it might
+               ;; be the return type of a function, or the like.  Exclude
+               ;; this case.
+               (c-syntactic-re-search-forward
+                (concat "[;=\(\[{]\\|\\("
+                        c-opt-block-decls-with-vars-key
+                        "\\)")
+                eo-block t t t)
+               (match-beginning 1)     ; Is there a "struct" etc., somewhere?
+               (not (eq (char-before) ?_))
+               (c-syntactic-re-search-forward "[;=\(\[{]" eo-block t t t)
+               (eq (char-before) ?\{)
+               bod)))))
 
 (defun c-where-wrt-brace-construct ()
   ;; Determine where we are with respect to functions (or other brace
@@ -1383,8 +1399,7 @@ No indentation or other \"electric\" behavior is performed."
   ;;
   ;; This function might do hidden buffer changes.
   (save-excursion
-    (let* (pos
-          kluge-start
+    (let* (kluge-start
           decl-result brace-decl-p
           (start (point))
           (paren-state (c-parse-state))
@@ -1417,11 +1432,12 @@ No indentation or other \"electric\" behavior is performed."
        (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.
                    (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?
-       (setq pos (point))            ; the search limit for c-recognize-knr-p
        (setq brace-decl-p
              (save-excursion
                    (and (c-syntactic-re-search-forward "[;{]" nil t t)
@@ -1431,7 +1447,7 @@ No indentation or other \"electric\" behavior is performed."
                                  ;; ';' in a K&R argdecl.  In
                                  ;; that case the declaration
                                  ;; should contain a block.
-                                 (c-in-knr-argdecl pos))))))
+                                 (c-in-knr-argdecl))))))
 
        (cond
         ((= (point) kluge-start)       ; might be BOB or unbalanced parens.
@@ -1475,9 +1491,7 @@ No indentation or other \"electric\" behavior is performed."
     (c-syntactic-re-search-forward "{")
     (backward-char)
     (setq n (1- n)))
-   (;; (or (eq where 'at-header) (eq where 'outwith-function)
-;;     (eq where 'at-function-end) (eq where 'in-trailer))
-    (memq where '(at-header outwith-function at-function-end in-trailer))
+   ((memq where '(at-header outwith-function at-function-end in-trailer))
     (c-syntactic-skip-backward "^}")
     (when (eq (char-before) ?\})
       (backward-sexp)
@@ -1511,7 +1525,8 @@ defun."
   (or arg (setq arg 1))
 
   (c-save-buffer-state
-      ((start (point))
+      (beginning-of-defun-function end-of-defun-function
+       (start (point))
        where paren-state pos)
 
     ;; Move back out of any macro/comment/string we happen to be in.
@@ -1524,14 +1539,13 @@ defun."
     (if (< arg 0)
        ;; Move forward to the closing brace of a function.
        (progn
-         (if ;; (or (eq where 'at-function-end) (eq where 'outwith-function))
-             (memq where '(at-function-end outwith-function))
+         (if (memq where '(at-function-end outwith-function))
              (setq arg (1+ arg)))
          (if (< arg 0)
              (setq arg (c-forward-to-nth-EOF-} (- arg) where)))
          ;; Move forward to the next opening brace....
          (when (and (= arg 0)
-                    (c-syntactic-re-search-forward "{" nil t))
+                    (c-syntactic-re-search-forward "{" nil 'eob))
            (backward-char)
            ;; ... and backward to the function header.
            (c-beginning-of-decl-1)
@@ -1585,13 +1599,11 @@ defun."
    ((eq where 'in-trailer)
     (c-syntactic-skip-backward "^}")
     (setq n (1- n)))
-   (;; (or (eq where 'at-function-end) (eq where 'outwith-function)
-;;     (eq where 'at-header) (eq where 'in-header))
-    (memq where '(at-function-end outwith-function at-header in-header))
-    (c-syntactic-re-search-forward "{")
-    (backward-char)
-    (forward-sexp)
-    (setq n (1- n)))
+   ((memq where '(at-function-end outwith-function at-header in-header))
+    (when (c-syntactic-re-search-forward "{" nil 'eob)
+      (backward-char)
+      (forward-sexp)
+      (setq n (1- n))))
    (t (error "c-forward-to-nth-EOF-}: `where' is %s" where)))
 
   ;; Each time round the loop, go forward to a "}" at the outermost level.
@@ -1616,7 +1628,8 @@ the open-parenthesis that starts a defun; see `beginning-of-defun'."
   (or arg (setq arg 1))
 
   (c-save-buffer-state
-      ((start (point))
+      (beginning-of-defun-function end-of-defun-function
+       (start (point))
        where paren-state pos)
 
     ;; Move back out of any macro/comment/string we happen to be in.
@@ -1629,15 +1642,12 @@ the open-parenthesis that starts a defun; see `beginning-of-defun'."
     (if (< arg 0)
        ;; Move backwards to the } of a function
        (progn
-         (if ;; (or (eq where 'at-header) (eq where 'outwith-function))
-             (memq where '(at-header outwith-function))
+         (if (memq where '(at-header outwith-function))
              (setq arg (1+ arg)))
          (if (< arg 0)
              (setq arg (c-backward-to-nth-BOF-{ (- arg) where)))
-         (when (and (= arg 0)
-                    (c-syntactic-skip-backward "^}")
-                    (eq (char-before) ?\}))
-           t))
+         (if (= arg 0)
+             (c-syntactic-skip-backward "^}")))
 
       ;; Move forward to the } of a function
       (if (> arg 0)
@@ -4236,6 +4246,7 @@ If a fill prefix is specified, it overrides all the above."
                                    (c-collect-line-comments c-lit-limits))
                              c-lit-type)))
                     (pos (point))
+                    (start-col (current-column))
                     (comment-text-end
                      (or (and (eq c-lit-type 'c)
                               (save-excursion
@@ -4252,6 +4263,11 @@ If a fill prefix is specified, it overrides all the above."
                 ;;
                 ;; If point is on the 'B' then the line will be
                 ;; broken after "Bla b".
+                ;;
+                ;; If we have an empty comment, /*   */, the next
+                ;; lot of code pushes point to the */.  We fix
+                ;; this by never allowing point to end up to the
+                ;; right of where it started.
                 (while (and (< (current-column) (cdr fill))
                             (not (eolp)))
                   (forward-char 1))
@@ -4274,7 +4290,10 @@ If a fill prefix is specified, it overrides all the above."
                         ((< (point) (+ (car c-lit-limits) 2))
                          (goto-char (+ (car c-lit-limits) 2))))
                   (funcall do-line-break)
-                  (insert-and-inherit (car fill))))
+                  (insert-and-inherit (car fill))
+                  (if (> (current-column) start-col)
+                      (move-to-column start-col)))) ; can this hit the
+                                                    ; middle of a TAB?
             ;; Inside a comment that should be broken.
             (let ((comment-start comment-start)
                   (comment-end comment-end)