[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 5231709 177/486: Speed up calls to "looking-back
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 5231709 177/486: Speed up calls to "looking-back" |
Date: |
Sat, 7 Aug 2021 09:25:13 -0400 (EDT) |
branch: elpa/rust-mode
commit 52317099f160869f37d9b02e279db4ab474c26a3
Author: Micah Chalmer <micah@micahchalmer.net>
Commit: Micah Chalmer <micah@micahchalmer.net>
Speed up calls to "looking-back"
---
rust-mode.el | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/rust-mode.el b/rust-mode.el
index 193f672..05d8528 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -20,6 +20,27 @@
"Set variable VAR to value VAL in current buffer."
(list 'set (list 'make-local-variable (list 'quote var)) val))))
+(defun rust-looking-back-str (str)
+ "Like `looking-back' but for fixed strings rather than regexps (so that it's
not so slow)"
+ (let ((len (length str)))
+ (and (> (point) len)
+ (equal str (buffer-substring-no-properties (- (point) len)
(point))))))
+
+(defun rust-looking-back-symbols (SYMS)
+ "Return non-nil if the point is just after a complete symbol that is a
member of the list of strings SYMS"
+ (save-excursion
+ (let* ((pt-orig (point))
+ (beg-of-symbol (progn (forward-thing 'symbol -1) (point)))
+ (end-of-symbol (progn (forward-thing 'symbol 1) (point))))
+ (and
+ (= end-of-symbol pt-orig)
+ (member (buffer-substring-no-properties beg-of-symbol pt-orig) SYMS)))))
+
+(defun rust-looking-back-ident ()
+ "Non-nil if we are looking backwards at a valid rust identifier"
+ (let ((beg-of-symbol (save-excursion (forward-thing 'symbol -1) (point))))
+ (looking-back rust-re-ident beg-of-symbol)))
+
;; Syntax definitions and helpers
(defvar rust-mode-syntax-table
(let ((table (make-syntax-table)))
@@ -77,7 +98,7 @@
(defun rust-rewind-irrelevant ()
(let ((starting (point)))
(skip-chars-backward "[:space:]\n")
- (if (looking-back "\\*/" nil) (backward-char))
+ (if (rust-looking-back-str "*/") (backward-char))
(if (rust-in-str-or-cmnt)
(rust-rewind-past-str-cmnt))
(if (/= starting (point))
@@ -141,13 +162,13 @@
;;
((skip-dot-identifier
(lambda ()
- (when (looking-back (concat "\\." rust-re-ident) nil)
+ (when (and (rust-looking-back-ident) (save-excursion
(forward-thing 'symbol -1) (= ?. (char-before))))
(forward-thing 'symbol -1)
(backward-char)
(- (current-column) rust-indent-offset)))))
(cond
;; foo.bar(...)
- ((looking-back ")" nil)
+ ((rust-looking-back-str ")")
(backward-list 1)
(funcall skip-dot-identifier))
@@ -271,7 +292,7 @@
;; ..or if the previous line ends with any of these:
;; { ? : ( , ; [ }
;; then we are at the beginning of an expression, so
stay on the baseline...
- (looking-back "[(,:;?[{}]\\|[^|]|" nil)
+ (looking-back "[(,:;?[{}]\\|[^|]|" (- (point) 2))
;; or if the previous line is the end of an
attribute, stay at the baseline...
(progn
(rust-rewind-to-beginning-of-current-level-expr) (looking-at "#")))))
baseline
- [nongnu] elpa/rust-mode 42730b1 144/486: Merge pull request #49 from huonw/playpen, (continued)
- [nongnu] elpa/rust-mode 42730b1 144/486: Merge pull request #49 from huonw/playpen, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 249e3ce 134/486: Merge pull request #40 from MicahChalmer/fix-comment-typos, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 31ceb60 135/486: Indent inside strings after ending backslash, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 22c8cfa 138/486: Merge pull request #43 from MicahChalmer/indent-backslash-strings, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ce976b9 145/486: Fix "-> Type" on a single line indentation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f2f4d67 158/486: Merge pull request #59 from lunaryorn/fix-byte-compiler-warnings, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ddf45ed 146/486: Use (goto-char (point-max)) instead of (end-of-buffer) to silence warning., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0077bbf 160/486: Fix package.el URL, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 86db9bd 166/486: Merge pull request #65 from tromey/blink-matching-paren, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 53c558c 175/486: Factor out rust-conditional-re-search-forward, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5231709 177/486: Speed up calls to "looking-back",
ELPA Syncer <=
- [nongnu] elpa/rust-mode c801dda 197/486: Merge pull request #77 from tromey/fix-byte-compiler-add-lexbind, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode cdaf3fc 201/486: Update MELPA URL, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 1761a9c 204/486: Merge pull request #105 from MicahChalmer/remove-misc, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f8d94cb 229/486: Use catch and throw instead of block and return, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 40c33fd 250/486: add code to handle new-style rustc errors, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode c69adaf 254/486: Add menu titles for items in imenu, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode dae5af7 298/486: Merge pull request #198 from tromey/indentation-fix, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bfe4056 452/486: Re-implement rust-in-macro for performance, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode eaf95af 210/486: Merge pull request #111 from mrBliss/where-indentation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2540d7e 262/486: Go back to the current line and column after formatting., ELPA Syncer, 2021/08/07