Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete and new indent are not working #27

Closed
AchmadFathoni opened this issue Apr 5, 2021 · 7 comments
Closed

Delete and new indent are not working #27

AchmadFathoni opened this issue Apr 5, 2021 · 7 comments

Comments

@AchmadFathoni
Copy link

OS (name + version; i.e. Linux Mint 20, Windows 10 2004, Macos Big Sur, etc.): Arch Linux
What vim? (+ version) (i.e. vim, gvim, nvim, nvim-qt, mvim, ...): nvim 0.4.4
Reproduced in other variants of Vim? (Optional): vim 8.2.2653

Autopairs config (if applicable): Clean config, just

call plug#begin('~/.config/nvim/plugged')
Plug 'LunarWatcher/auto-pairs'
call plug#end()

Describe the bug

  • Delete pair: There is no different when hitting <BS> compared to without plugin, The original jiangmiao plugin doesn't have this issue.
  • New indented line: Hitting <CR> inside pair adds newline but it is not indented. The jiangmiao has this problem.

Steps to reproduce

  • Delete pair: Type [+<BS> produces ], expected to delete pair completely
  • Delete pair: Type [+<CR> + k produces
[
k
]

expected output:

[
     k
]
@AchmadFathoni AchmadFathoni added bug Something isn't working status:Triage labels Apr 5, 2021
@LunarWatcher
Copy link
Owner

BS isn't mapped by default;
(in part because it's relatively intrusive in the way it's designed atm - largely a biased, personal choice to do so); let g:AutoPairsMapBS = 1 enables it.

As for the CR problem, did you set autoindent? Since you're on a clean vimrc, there shouldn't be plugins or other mappings interfering, which leaves autoindent as the most likely suspect. Auto-pairs' auto-indent is just a happy side-effect of autoindent, smartindent, cindent, and/or indentexpr. Might actually be worth auto-setting autoindent or something just for good measure though, just to avoid this.

(I'm currently on my way to bed, so I'll read your reply tomorrow)

@AchmadFathoni
Copy link
Author

The delete pair issue is resolved. But the new line is still not indented even after I set autoindent and add let g:AutoPairsMapCR = 1 to my vimrc

@roachsinai
Copy link

@LunarWatcher thanks for your work! Maybe it't better to say user need enable at Feature delete part:

Delete in pair: >

        input: foo[<BS>]
        output: foo

@LunarWatcher
Copy link
Owner

Had to set cindent as well, which yields:

[
    k|
]

But this seems to be relatively context-dependent.

The same behavior isn't present for (), which yields:

(
 k|
)

(which happens with my config too)

#26 is a fairly interesting case though: using the same cino and other indent options, this (:e test.py):

def test():
    (<CR>)

Yields very different results.
With my config:

def test():
    (
        |
    )

but with both nvim and gvim on the same default config (shown after this block):

def test():
    (
            |
            )

With:

set nocompatible

filetype off

call plug#begin()
Plug 'LunarWatcher/auto-pairs'
call plug#end()

filetype on
filetype plugin indent on
filetype plugin on
set autoindent
set smartindent
set cindent

Doesn't help if I copy over my cino settings either - as a result, I'm not sure what's causing it to work with my config, but not with a relatively "plain" config for vim/nvim. Gonna need to disassemble my .vimrc later to track it down

@LunarWatcher
Copy link
Owner

Tracked it down to vim-polyglot.

To make a long story short:

set autoindent
set smartindent
set cindent

Enables some indentation. Configuration from there is required to make the resulting indentation sane, which I'm gonna have to look into whether or not I can do with just cino. The thing about setting up cino expressions is that I have to do as little as possible (and make it possible to turn off).

Polyglot does seem to reduce some indent problems in a few languages by providing custom indentexprs, but auto- and smartindent don't take effect in filetypeless buffers - in buffers like that, cindent has to be enabled for anything to happen, and speaking from some random testing, adjusting the exact indent doesn't seem to be as easy in those.

And just so that's clarified, I'm not gonna write a feature to indent manually for a number of reasons that're largely intertwined, and starts with tabs and spaces, and varying shiftwidth. The rest of the argument is fairly self-explanatory if you've seen how dedicated some people are to tabs vs. spaces and other styling options. I can detect shiftwidth, but not tab vs. space preference, and file-specific configuration from there is honestly a redundant use of code when vim has systems in place for it that only require a bit of config, apparently.

I'm gonna make a "sensible standard" for cino and make it optional to load (and possibly set the default depending on whether or not cino is blank just to avoid interfering - I'm under the general impression that most people don't touch cino settings, and that those who do usually prefer keeping theirs) to try make this a more out of the box experience, though.

@LunarWatcher
Copy link
Owner

... actually, that's not gonna work either. Python is one of the languages that don't do cindent, which means there's a number of indentation systems. Arguably though, indentation inaccuracies are a separate problem. set autoindent smartindent cindent should fix the indentation problem asked about here

LunarWatcher added a commit that referenced this issue Apr 6, 2021
@AchmadFathoni
Copy link
Author

Setting those indent option makes the newline indented. Thank for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants