Lua Formatter ignores tab_size

Plugins for SynWrite and CudaText...
Post Reply
yabobay
Posts: 2
Joined: 27.09.2023 09:16
Contact:

Lua Formatter ignores tab_size

Post by yabobay »

I had `tab_size` and `indent_size` set to 2 in my user.json, but lua_fmt which i just installed indents things with 4 spaces by default. So i checked if lua_fmt is configurable, it's not.

So i checked in the source code, and found this:

Code: Select all

    def __str__(self):
        r = ''
        for node in self._nodes:
            r += str(node)
        enter_pos = r.find('\n')
        r = r[:enter_pos].strip(' ') + r[enter_pos:]
        if r.strip(' ') == '\n': return '\n' #20
        return ' ' * _settings.get('tab_size') * self._indent + r
So it's trying to pay attention to `tab_size`, but it's failing. if i change the call to `_settings.get('tab_size')` to another number myself, it uses that number. So it's somehow getting 4 from tab_size? I checked, and it doesn't look like i have any specific tab_size setting for the Lua lexer.
main Alexey
Posts: 2323
Joined: 25.08.2021 18:15

Re: Lua Formatter ignores tab_size

Post by main Alexey »

I opened the Lua formatter code: py/cuda_fmt_lua/__init__.py .
and i see it is hardcoded to 4 tab-size!

Code: Select all

from .lua_format import lua_format

def do_format(text):

    settings = {
        'tab_size': 4,
        'special_symbol_split': True,
        'bracket_split': False,
        }

    res = lua_format(text.splitlines(), settings)
    return res
change all file content to:

Code: Select all

from .lua_format import lua_format
import cudatext as app

def do_format(text):

    settings = {
        'tab_size': app.ed.get_prop(app.PROP_TAB_SIZE),
        'special_symbol_split': True,
        'bracket_split': False,
        }

    res = lua_format(text.splitlines(), settings)
    return res
seems it works ok now. if so, i will fix it in addons.
yabobay
Posts: 2
Joined: 27.09.2023 09:16
Contact:

Re: Lua Formatter ignores tab_size

Post by yabobay »

If i edit the file, will it get overwritten when an update comes out for the plugin? (That's what i want to happen)
main Alexey
Posts: 2323
Joined: 25.08.2021 18:15

Re: Lua Formatter ignores tab_size

Post by main Alexey »

yes, it will (if you did NOT use 'Install from Github' menu item).
main Alexey
Posts: 2323
Joined: 25.08.2021 18:15

Re: Lua Formatter ignores tab_size

Post by main Alexey »

i applied this fix and updated the addon in AddonsManager.
Post Reply