[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
- [nongnu] elpa/lua-mode 56691b8 338/468: Add tests for preserving point location when filling, (continued)
- [nongnu] elpa/lua-mode 56691b8 338/468: Add tests for preserving point location when filling, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6daec31 342/468: utils: update to new buttercup matcher definition logic (#138), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a80d912 350/468: Fix a minor bug in lua-kill-process, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 5a90655 355/468: correct spelling mistake, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode aca4014 356/468: utils: update to new buttercup matcher definition logic (#138), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode e8281dc 362/468: Fix a minor bug in lua-kill-process, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1f04654 379/468: travis: enable testing on osx, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode eb93be5 380/468: Merge pull request #158 from immerrr/enable-testing-on-osx, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4cdee31 388/468: Use proper lexical-bindings instead of lexical-let*, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 5dfc5be 399/468: Merge pull request #168 from immerrr/index-requires-as-imenu-items, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a3a71b1 400/468: Merge pull request #151 from edam/indent-nested-blocks,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode 35b6e4c 402/468: Merge pull request #169 from tarsiiformes/typos, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 724bfa5 409/468: Fix support for file-local vars in indentation tests, add tests for blocks, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1365ba0 412/468: Enable XFAIL-ing tests for continuation in block intros, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 51a32ef 417/468: Merge pull request #176 from immerrr/improve-indentation-for-continuation-lines, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b37710e 418/468: Enable fontification of variable names in "for" and function parameters, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 9c275cd 419/468: Add regression test for issue #157, fix lua-get-line-faces, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 5fe5f57 422/468: Fix wait-for-prompt to take lua-prompt-regexp into account, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 83ec53d 430/468: `lua-funcname-at-point': be more strict, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 70b9384 448/468: Don't evaluate lua-is-continuing-statement-p-1 twice, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 350acce 450/468: Don't do lua-backward-up-list calculation for overrides if not necessary, Philip Kaludercic, 2021/08/05