ZhiyuanLck / smart-pairs

Ultimate smart pairs written in lua!
MIT License
137 stars 2 forks source link

Infer indentation from previous line #13

Open Bruflot opened 2 years ago

Bruflot commented 2 years ago

I typically do not indent namespaces in C++. If I define a namespace and hit enter, smart-pairs will automatically indent my cursor. Even if I manually remove the indentation, it will disregard that if I insert another pair of braces.

For example, let's say I have the following code:

namespace
{
constexpr uint8_t X = 123;
}

If my cursor is placed at the semicolon and I hit enter, smart-pairs will indent my cursor on the next line. If I yet again manually remove the indentation and, say, define a function, it will indent the braces on the next line, and then indent the following code once more.

namespace
{
constexpr uint8_t X = 123;
void test()
    {
        | (cursor is now here)
    }
}

The desired behavior here would be for smart-pairs to not indent the braces following test() and instead use the same indentation as the line above it. I don't mind manually removing the initial indentation from the namespace as long as I don't have to do it more than once.

ZhiyuanLck commented 2 years ago

For your first example, you can set delete.empty_line.trigger_indent_level to 0 as a temporary workaround. This issue will be solved after refactoring the code of deletion and enter.

ZhiyuanLck commented 2 years ago

Now relative indent level is calculated correctly and trigger_indent_level is set to 0 by default. The wrong indentation of enter may be caused by cindent option, please check it by :echo &cindent.

Bruflot commented 2 years ago

Disabling cindent works, but I get similar issues with other languages. It'd be quite the downside to have to disable all the built-in formatting capabilities of VIm just to use this plugin. It seems other autopairs-esque plugins handle this by removing the inserted indent. Do you think something similar should be done for smart-pairs?

ZhiyuanLck commented 2 years ago

I do not handle such cases just because I want to ultilize the internal indent mechanism of the vim. Since the vallian indentation is not so satisfied. I'll provide an option to totally replace the original Enter later.