[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode 0b3df35 135/468: Fix string content indentation:
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode 0b3df35 135/468: Fix string content indentation: it's now indented by indent-level relative to indentation of the line where string/comment literal starts (issue #6) |
Date: |
Thu, 5 Aug 2021 04:58:22 -0400 (EDT) |
branch: elpa/lua-mode
commit 0b3df35c0d830f35c52553c18050f9e0401a48b0
Author: immerrr <immerrr@gmail.com>
Commit: immerrr <immerrr@gmail.com>
Fix string content indentation: it's now indented by indent-level relative
to indentation of the line where string/comment literal starts (issue #6)
---
lua-mode.el | 38 +++++++++++++++++++++++++-------------
1 file changed, 25 insertions(+), 13 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index 4a6d98c..4abe24d 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -450,19 +450,31 @@ Return the amount the indentation changed by."
;; save point as a distance to eob - it's invariant w.r.t indentation
(pos (- (point-max) (point))))
(back-to-indentation)
- (if (and (not lua-indent-string-contents) (lua-string-p))
- (goto-char (- (point-max) pos)) ;; just restore point position
-
+ (if (lua-comment-or-string-p)
+ (setq indent (lua-calculate-string-or-comment-indentation)) ;; just
restore point position
(setq indent (max 0 (- (lua-calculate-indentation nil)
- (lua-calculate-unindentation))))
- (when (not (equal indent (current-column)))
- (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)))
- indent)))
+ (lua-calculate-unindentation)))))
+
+ (when (not (equal indent (current-column)))
+ (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)))
+
+ indent))
+
+(defun lua-calculate-string-or-comment-indentation ()
+ "This function should be run when point at (current-indentation) is inside
string"
+ (if (and (lua-string-p) (not lua-indent-string-contents))
+ ;; if inside string and strings aren't to be indented, return current
indentation
+ (current-indentation)
+ ;; otherwise indent by lua-indent-level relative to the line where literal
starts
+ (save-excursion
+ (goto-char (lua-get-multiline-start))
+ (+ (current-indentation) lua-indent-level))))
(defun lua-find-regexp (direction regexp &optional limit ignore-p)
"Searches for a regular expression in the direction specified.
@@ -669,7 +681,7 @@ previous one even though it looked like an
end-of-statement."
;; if first character of the line is inside string, it's a continuation
;; if strings aren't supposed to be indented,
`lua-calculate-indentation' won't even let
;; the control inside this function
- (or (lua-comment-or-string-p) (re-search-forward lua-cont-bol-regexp
line-end t)))))
+ (re-search-forward lua-cont-bol-regexp line-end t))))
(defun lua-is-continuing-statement-p (&optional parse-start)
"Return non-nil if the line continues a statement.
- [nongnu] elpa/lua-mode 6b1d389 074/468: lua-calculate-unindentation: skip semicolons as well, (continued)
- [nongnu] elpa/lua-mode 6b1d389 074/468: lua-calculate-unindentation: skip semicolons as well, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode bda4fbd 075/468: lua-calculate-unindentation: update docs, remove extraneous catch, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a20b08e 078/468: lua-indent-line: remove extra variable shift-amt, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c0d6f80 079/468: Add markdown README, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 08cff6e 081/468: Implement basic multiline-aware functionality, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode dfc3b78 083/468: Preserve buffer-modified-p state when (un-)marking multiline delimiters, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 7920d17 087/468: lua-mark-all-multiline-literals: if region is active, limit to region boundaries, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4a22b3c 100/468: Allow lua-start-process to be called interactively., Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a3ed448 106/468: Make dist with git-archive, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 742180e 125/468: lua-automark-multiline: add lua-automark-multiline-maxsize variable to prevent long waits on big files, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 0b3df35 135/468: Fix string content indentation: it's now indented by indent-level relative to indentation of the line where string/comment literal starts (issue #6),
Philip Kaludercic <=
- [nongnu] elpa/lua-mode 5aa6f9e 042/468: Patch from Reuben: fix long string colouring problem, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode eb5d301 055/468: Bump version., Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d66ec8e 080/468: Remove broken multiline literal font-locking, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d142ed1 084/468: Update TODO, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode de12f4b 086/468: lua-mark-all-multiline-literals: also handle multiline comments, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 46683e7 052/468: Make lua-indent-level customizable., Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 3c89a0a 054/468: Reorder customizations better., Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 158f267 058/468: Merge lua-goto-nonblank-* funcs into one, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c5f37b0 088/468: lua-mark-all-multiline-literals: look for multiline ending beyond specified bounds to improve integrity, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 96658a0 089/468: Move actual marking of multiline construct into lua-mark-multiline-region, Philip Kaludercic, 2021/08/05