diff options
author | Alan Mackenzie <acm@muc.de> | 2016-06-27 11:34:02 +0000 |
---|---|---|
committer | Alan Mackenzie <acm@muc.de> | 2016-06-27 11:34:02 +0000 |
commit | 8040d99b6294ad798d4ab677ba20082b45fd2e7d (patch) | |
tree | 9c53c471d718eb1a2028168705324ffa9501cac4 /lisp/progmodes/cc-cmds.el | |
parent | 15c307417f7bc13b27f06994dd931cb04873a26f (diff) | |
download | emacs-8040d99b6294ad798d4ab677ba20082b45fd2e7d.tar.gz emacs-8040d99b6294ad798d4ab677ba20082b45fd2e7d.tar.bz2 emacs-8040d99b6294ad798d4ab677ba20082b45fd2e7d.zip |
Amend a cache so that typing into C++ raw strings has no undue delay.
Also amend the code so that low-level searches to the end of literals are done
only when these positions get used.
* lisp/progmodes/cc-engine.el (c-crosses-statement-barrier-p): Use the new
c-literal-start instead of c-literal-limit.
(c-state-semi-nonlit-pos-cache): Change the structure of this cache, such that
it stores details of the literal at a point, rather than merely points outside
of literals.
(c-state-semi-pp-to-literal, c-state-full-pp-to-literal)
(c-cache-to-parse-ps-state, c-parse-ps-state-to-cache, c-ps-state-cache-pos)
(c-parse-ps-state-below, c-literal-start): New functions.
(c-state-semi-safe-place): Removed.
(c-in-literal): Use c-state-semi-pp-to-literal, so as not to scan to its end.
(c-literal-limits, c-determine-limit-get-base): consequential amendments.
(c-find-decl-spots, c-before-change-check-<>-operators, c-raw-string-pos)
(c-guess-basic-syntax (CASE 2)): Avoid needless scans to end of literals.
* lisp/progmodes/cc-fonts.el (c-font-lock-doc-comments): Avoid needless scans
to end of literals.
* lisp/progmodes/cc-mode.el (c-fl-decl-start): Avoid needless scans to end of
literals.
* lisp/progmodes/cc-cmds.el (c-beginning-of-defun, c-end-of-defun)
(c-defun-name, c-declaration-limits): Avoid needless scans to end of literals.
Diffstat (limited to 'lisp/progmodes/cc-cmds.el')
-rw-r--r-- | lisp/progmodes/cc-cmds.el | 188 |
1 files changed, 94 insertions, 94 deletions
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el index 59f2729c43d..f0ad2942457 100644 --- a/lisp/progmodes/cc-cmds.el +++ b/lisp/progmodes/cc-cmds.el @@ -1610,8 +1610,8 @@ defun." ;; 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)) @@ -1734,8 +1734,8 @@ the open-parenthesis that starts a defun; see `beginning-of-defun'." ;; 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)) @@ -1793,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)) @@ -1880,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 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))))) - (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 - - ;; 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)) |