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

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

[nongnu] elpa/lua-mode 5fa9b81 077/468: lua-indent-line: don't change th


From: Philip Kaludercic
Subject: [nongnu] elpa/lua-mode 5fa9b81 077/468: lua-indent-line: don't change the indent if inside multiline string literal
Date: Thu, 5 Aug 2021 04:58:11 -0400 (EDT)

branch: elpa/lua-mode
commit 5fa9b81c6f2ee2d08fdf71d5d0e978ce9e1ae94c
Author: immerrr <immerrr@gmail.com>
Commit: immerrr <immerrr@gmail.com>

    lua-indent-line: don't change the indent if inside multiline string literal
---
 lua-mode.el | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/lua-mode.el b/lua-mode.el
index 9e69ff7..f304d9e 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -420,23 +420,27 @@ This function replaces previous prefix-key binding with a 
new one."
 (defun lua-indent-line ()
   "Indent current line for Lua mode.
 Return the amount the indentation changed by."
-  (let ((indent (max 0 (- (lua-calculate-indentation nil)
-                          (lua-calculate-unindentation))))
-        (beg (line-beginning-position))
+  (let (indent
         shift-amt
         (case-fold-search nil)
+        ;; save point as a distance to eob - it's invariant w.r.t indentation
         (pos (- (point-max) (point))))
     (back-to-indentation)
-    (setq shift-amt (- indent (current-column)))
-    (when (not (zerop shift-amt))
-      (delete-region beg (point))
-      (indent-to indent))
-    ;; If initial point was within line's indentation,
-    ;; position after the indentation.  Else stay at same point in text.
-    (if (> (- (point-max) pos) (point))
-        (goto-char (- (point-max) pos)))
-    shift-amt
-    indent))
+    (if (lua-string-p)  ;; don't indent if inside multiline string literal
+        (goto-char (- (point-max) pos)) ;; just restore point position
+
+      (setq indent (max 0 (- (lua-calculate-indentation nil)
+                             (lua-calculate-unindentation))))
+      (setq shift-amt (- indent (current-column)))
+      (when (not (zerop shift-amt))
+        (delete-region (line-beginning-position) (point))
+        (indent-to indent))
+      ;; If initial point was within line's indentation,
+      ;; position after the indentation.  Else stay at same point in text.
+      (if (> (- (point-max) pos) (point))
+          (goto-char (- (point-max) pos)))
+      shift-amt
+      indent)))
 
 (defun lua-find-regexp (direction regexp &optional limit ignore-p)
   "Searches for a regular expression in the direction specified.



reply via email to

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