emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/rust-mode 1d42d69 416/486: Speed up line indentation insid


From: ELPA Syncer
Subject: [nongnu] elpa/rust-mode 1d42d69 416/486: Speed up line indentation inside strings (#313)
Date: Sat, 7 Aug 2021 09:26:05 -0400 (EDT)

branch: elpa/rust-mode
commit 1d42d6981877100bff4e643f6374cee0a15e733f
Author: Chris Rayner <riscy@users.noreply.github.com>
Commit: Nathan Moreau <nathan.moreau@m4x.org>

    Speed up line indentation inside strings (#313)
---
 rust-mode.el | 14 ++++++++------
 1 file 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]