ethereum / emacs-solidity

The official solidity-mode for EMACS
GNU General Public License v3.0
205 stars 66 forks source link

Indentation After Structs #51

Closed rheaplex closed 4 years ago

rheaplex commented 4 years ago

Thank you for solidity-mode!

When using it to automatically indent code, the indentation of lines after the closing curly brace of a struct is increased by one level until after closing another declaration:

image

c-mode seems to be expecting a semicolon after the closing curly brace of the struct, but Solidity doesn't require one (and complains if one is provided, although doing so fixed the indentation).

I'm not quite sure how to address this, modifying c-offsets-alist for class-close (the syntactic type returned by C-c C-s) affects the indentation of the curly brace, not the lines that follow it.

I addressed similar issues with my desired indentation for events and other constructs with closing parentheses on a new line using:

            (add-to-list 'c-offsets-alist
                         '(arglist-close . c-lineup-close-paren))
LefterisJP commented 4 years ago

Hey @robmyers thank you for the bug report and apologies for the late response!

So I tried to reproduce what you are saying with the following program:

contract foo {

    struct boo {
        uint256 a;
    }

    function funA() {
        return;
    }  
}

But the indentation does not appear like in your screenshot. How did you automatically ident? By pressing TAB?

My c/c++ code setup which also applies in solidity is here: https://github.com/LefterisJP/.emacs/blob/90d542d8ee0ddc68a58fd1e2318b694a3dd7d5f5/lk/cstyle-setup.el#L18-L79

rheaplex commented 4 years ago

Thank you for looking at this.

The embarrassing outcome of a long process of discovery is that this is an issue with emacs 27 in git. I reverted to emacs 26 and everything is fine.

My apologies for not catching that before asking.

coventry commented 3 years ago

@rheaplex , I am running into this issue with bleeding-edge emacs 28. Do you recall what the causative issue was in emacs27?

vhqr0 commented 1 year ago

It can still be reproduced on Emacs29. Adding a semicolon after struct and enum can correct indentation, but it cannot be compiled.

harrigan commented 7 months ago

Check out https://github.com/ethereum/emacs-solidity/issues/72#issuecomment-1046246624.