Lua indentation in Vim

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Lua indentation in Vim

Hugo Musso Gualandi
Hi everyone,

One thing that has been bugging me lately is that the default
indentation scripts that Vim ships for Lua often don't do what I want,
requiring me to fix their output by hand.

For example, Vim doesn't add extra indentation to function parameters
that continue on a second line, and it doesn't automatically unindent a
"then" when it appears on a line by itself, like it does with "end":


    print(1,2,3,
    4,5,6)

    if condition
        then
            x = 1
        end

Searching the web, it appears that there are many different people who
have tried to develop better Lua indentation scripts for Lua:

https://github.com/tbastos/vim-lua
https://github.com/drmingdrmer/vim-indent-lua
https://github.com/raymond-w-ko/vim-lua-indent
https://gist.github.com/bonsaiviking/8845871

My questions to this list are as follows:

- Is anyone else bothered by the Vim's Lua indentation like I am?
- Do any of you use custom Vim indentation scripts? (Which one?)
- What we can do to improve Lua indentation in upstream Vim?

I'm very curious what you all have to say about this.

-- Hugo

Reply | Threaded
Open this post in threaded view
|

Re: Lua indentation in Vim

Jeff Pohlmeyer
On Mar 10, 2018 3:49 PM, Hugo Musso Gualandi wrote:

> One thing that has been bugging me lately is that the default
> indentation scripts that Vim ships for Lua often don't do what I want,
> requiring me to fix their output by hand.
...
> I'm very curious what you all have to say about this.

A few years ago somebody posted an editor-agnostic Lua parser
designed for this sort of thing. Can't remember the name of the
project but maybe someone here knows.

- Jeff

Reply | Threaded
Open this post in threaded view
|

Re: Lua indentation in Vim

Jeff Pohlmeyer
On Mar 10, 2018 at 3:54 PM, Jeff Pohlmeyer wrote:
> A few years ago somebody posted an editor-agnostic Lua parser
> designed for this sort of thing. Can't remember the name of the
> project but maybe someone here knows.

This was one:
https://bitbucket.org/jean_luc/luasyntaxer

(But it seems like there may have been another that specifically mentioned vim.)

 - Jeff

Reply | Threaded
Open this post in threaded view
|

Re: Lua indentation in Vim

Jeff Pohlmeyer
On Mar 10, 2018 at 4:03 PM, Jeff Pohlmeyer wrote:
> (But it seems like there may have been another that specifically mentioned vim.)

This may have been what I was thinking of. Looks like it doesn't handle
indentation after all, but still might be interesting:

https://github.com/xolox/vim-lua-inspect

PS Sorry so noisy, I'll try to shut up now...

 - Jeff

Reply | Threaded
Open this post in threaded view
|

Re: Lua indentation in Vim

Dirk Laurie-2
In reply to this post by Hugo Musso Gualandi
2018-03-10 23:49 GMT+02:00 Hugo Musso Gualandi <[hidden email]>:

> - Is anyone else bothered by the Vim's Lua indentation like I am?
> - Do any of you use custom Vim indentation scripts? (Which one?)
> - What we can do to improve Lua indentation in upstream Vim?

I use highlighting, and find it very useful since it flags unmatched
delimiters, even 'end'.

I stopped using automatic indentation when I stopped writing Python.

I get an extra second's thinking time while I type the spaces myself,
which generally repays itself in the quality of my first-time code.

Reply | Threaded
Open this post in threaded view
|

Re: Lua indentation in Vim

Bruce Hill
In reply to this post by Hugo Musso Gualandi

On Mar 10, 2018, at 1:49 PM, Hugo Musso Gualandi <[hidden email]> wrote:

My questions to this list are as follows:

- Is anyone else bothered by the Vim's Lua indentation like I am?
- Do any of you use custom Vim indentation scripts? (Which one?)
- What we can do to improve Lua indentation in upstream Vim?


It's occasionally annoying, but most of the irregularities are only mildly inconvenient. The one that really frustrates me though, is that the indentation is completely unaware of long bracket strings. For example, this code prints "This sentence is the\nend of the paragraph.":

if true then
    pcall(function()
        print[[
This sentence is the
end of the paragraph.]]
    end)
end

But it gets auto-indented into code with not only bad indentation, but also completely different behavior (the code now prints "        This sentence is the\n    end of the paragraph."):

if true then
    pcall(function()
        print[[
        This sentence is the
    end of the paragraph.]]
end)
end

Since I've been doing a bunch of work with dynamically generated Lua code, this particular issue is actually something that has bothered me a lot. It's really more of a Vim problem than a Lua problem though. If you want Vim's default Lua indentation to improve, you'd need to get a patch to this file approved:


signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Lua indentation in Vim

James Darnley
In reply to this post by Hugo Musso Gualandi
On 2018-03-10 22:49, Hugo Musso Gualandi wrote:
> - Is anyone else bothered by the Vim's Lua indentation like I am?

Yes.  I sometimes get frustrated by its poor auto-indentation, at least
compared to what I see/expect it to do with C files.

I wrote part of this draft just after you first email but I never sent
it.  Today it reminded me of this thread.  Have you made any progress?

> https://github.com/tbastos/vim-lua
> https://github.com/drmingdrmer/vim-indent-lua
> https://github.com/raymond-w-ko/vim-lua-indent
> https://gist.github.com/bonsaiviking/8845871

Anyone tried any of these?  Do you use anything else?

> - What we can do to improve Lua indentation in upstream Vim?

Learn Vim's syntax, make a good parser for Lua, use it to indent as you
want, submit a patch to upstream, volunteer to maintain the code.  I'm
willing to help test things but I don't think I have time right now to
learn Vim script in depth nor to maintain it.  Having said that I also
want better syntax highlighting and indentation for x86 assembly in Vim.


signature.asc (616 bytes) Download Attachment