Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 24 additions & 2 deletions lua-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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':
Expand Down Expand Up @@ -359,6 +365,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
Expand Down Expand Up @@ -1260,7 +1280,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))
Expand Down Expand Up @@ -1537,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)))))))

Expand Down
83 changes: 82 additions & 1 deletion test/test-indentation.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down