GithubHelp home page GithubHelp logo

No indent in LUA files about treesj HOT 7 CLOSED

tummetott avatar tummetott commented on June 18, 2024
No indent in LUA files

from treesj.

Comments (7)

Wansmer avatar Wansmer commented on June 18, 2024

Hello, I think, you have 'shiftwidth' equals 0 for filetype 'lua'.
Indent calculating on value of 'shiftwidth'.
Try :lua =vim.bo.shiftwidth. If it will be '0', set option shiftwitdh bigger than 0 in your init.lua.

from treesj.

tummetott avatar tummetott commented on June 18, 2024

Thank you for the quick response.
Yes it's true i have shiftwith = 0 because when zero, it defaults to tabstop. And I have tabstop = 4.
Interestingly, when inside e.g..js or .py files, the indent works properly with shiftwith = 0. Is this intended, that .lua files are treated differently?

Setting shiftwith to 4 would solve my problem, however I like having shiftwith bound to my tabstop. If it's not too complicated, I'd love to see a fix but otherwise i'll just change my shiftwith value.

Great plugin by the way ❤️

from treesj.

Wansmer avatar Wansmer commented on June 18, 2024

Thanks for feedback.
I not sure what it needs to be fixed, because shiftwidth is a default for builtin neovim indent engine.

Try set expandtab to false – it will save tabs instead of spaces and you can use shiftwidth.

Is this intended, that .lua files are treated differently?

I think, it sets by neovim's directly. Neovim have builtin preset for different filetypes.

from treesj.

tummetott avatar tummetott commented on June 18, 2024

Yes it's true, shiftwith is a default. However you can not take that value literally.

Output from :help shiftwith:

Number of spaces to use for each step of (auto)indent.
Used for 'cindent', >>, <<, etc. When zero the 'ts' value will be used.

That means, whenever shiftwidth is set to zero, the true value of shiftwidth is the value of tabstop. The zero just denotes, that tabstop and shiftwith are bound together.

You're using the shiftwidth literally in two palces:

local shiftwidth = vim.api.nvim_buf_get_option(0, 'shiftwidth')

local sw = vim.api.nvim_buf_get_option(0, 'shiftwidth')

An additional check like the following would solve the issue:

if shiftwidth == 0 then
    shiftwidth = vim.api.nvim_buf_get_option(0, 'tabstop') 
end

I'd do a PR, but i don't understand the logic of your plugin. Do when do you use the calc_indent() and when the build_tree() function? Do you need to change it in both places? I guess you have a better understanding of that.

from treesj.

tummetott avatar tummetott commented on June 18, 2024

I think, it sets by neovim's directly. Neovim have builtin preset for different filetypes.

You're right with that. The global value was overwritten by ftplugin. Thanks for the clarification

from treesj.

Wansmer avatar Wansmer commented on June 18, 2024

That means, whenever shiftwidth is set to zero, the true value of shiftwidth is the value of tabstop. The zero just denotes, that tabstop and shiftwith are bound together.

I use shiftwidth in a logic way – because it about indentation. tabstop it only about width of tabulation.
I'll learn a little more about interconnections of tabstop and shiftwidth. At the moment, sw looks the best values for use.

from treesj.

f1rstlady avatar f1rstlady commented on June 18, 2024

An additional check like the following would solve the issue:

if shiftwidth == 0 then
    shiftwidth = vim.api.nvim_buf_get_option(0, 'tabstop') 
end

The shiftwidth() function returns the effective value of 'shiftwidth'; see :h shiftwidth().

from treesj.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.