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

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

[nongnu] elpa/lua-mode a3a71b1 400/468: Merge pull request #151 from eda


From: Philip Kaludercic
Subject: [nongnu] elpa/lua-mode a3a71b1 400/468: Merge pull request #151 from edam/indent-nested-blocks
Date: Thu, 5 Aug 2021 04:59:17 -0400 (EDT)

branch: elpa/lua-mode
commit a3a71b155ab63a64c077a48d1f83596b388bd564
Merge: 5dfc5be 0cf8000
Author: immerrr again <immerrr+lua@gmail.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #151 from edam/indent-nested-blocks
    
    Enhance indentation of blocks
---
 README.md                |  4 ++-
 lua-mode.el              | 26 +++++++++++++--
 test/test-indentation.el | 83 +++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 109 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index d2bcee5..1faec34 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ modules to your Emacs and keeping them up-to-date. Once you 
have **el-get** set
 and updating is no more than
 
     <M-x> el-get-update "lua-mode"`
-    
+
 Please, consult with [el-get 
documentation](https://github.com/dimitri/el-get/blob/master/README.md) for 
further information.
 
 ### MANUAL INSTALLATION
@@ -53,6 +53,8 @@ The following variables are available for customization (see 
more via `M-x custo
 
 - Var `lua-indent-level` (default `3`): indentation offset in spaces
 - Var `lua-indent-string-contents` (default `nil`): set to `t` if you like to 
have contents of multiline strings to be indented like comments
+- Var `lua-indent-nested-block-content-align` (default `t`) set to `nil` to 
stop aligning the content of nested blocks with the open parenthesis
+- Var `lua-indent-close-paren-align` (defaut `t`) set to `t` to align close 
parenthesis with the open parenthesis rather than with the beginning of the line
 - Var `lua-mode-hook`: list of functions to execute when lua-mode is 
initialized
 - Var `lua-documentation-url` (default 
`"http://www.lua.org/manual/5.1/manual.html#pdf-"`): base URL for documentation 
lookup
 - Var `lua-documentation-function` (default `browse-url`): function used to 
show documentation (`eww` is a viable alternative for Emacs 25)
diff --git a/lua-mode.el b/lua-mode.el
index e75b7da..107dbc4 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -53,6 +53,12 @@
 ;; - Var `lua-indent-string-contents':
 ;;   set to `t` if you like to have contents of multiline strings to be
 ;;   indented like comments
+;; - Var `lua-indent-nested-block-content-align':
+;;   set to `nil' to stop aligning the content of nested blocks with the
+;;   open parenthesis
+;; - Var `lua-indent-close-paren-align':
+;;   set to `t' to align close parenthesis with the open parenthesis,
+;;   rather than with the beginning of the line
 ;; - Var `lua-mode-hook':
 ;;   list of functions to execute when lua-mode is initialized
 ;; - Var `lua-documentation-url':
@@ -399,6 +405,20 @@ Otherwise leading amount of whitespace on each line is 
preserved."
   :group 'lua
   :type 'boolean)
 
+(defcustom lua-indent-nested-block-content-align t
+  "If non-nil, the contents of nested blocks are indented to
+align with the column of the opening parenthesis, rather than
+just forward by `lua-indent-level'."
+  :group 'lua
+  :type 'boolean)
+
+(defcustom lua-indent-close-paren-align t
+  "If non-nil, close parenthesis are aligned with their open
+parenthesis.  If nil, close parenthesis are aligned to the
+beginning of the line."
+  :group 'lua
+  :type 'boolean)
+
 (defcustom lua-jump-on-traceback t
   "*Jump to innermost traceback location in *lua* buffer.  When this
 variable is non-nil and a traceback occurs when running Lua code in a
@@ -1306,7 +1326,8 @@ Don't use standalone."
     (cons 'relative lua-indent-level))
 
    ;; block openers
-   ((member found-token (list "{" "(" "["))
+   ((and lua-indent-nested-block-content-align
+        (member found-token (list "{" "(" "[")))
     (save-excursion
       (let ((found-bol (line-beginning-position)))
         (forward-comment (point-max))
@@ -1580,7 +1601,8 @@ If not, return nil."
         (when (lua-goto-matching-block-token block-token-pos 'backward)
           ;; Exception cases: when the start of the line is an assignment,
           ;; go to the start of the assignment instead of the matching item
-          (if (lua-point-is-after-left-shifter-p)
+          (if (or (not lua-indent-close-paren-align)
+                  (lua-point-is-after-left-shifter-p))
               (current-indentation)
             (current-column)))))))
 
diff --git a/test/test-indentation.el b/test/test-indentation.el
index 44d2355..6c7c59d 100644
--- a/test/test-indentation.el
+++ b/test/test-indentation.el
@@ -501,10 +501,91 @@ foobar(
       b
    },
    c, d
-)"))))
+)")))
+
+  (it "indent blocks with lua-indent-nested-block-content-align"
+       (let ((lua-indent-nested-block-content-align nil))
+         (expect (lua--reindent-like "\
+call_some_fn( something, {
+      val = 5,
+      another = 6,
+} )"))
+         (expect (lua--reindent-like "\
+local def = {
+   some_very_long_name = { fn =
+         function()
+            return true
+         end
+   }
+}"))
+         ))
+
+  (it "indent blocks with lua-indent-close-paren-align"
+       (let ((lua-indent-close-paren-align nil))
+         (expect (lua--reindent-like "\
+local foo = setmetatable( {
+      a = 4,
+      b = 5,
+}, {
+      __index = some_func,
+} )"))
+         ))
+
+  (it "indents nested tables with alternative block indenting"
+       (let ((lua-indent-nested-block-content-align nil)
+                 (lua-indent-close-paren-align nil))
+         (expect (lua--reindent-like "\
+foobar({
+      a, b, c
+})"))
+
+         (expect (lua--reindent-like "\
+foobar(a, {
+      b,
+      c
+})"))
+
+         (expect (lua--reindent-like "\
+foobar(
+   a,
+   {
+      b,
+      c
+})"))
+
+         (expect (lua--reindent-like "\
+foobar(
+   a,
+   {
+      b,
+      c
+   }
+)"))
 
+         (expect (lua--reindent-like "\
+foobar(a,
+   {
+      b,
+      c
+})"))
 
+         (expect (lua--reindent-like "\
+foobar(a,
+   {
+      b,
+      c
+   }
+)"))
 
+         (expect (lua--reindent-like "\
+foobar(
+   {
+      a,
+      b
+   },
+   c, d
+)"))
+         )))
 
 (ert-deftest lua-indentation-defun ()
   ;;    [local] function funcname funcbody



reply via email to

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