]> git.eshelyaron.com Git - emacs.git/commitdiff
CC Mode: Make it scroll fast over buffers with only #define's
authorAlan Mackenzie <acm@muc.de>
Thu, 24 Nov 2022 10:51:03 +0000 (10:51 +0000)
committerAlan Mackenzie <acm@muc.de>
Thu, 24 Nov 2022 10:51:03 +0000 (10:51 +0000)
* lisp/progmodes/cc-engine.el (c-forward-over-token): New LIMIT parameter

* lisp/progmodes/cc-langs.el (c-anchored-hash-define-no-parens): Replace
ill-formed regular expression (which mixed \\sw and character alternative)
with simpler efficient regexp.

* lisp/progmodes/cc-mode.el (c-fl-decl-end): New forward limit LIM+ used in
c-forward-declarator and c-forward-over-token.

lisp/progmodes/cc-engine.el
lisp/progmodes/cc-langs.el
lisp/progmodes/cc-mode.el

index 086166c822b6a1e090f92c6379b96fcc1e06a1a9..9e09e5150d9ea8ebd609e7f44e9e2150faae2b31 100644 (file)
@@ -4951,30 +4951,31 @@ comment at the start of cc-engine.el for more info."
       "\\w\\|\\s_\\|\\s\"\\|\\s|"
     "\\w\\|\\s_\\|\\s\""))
 
-(defun c-forward-over-token (&optional balanced)
+(defun c-forward-over-token (&optional balanced limit)
   "Move forward over a token.
 Return t if we moved, nil otherwise (i.e. we were at EOB, or a
 non-token or BALANCED is non-nil and we can't move).  If we
 are at syntactic whitespace, move over this in place of a token.
 
 If BALANCED is non-nil move over any balanced parens we are at, and never move
-out of an enclosing paren."
+out of an enclosing paren.  LIMIT is the limit to where we might move to."
   (let ((jump-syntax (if balanced
                         c-jump-syntax-balanced
                       c-jump-syntax-unbalanced))
-       (here (point)))
+       (here (point))
+       (limit (or limit (point-max))))
     (condition-case nil
        (cond
         ((/= (point)
-             (progn (c-forward-syntactic-ws) (point)))
+             (progn (c-forward-syntactic-ws limit) (point)))
          ;; If we're at whitespace, count this as the token.
          t)
         ((eobp) nil)
         ((looking-at jump-syntax)
-         (goto-char (scan-sexps (point) 1))
+         (goto-char (min limit (scan-sexps (point) 1)))
          t)
         ((looking-at c-nonsymbol-token-regexp)
-         (goto-char (match-end 0))
+         (goto-char (min (match-end 0) limit))
          t)
         ((save-restriction
            (widen)
index 47e05438ea381c9e64654d6b95c30f6028b9e466..581685cad7013ddeb6248fb191aec26d6efc2907 100644 (file)
@@ -1188,7 +1188,7 @@ definition, or nil if the language doesn't have any."
   t (if (c-lang-const c-opt-cpp-macro-define)
        (concat (c-lang-const c-anchored-cpp-prefix)
                (c-lang-const c-opt-cpp-macro-define)
-               "[ \t]+\\(\\sw\\|_\\)+\\([^(a-zA-Z0-9_]\\|$\\)")))
+               "[ \t]+[a-zA-Z0-9_]+\\([^(a-zA-Z0-9_]\\|$\\)")))
 
 (c-lang-defconst c-cpp-expr-directives
   "List of cpp directives (without the prefix) that are followed by an
index 99067e47618930b2102c9e575eac0ddc53d6fbe6..6a2c2f2911e08e7483d8fc583d3709b136c333ab 100644 (file)
@@ -2482,7 +2482,8 @@ with // and /*, not more generic line and block comments."
       (let* ((lim1 (save-excursion
                     (and (c-beginning-of-macro)
                          (progn (c-end-of-macro) (point)))))
-            (decl-res (c-forward-declarator)))
+            (lim+ (c-determine-+ve-limit 200))
+            (decl-res (c-forward-declarator lim+)))
        (if (or (cadr (cddr (cddr decl-res))) ; We scanned an arglist.
                (and (eq (char-after) ?\()    ; Move over a non arglist (...).
                     (prog1 (c-go-list-forward)
@@ -2499,7 +2500,7 @@ with // and /*, not more generic line and block comments."
                   (c-backward-syntactic-ws lim1)
                   (eq (char-before) ?\())
                 (c-fl-decl-end (1- (point))))
-             (c-forward-over-token)
+             (c-forward-over-token nil lim+) ; The , or ) after the declarator.
              (point))
          (if (progn (c-forward-syntactic-ws)
                     (not (eobp)))