]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/cc-cmds.el
Amend a cache so that typing into C++ raw strings has no undue delay.
[gnu-emacs] / lisp / progmodes / cc-cmds.el
index 764f44a8dd819fcc322cbae62e3c0f35b50dc568..f0ad2942457623612071749b30732033596c0857 100644 (file)
@@ -1594,70 +1594,69 @@ defun."
       (c-region-is-active-p)
       (push-mark))
 
-  (c-self-bind-state-cache ; We must not share with other users of c-state-cache.
-   (c-save-buffer-state
-       (beginning-of-defun-function
-       end-of-defun-function
-       (start (point))
-       (paren-state (c-parse-state))
-       (orig-point-min (point-min)) (orig-point-max (point-max))
-       lim                 ; Position of { which has been widened to.
-       where pos case-fold-search)
-
-     (save-restriction
-       (if (eq c-defun-tactic 'go-outward)
-          (setq lim (c-widen-to-enclosing-decl-scope ; e.g. class, namespace.
-                     paren-state orig-point-min orig-point-max)))
-
-       ;; 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))
-
-       (if (< arg 0)
-          ;; Move forward to the closing brace of a function.
-          (progn
-            (if (memq where '(at-function-end outwith-function))
-                (setq arg (1+ arg)))
-            (if (< arg 0)
-                (c-while-widening-to-decl-block
-                 (< (setq arg (- (c-forward-to-nth-EOF-} (- arg) where))) 0)))
-            ;; Move forward to the next opening brace....
-            (when (and (= arg 0)
-                       (progn
-                         (c-while-widening-to-decl-block
-                          (not (c-syntactic-re-search-forward "{" nil 'eob)))
-                         (eq (char-before) ?{)))
-              (backward-char)
-              ;; ... and backward to the function header.
-              (c-beginning-of-decl-1)
-              t))
-
-        ;; Move backward to the opening brace of a function, making successively
-        ;; larger portions of the buffer visible as necessary.
-        (when (> arg 0)
-          (c-while-widening-to-decl-block
-           (> (setq arg (c-backward-to-nth-BOF-{ arg where)) 0)))
-
-        (when (eq arg 0)
-          ;; Go backward to this function's header.
-          (c-beginning-of-decl-1)
-
-          (setq pos (point))
-          ;; We're now there, modulo comments and whitespace.
-          ;; Try to be line oriented; position point at the closest
-          ;; preceding boi that isn't inside a comment, but if we hit
-          ;; the previous declaration then we use the current point
-          ;; instead.
-          (while (and (/= (point) (c-point 'boi))
-                      (c-backward-single-comment)))
-          (if (/= (point) (c-point 'boi))
-              (goto-char pos)))
-
-        (c-keep-region-active)
-        (= arg 0))))))
+  (c-save-buffer-state
+      (beginning-of-defun-function
+       end-of-defun-function
+       (start (point))
+       (paren-state (c-parse-state))
+       (orig-point-min (point-min)) (orig-point-max (point-max))
+       lim                 ; Position of { which has been widened to.
+       where pos case-fold-search)
+
+    (save-restriction
+      (if (eq c-defun-tactic 'go-outward)
+         (setq lim (c-widen-to-enclosing-decl-scope ; e.g. class, namespace.
+                    paren-state orig-point-min orig-point-max)))
+
+      ;; Move back out of any macro/comment/string we happen to be in.
+      (c-beginning-of-macro)
+      (setq pos (c-literal-start))
+      (if pos (goto-char pos))
+
+      (setq where (c-where-wrt-brace-construct))
+
+      (if (< arg 0)
+         ;; Move forward to the closing brace of a function.
+         (progn
+           (if (memq where '(at-function-end outwith-function))
+               (setq arg (1+ arg)))
+           (if (< arg 0)
+               (c-while-widening-to-decl-block
+                (< (setq arg (- (c-forward-to-nth-EOF-} (- arg) where))) 0)))
+           ;; Move forward to the next opening brace....
+           (when (and (= arg 0)
+                      (progn
+                        (c-while-widening-to-decl-block
+                         (not (c-syntactic-re-search-forward "{" nil 'eob)))
+                        (eq (char-before) ?{)))
+             (backward-char)
+             ;; ... and backward to the function header.
+             (c-beginning-of-decl-1)
+             t))
+
+       ;; Move backward to the opening brace of a function, making successively
+       ;; larger portions of the buffer visible as necessary.
+       (when (> arg 0)
+         (c-while-widening-to-decl-block
+          (> (setq arg (c-backward-to-nth-BOF-{ arg where)) 0)))
+
+       (when (eq arg 0)
+         ;; Go backward to this function's header.
+         (c-beginning-of-decl-1)
+
+         (setq pos (point))
+         ;; We're now there, modulo comments and whitespace.
+         ;; Try to be line oriented; position point at the closest
+         ;; preceding boi that isn't inside a comment, but if we hit
+         ;; the previous declaration then we use the current point
+         ;; instead.
+         (while (and (/= (point) (c-point 'boi))
+                     (c-backward-single-comment)))
+         (if (/= (point) (c-point 'boi))
+             (goto-char pos)))
+
+       (c-keep-region-active)
+       (= arg 0)))))
 
 (defun c-forward-to-nth-EOF-} (n where)
   ;; Skip to the closing brace of the Nth function after point.  If
@@ -1719,68 +1718,66 @@ the open-parenthesis that starts a defun; see `beginning-of-defun'."
       (c-region-is-active-p)
       (push-mark))
 
-  (c-self-bind-state-cache ; c-state-cache's list structure must not be shared
-                          ; with other users.
-   (c-save-buffer-state
-       (beginning-of-defun-function
-       end-of-defun-function
-       (start (point))
-       (paren-state (c-parse-state))
-       (orig-point-min (point-min)) (orig-point-max (point-max))
-       lim
-       where pos case-fold-search)
-
-     (save-restriction
-       (if (eq c-defun-tactic 'go-outward)
-          (setq lim (c-widen-to-enclosing-decl-scope ; e.g. class, namespace
-                     paren-state orig-point-min orig-point-max)))
-
-       ;; 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))
-
-       (if (< arg 0)
-          ;; Move backwards to the } of a function
-          (progn
-            (if (memq where '(at-header outwith-function))
-                (setq arg (1+ arg)))
-            (if (< arg 0)
-                (c-while-widening-to-decl-block
-                 (< (setq arg (- (c-backward-to-nth-BOF-{ (- arg) where))) 0)))
-            (if (= arg 0)
-                (c-while-widening-to-decl-block
-                 (progn (c-syntactic-skip-backward "^}")
-                        (not (eq (char-before) ?}))))))
-
-        ;; Move forward to the } of a function
-        (if (> arg 0)
-            (c-while-widening-to-decl-block
-             (> (setq arg (c-forward-to-nth-EOF-} arg where)) 0))))
-
-       ;; Do we need to move forward from the brace to the semicolon?
-       (when (eq arg 0)
-        (if (c-in-function-trailer-p)  ; after "}" of struct/enum, etc.
-            (c-syntactic-re-search-forward ";"))
+  (c-save-buffer-state
+      (beginning-of-defun-function
+       end-of-defun-function
+       (start (point))
+       (paren-state (c-parse-state))
+       (orig-point-min (point-min)) (orig-point-max (point-max))
+       lim
+       where pos case-fold-search)
 
-        (setq pos (point))
-        ;; We're there now, modulo comments and whitespace.
-        ;; Try to be line oriented; position point after the next
-        ;; newline that isn't inside a comment, but if we hit the
-        ;; next declaration then we use the current point instead.
-        (while (and (not (bolp))
-                    (not (looking-at "\\s *$"))
-                    (c-forward-single-comment)))
-        (cond ((bolp))
-              ((looking-at "\\s *$")
-               (forward-line 1))
-              (t
-               (goto-char pos))))
+    (save-restriction
+      (if (eq c-defun-tactic 'go-outward)
+         (setq lim (c-widen-to-enclosing-decl-scope ; e.g. class, namespace
+                    paren-state orig-point-min orig-point-max)))
+
+      ;; Move back out of any macro/comment/string we happen to be in.
+      (c-beginning-of-macro)
+      (setq pos (c-literal-start))
+      (if pos (goto-char pos))
+
+      (setq where (c-where-wrt-brace-construct))
+
+      (if (< arg 0)
+         ;; Move backwards to the } of a function
+         (progn
+           (if (memq where '(at-header outwith-function))
+               (setq arg (1+ arg)))
+           (if (< arg 0)
+               (c-while-widening-to-decl-block
+                (< (setq arg (- (c-backward-to-nth-BOF-{ (- arg) where))) 0)))
+           (if (= arg 0)
+               (c-while-widening-to-decl-block
+                (progn (c-syntactic-skip-backward "^}")
+                       (not (eq (char-before) ?}))))))
+
+       ;; Move forward to the } of a function
+       (if (> arg 0)
+           (c-while-widening-to-decl-block
+            (> (setq arg (c-forward-to-nth-EOF-} arg where)) 0))))
+
+      ;; Do we need to move forward from the brace to the semicolon?
+      (when (eq arg 0)
+       (if (c-in-function-trailer-p)   ; after "}" of struct/enum, etc.
+           (c-syntactic-re-search-forward ";"))
 
-       (c-keep-region-active)
-       (= arg 0)))))
+       (setq pos (point))
+       ;; We're there now, modulo comments and whitespace.
+       ;; Try to be line oriented; position point after the next
+       ;; newline that isn't inside a comment, but if we hit the
+       ;; next declaration then we use the current point instead.
+       (while (and (not (bolp))
+                   (not (looking-at "\\s *$"))
+                   (c-forward-single-comment)))
+       (cond ((bolp))
+             ((looking-at "\\s *$")
+              (forward-line 1))
+             (t
+              (goto-char pos))))
+
+      (c-keep-region-active)
+      (= arg 0))))
 
 (defun c-defun-name ()
   "Return the name of the current defun, or NIL if there isn't one.
@@ -1796,8 +1793,8 @@ with a brace block."
       (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 pos (c-literal-start))
+       (if pos (goto-char pos))
 
        (setq where (c-where-wrt-brace-construct))
 
@@ -1883,103 +1880,103 @@ with a brace block."
        (or (save-restriction
              (c-narrow-to-most-enclosing-decl-block nil)
 
-    ;; Note: Some code duplication in `c-beginning-of-defun' and
-    ;; `c-end-of-defun'.
-    (catch 'exit
-      (let ((start (point))
-           (paren-state (c-parse-state))
-           lim pos end-pos)
-       (unless (c-safe
-                 (goto-char (c-least-enclosing-brace paren-state))
+             ;; Note: Some code duplication in `c-beginning-of-defun' and
+             ;; `c-end-of-defun'.
+             (catch 'exit
+               (let ((start (point))
+                     (paren-state (c-parse-state))
+                     lim pos end-pos)
+                 (unless (c-safe
+                           (goto-char (c-least-enclosing-brace paren-state))
                            ;; If we moved to the outermost enclosing paren
                            ;; then we can use c-safe-position to set the
                            ;; limit. Can't do that otherwise since the
                            ;; earlier paren pair on paren-state might very
                            ;; well be part of the declaration we should go
                            ;; to.
-                 (setq lim (c-safe-position (point) paren-state))
-                 t)
-         ;; At top level.  Make sure we aren't inside a literal.
-         (setq pos (c-literal-limits
-                    (c-safe-position (point) paren-state)))
-         (if pos (goto-char (car pos))))
-
-       (when (c-beginning-of-macro)
-         (throw 'exit
-                (cons (point)
-                      (save-excursion
-                        (c-end-of-macro)
-                        (forward-line 1)
-                        (point)))))
-
-       (setq pos (point))
-       (when (or (eq (car (c-beginning-of-decl-1 lim)) 'previous)
-                 (= pos (point)))
-         ;; We moved back over the previous defun.  Skip to the next
-         ;; one.  Not using c-forward-syntactic-ws here since we
-         ;; should not skip a macro.  We can also be directly after
-         ;; the block in a `c-opt-block-decls-with-vars-key'
-         ;; declaration, but then we won't move significantly far
-         ;; here.
-         (goto-char pos)
-         (c-forward-comments)
-
-         (when (and near (c-beginning-of-macro))
-           (throw 'exit
-                  (cons (point)
-                        (save-excursion
-                          (c-end-of-macro)
-                          (forward-line 1)
-                          (point))))))
-
-       (if (eobp) (throw 'exit nil))
-
-       ;; Check if `c-beginning-of-decl-1' put us after the block in a
-       ;; declaration that doesn't end there.  We're searching back and
-       ;; forth over the block here, which can be expensive.
-       (setq pos (point))
-       (if (and c-opt-block-decls-with-vars-key
-                (progn
-                  (c-backward-syntactic-ws)
-                  (eq (char-before) ?}))
-                (eq (car (c-beginning-of-decl-1))
-                    'previous)
-                (save-excursion
-                  (c-end-of-decl-1)
-                  (and (> (point) pos)
-                       (setq end-pos (point)))))
-           nil
-         (goto-char pos))
-
-       (if (and (not near) (> (point) start))
-           nil
+                           (setq lim (c-safe-position (point) paren-state))
+                           t)
+                   ;; At top level.  Make sure we aren't inside a literal.
+                   (setq pos (c-literal-start
+                              (c-safe-position (point) paren-state)))
+                   (if pos (goto-char pos)))
+
+                 (when (c-beginning-of-macro)
+                   (throw 'exit
+                          (cons (point)
+                                (save-excursion
+                                  (c-end-of-macro)
+                                  (forward-line 1)
+                                  (point)))))
 
-         ;; Try to be line oriented; position the limits at the
-         ;; closest preceding boi, and after the next newline, that
-         ;; isn't inside a comment, but if we hit a neighboring
-         ;; declaration then we instead use the exact declaration
-         ;; limit in that direction.
-         (cons (progn
                  (setq pos (point))
-                 (while (and (/= (point) (c-point 'boi))
-                             (c-backward-single-comment)))
-                 (if (/= (point) (c-point 'boi))
-                     pos
-                   (point)))
-               (progn
-                 (if end-pos
-                     (goto-char end-pos)
-                   (c-end-of-decl-1))
+                 (when (or (eq (car (c-beginning-of-decl-1 lim)) 'previous)
+                           (= pos (point)))
+                   ;; We moved back over the previous defun.  Skip to the next
+                   ;; one.  Not using c-forward-syntactic-ws here since we
+                   ;; should not skip a macro.  We can also be directly after
+                   ;; the block in a `c-opt-block-decls-with-vars-key'
+                   ;; declaration, but then we won't move significantly far
+                   ;; here.
+                   (goto-char pos)
+                   (c-forward-comments)
+
+                   (when (and near (c-beginning-of-macro))
+                     (throw 'exit
+                            (cons (point)
+                                  (save-excursion
+                                    (c-end-of-macro)
+                                    (forward-line 1)
+                                    (point))))))
+
+                 (if (eobp) (throw 'exit nil))
+
+                 ;; Check if `c-beginning-of-decl-1' put us after the block in a
+                 ;; declaration that doesn't end there.  We're searching back and
+                 ;; forth over the block here, which can be expensive.
                  (setq pos (point))
-                 (while (and (not (bolp))
-                             (not (looking-at "\\s *$"))
-                             (c-forward-single-comment)))
-                 (cond ((bolp)
-                        (point))
-                       ((looking-at "\\s *$")
-                        (forward-line 1)
-                        (point))
-                       (t
+                 (if (and c-opt-block-decls-with-vars-key
+                          (progn
+                            (c-backward-syntactic-ws)
+                            (eq (char-before) ?}))
+                          (eq (car (c-beginning-of-decl-1))
+                              'previous)
+                          (save-excursion
+                            (c-end-of-decl-1)
+                            (and (> (point) pos)
+                                 (setq end-pos (point)))))
+                     nil
+                   (goto-char pos))
+
+                 (if (and (not near) (> (point) start))
+                     nil
+
+                   ;; Try to be line oriented; position the limits at the
+                   ;; closest preceding boi, and after the next newline, that
+                   ;; isn't inside a comment, but if we hit a neighboring
+                   ;; declaration then we instead use the exact declaration
+                   ;; limit in that direction.
+                   (cons (progn
+                           (setq pos (point))
+                           (while (and (/= (point) (c-point 'boi))
+                                       (c-backward-single-comment)))
+                           (if (/= (point) (c-point 'boi))
+                               pos
+                             (point)))
+                         (progn
+                           (if end-pos
+                               (goto-char end-pos)
+                             (c-end-of-decl-1))
+                           (setq pos (point))
+                           (while (and (not (bolp))
+                                       (not (looking-at "\\s *$"))
+                                       (c-forward-single-comment)))
+                           (cond ((bolp)
+                                  (point))
+                                 ((looking-at "\\s *$")
+                                  (forward-line 1)
+                                  (point))
+                                 (t
                                   pos))))))))
            (and (not near)
                 (goto-char (point-min))