|
20 | 20 | "Set variable VAR to value VAL in current buffer."
|
21 | 21 | (list 'set (list 'make-local-variable (list 'quote var)) val))))
|
22 | 22 |
|
| 23 | +(defun rust-looking-back-str (str) |
| 24 | + "Like `looking-back' but for fixed strings rather than regexps (so that it's not so slow)" |
| 25 | + (let ((len (length str))) |
| 26 | + (and (> (point) len) |
| 27 | + (equal str (buffer-substring-no-properties (- (point) len) (point)))))) |
| 28 | + |
| 29 | +(defun rust-looking-back-symbols (SYMS) |
| 30 | + "Return non-nil if the point is just after a complete symbol that is a member of the list of strings SYMS" |
| 31 | + (save-excursion |
| 32 | + (let* ((pt-orig (point)) |
| 33 | + (beg-of-symbol (progn (forward-thing 'symbol -1) (point))) |
| 34 | + (end-of-symbol (progn (forward-thing 'symbol 1) (point)))) |
| 35 | + (and |
| 36 | + (= end-of-symbol pt-orig) |
| 37 | + (member (buffer-substring-no-properties beg-of-symbol pt-orig) SYMS))))) |
| 38 | + |
| 39 | +(defun rust-looking-back-ident () |
| 40 | + "Non-nil if we are looking backwards at a valid rust identifier" |
| 41 | + (let ((beg-of-symbol (save-excursion (forward-thing 'symbol -1) (point)))) |
| 42 | + (looking-back rust-re-ident beg-of-symbol))) |
| 43 | + |
23 | 44 | ;; Syntax definitions and helpers
|
24 | 45 | (defvar rust-mode-syntax-table
|
25 | 46 | (let ((table (make-syntax-table)))
|
|
77 | 98 | (defun rust-rewind-irrelevant ()
|
78 | 99 | (let ((starting (point)))
|
79 | 100 | (skip-chars-backward "[:space:]\n")
|
80 |
| - (if (looking-back "\\*/" nil) (backward-char)) |
| 101 | + (if (rust-looking-back-str "*/") (backward-char)) |
81 | 102 | (if (rust-in-str-or-cmnt)
|
82 | 103 | (rust-rewind-past-str-cmnt))
|
83 | 104 | (if (/= starting (point))
|
|
141 | 162 | ;;
|
142 | 163 | ((skip-dot-identifier
|
143 | 164 | (lambda ()
|
144 |
| - (when (looking-back (concat "\\." rust-re-ident) nil) |
| 165 | + (when (and (rust-looking-back-ident) (save-excursion (forward-thing 'symbol -1) (= ?. (char-before)))) |
145 | 166 | (forward-thing 'symbol -1)
|
146 | 167 | (backward-char)
|
147 | 168 | (- (current-column) rust-indent-offset)))))
|
148 | 169 | (cond
|
149 | 170 | ;; foo.bar(...)
|
150 |
| - ((looking-back ")" nil) |
| 171 | + ((rust-looking-back-str ")") |
151 | 172 | (backward-list 1)
|
152 | 173 | (funcall skip-dot-identifier))
|
153 | 174 |
|
|
271 | 292 | ;; ..or if the previous line ends with any of these:
|
272 | 293 | ;; { ? : ( , ; [ }
|
273 | 294 | ;; then we are at the beginning of an expression, so stay on the baseline...
|
274 |
| - (looking-back "[(,:;?[{}]\\|[^|]|" nil) |
| 295 | + (looking-back "[(,:;?[{}]\\|[^|]|" (- (point) 2)) |
275 | 296 | ;; or if the previous line is the end of an attribute, stay at the baseline...
|
276 | 297 | (progn (rust-rewind-to-beginning-of-current-level-expr) (looking-at "#")))))
|
277 | 298 | baseline
|
|
0 commit comments