summaryrefslogtreecommitdiff
path: root/rust-mode.el
diff options
context:
space:
mode:
authorChris Rayner <riscy@users.noreply.github.com>2019-10-21 02:50:10 -0700
committerNathan Moreau <nathan.moreau@m4x.org>2019-10-21 11:50:10 +0200
commit1d42d6981877100bff4e643f6374cee0a15e733f (patch)
treee9e9c158a4a2dc2ae81944f62aca1a8d86ca63ff /rust-mode.el
parent7e2533f00e7b8e2f0b1f81a124263fdfb58cdc84 (diff)
downloadrust-mode-1d42d6981877100bff4e643f6374cee0a15e733f.tar.gz
Speed up line indentation inside strings (#313)
Diffstat (limited to 'rust-mode.el')
-rw-r--r--rust-mode.el14
1 files changed, 8 insertions, 6 deletions
diff --git a/rust-mode.el b/rust-mode.el
index 7b14d04..b912140 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -365,11 +365,8 @@ buffer."
((nth 3 (syntax-ppss))
(let*
((string-begin-pos (nth 8 (syntax-ppss)))
- (end-of-prev-line-pos (when (> (line-number-at-pos) 1)
- (save-excursion
- (forward-line -1)
- (end-of-line)
- (point)))))
+ (end-of-prev-line-pos (unless (rust--same-line-p (point) (point-min))
+ (line-end-position 0))))
(when
(and
;; If the string begins with an "r" it's a raw string and
@@ -389,7 +386,7 @@ buffer."
;; Indent to the same level as the previous line, or the
;; start of the string if the previous line starts the string
- (if (= (line-number-at-pos end-of-prev-line-pos) (line-number-at-pos string-begin-pos))
+ (if (rust--same-line-p end-of-prev-line-pos string-begin-pos)
;; The previous line is the start of the string.
;; If the backslash is the only character after the
;; string beginning, indent to the next indent
@@ -530,6 +527,11 @@ buffer."
(indent-line-to indent)
(save-excursion (indent-line-to indent))))))
+(defun rust--same-line-p (pos1 pos2)
+ "Return non-nil if POS1 and POS2 are on the same line."
+ (save-excursion (= (progn (goto-char pos1) (line-end-position))
+ (progn (goto-char pos2) (line-end-position)))))
+
;; Font-locking definitions and helpers
(defconst rust-mode-keywords