From aee46da90413a3706fbafee5e5291f1415e65e32 Mon Sep 17 00:00:00 2001 From: edam Date: Wed, 2 Oct 2019 10:13:00 +0100 Subject: [PATCH 1/4] added lua-indent-nested-block-content-align var --- README.md | 3 ++- lua-mode.el | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d2bcee5..536d482 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 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,7 @@ 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-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 af94a13..ed8484d 100644 --- a/lua-mode.el +++ b/lua-mode.el @@ -52,6 +52,9 @@ ;; - 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-mode-hook': ;; list of functions to execute when lua-mode is initialized ;; - Var `lua-documentation-url': @@ -359,6 +362,13 @@ 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-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 @@ -1260,7 +1270,8 @@ 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)) From a1f6d28c5d4f392b9f180934804f57bbcb47c262 Mon Sep 17 00:00:00 2001 From: edam Date: Mon, 18 Nov 2019 20:39:41 +0000 Subject: [PATCH 2/4] added lua-indent-close-paren-align var --- lua-mode.el | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lua-mode.el b/lua-mode.el index ed8484d..aecd35e 100644 --- a/lua-mode.el +++ b/lua-mode.el @@ -55,6 +55,9 @@ ;; - 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': @@ -369,6 +372,13 @@ 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 @@ -1548,7 +1558,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))))))) From 505896fbb771332d99b44c2f3f4e3f406a665a16 Mon Sep 17 00:00:00 2001 From: edam Date: Mon, 18 Nov 2019 21:11:40 +0000 Subject: [PATCH 3/4] added tests for lua-indent-nested-block-content-align and lua-indent-close-paren-align --- test/test-indentation.el | 83 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) 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 From 0cf8000bdaf5b98926d33ada531dfcb37e516220 Mon Sep 17 00:00:00 2001 From: edam Date: Tue, 19 Nov 2019 09:12:54 +0000 Subject: [PATCH 4/4] add lua-indent-close-paren-align to README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 536d482..1faec34 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ 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)