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

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

[nongnu] elpa/lua-mode 562540e 073/468: Fix lua-calculate-indentation: i


From: Philip Kaludercic
Subject: [nongnu] elpa/lua-mode 562540e 073/468: Fix lua-calculate-indentation: indent to 0 when inside string literal
Date: Thu, 5 Aug 2021 04:58:10 -0400 (EDT)

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

    Fix lua-calculate-indentation: indent to 0 when inside string literal
    
    Otherwise, all the whitespace by which the line is to be indented will get 
into the literal
---
 lua-mode.el | 55 +++++++++++++++++++++++++++++++------------------------
 1 file changed, 31 insertions(+), 24 deletions(-)

diff --git a/lua-mode.el b/lua-mode.el
index 2ab926b..fcb7ea2 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -811,30 +811,37 @@ In usual case returns an integer: the column to indent 
to."
   (let ((pos (point))
         shift-amt)
     (save-excursion
-      (if parse-start (setq pos (goto-char parse-start)))
-      (beginning-of-line)
-      (setq shift-amt (if (lua-is-continuing-statement-p) lua-indent-level 0))
-      (if (bobp)          ; If we're at the beginning of the buffer, no change.
-          (+ (current-indentation) shift-amt)
-        ;; This code here searches backwards for a "block beginning/end"
-        ;; It snarfs the indentation of that, plus whatever amount the
-        ;; line was shifted left by, because of block end tokens. It
-        ;; then adds the indentation modifier of that line to obtain the
-        ;; final level of indentation.
-        ;; Finally, if this line continues a statement from the
-        ;; previous line, add another level of indentation.
-        (if (lua-backwards-to-block-begin-or-end)
-            ;; now we're at the line with block beginning or end.
-            (max (+ (current-indentation)
-                    (lua-calculate-indentation-block-modifier)
-                    shift-amt)
-                 0)
-          ;; Failed to find a block begin/end.
-          ;; Just use the previous line's indent.
-          (goto-char pos)
-          (beginning-of-line)
-          (forward-line -1)
-          (+ (current-indentation) shift-amt))))))
+      (catch 'indent
+        (if parse-start (setq pos (goto-char parse-start)))
+        (beginning-of-line)
+
+        ;; if bol is inside a string, suppress any indentation
+        ;; or all of the whitespace will go into the literal
+        (when (lua-string-p)
+          (throw 'indent 0))
+
+        (setq shift-amt (if (lua-is-continuing-statement-p) lua-indent-level 
0))
+        (if (bobp)          ; If we're at the beginning of the buffer, no 
change.
+            (+ (current-indentation) shift-amt)
+          ;; This code here searches backwards for a "block beginning/end"
+          ;; It snarfs the indentation of that, plus whatever amount the
+          ;; line was shifted left by, because of block end tokens. It
+          ;; then adds the indentation modifier of that line to obtain the
+          ;; final level of indentation.
+          ;; Finally, if this line continues a statement from the
+          ;; previous line, add another level of indentation.
+          (if (lua-backwards-to-block-begin-or-end)
+              ;; now we're at the line with block beginning or end.
+              (max (+ (current-indentation)
+                      (lua-calculate-indentation-block-modifier)
+                      shift-amt)
+                   0)
+            ;; Failed to find a block begin/end.
+            ;; Just use the previous line's indent.
+            (goto-char pos)
+            (beginning-of-line)
+            (forward-line -1)
+            (+ (current-indentation) shift-amt)))))))
 
 (defun lua-beginning-of-proc (&optional arg)
   "Move backward to the beginning of a lua proc (or similar).



reply via email to

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