emacs-evil / evil

The extensible vi layer for Emacs.
GNU General Public License v3.0
3.38k stars 281 forks source link

indentation using =<motion> ignores settings like indent-tabs-mode or c-basic-offset #1163

Closed wilhelmy closed 4 years ago

wilhelmy commented 5 years ago

Issue type

Environment

Emacs version: 26.2 Operating System: openSuSE Tumbleweed Evil version: 1.2.14 Evil installation type: spacemacs default Graphical/Terminal: X11 Tested in a make emacs session (see CONTRIBUTING.md): No

Reproduction steps

Expected behavior

Code is indented using tab-stops

Actual behavior

Code is indented with 2 spaces instead of tab-stops.

Further notes

From a quick look at the function definition, apparently == is special-cased to (indent-according-to-mode) which does the right thing, while = otherwise implements its own indentation logic.

nnicandro commented 5 years ago

= doesn't implement its own indentation logic. It calls indent-region if the selected region is larger than a line and indent-according-to-mode otherwise. The other code in the function either tabifies or untabifies the indented region depending on the value of evil-indent-convert-tabs. There does seem to be a few minor issues with that part of the code, but it mostly works.

When I create a cc-mode file, more specifically a C file, containing the code

typedef struct {
    char *name;
    void *fun;
    char const * doc;
    ptrdiff_t minarity;
    ptrdiff_t maxarity;
} ezmq_fun_t;

And run gg=G I get the expected results with indent-tabs-mode set to t, c-basic-offset set to 8, and evil-indent-convert-tabs set to t. It doesn't appear that evil-indent-convert-tabs matters for cc-mode since I also get tabs when it is set to nil.

TheBB commented 4 years ago

Like @dzop I'm unable to reproduce this. Please let us know if you can find some better repro steps.

hkjels commented 4 years ago

This is still an issue and does not only apply to motion, but also visual.

#import "AViewController.h"

@implementation AViewController {
    IosServiceProvider *serviceProvider_;
}

- (instancetype)initWithServiceProvider:(IosServiceProvider *)serviceProvider {
    if (self = [super init]) {
        serviceProvider_ = serviceProvider;
    }
}

@end

I have editorconfig set up, so when I indent by hitting tab, it will indent using 4 spaces as specified by editorconfig. If I on the other hand select a region and run evil-indent it will be indented with 2 spaces. I think it's hard-coded somewhere as all the relevant variables are set correctly AFAIK.