Emacs-D-Mode-Maintainers / Emacs-D-Mode

An Emacs mode for D code.
GNU General Public License v3.0
84 stars 21 forks source link

Contracts are more indented than body #58

Closed mathias-lang-sociomantic closed 3 years ago

mathias-lang-sociomantic commented 8 years ago

The following is the indentation I get for contracts:

double foo (double b)
    in
    {
        assert(b == b);
    }
out (result)
    {
        assert(result == result);
    }
body
{
    return b;
}
double foo (double b)
    out (result)
        {
            assert(result == result);
        }
body
{
    return b;
}
double foo (double b)
    in
    {
        assert(b == b);
    }
body
{
    return b;
}

My settings are:

(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(defvaralias 'c-basic-offset 'tab-width)
(setq c-default-style "bsd" c-basic-offset 4)

But it happens when commenting those lines out too.

nordlow commented 3 years ago

Incorrect indentation still happens for me. Can you point to a place in d-mode.el that controls this behaviour?

CyberShadow commented 3 years ago

Incorrect indentation still happens for me.

Please don't forget to configure the offset according to your preference. (C-c C-o)

Can you point to a place in d-mode.el that controls this behaviour?

Please see d-in-knr-argdecl.

nordlow commented 3 years ago

Please see d-in-knr-argdecl.

Thanks! Would it be possible to have

(c-set-offset 'knr-argdecl-intro 0)

be called automatically upon entering of d-mode, provided d-mode.el has been loaded?

I now currently have

(c-add-style "D"
             '("stroustrup"
               (c-offsets-alist
                (innamespace . -)
                (inline-open . 0)
                (inher-cont . c-lineup-multi-inher)
                (template-args-cont . +)
                (substatement-open . 0)
                (statement-block-intro . +)
                (arglist-cont-nonempty (d-lineup-cascaded-calls
                                        c-lineup-gcc-asm-reg
                                        c-lineup-arglist))
                (statement-cont . d-lineup-cascaded-calls)
                (case-label . 0)        ;no indentation
                (knr-argdecl-intro . 0) ;no indentation for template restrictions and in contracts
                )))

which I believe matches the recommend D formatting rules.

What about adding this to d-mode.el?

CyberShadow commented 3 years ago

I think the proper way is something like:

(c-add-style
 "My D style"
 '((c-offsets-alist . ((knr-argdecl-intro . 0)
                       ;; ...
               ))))

(defun my/d-mode-hook ()
  (c-set-style "My D style"))
(add-hook 'd-mode-hook 'my/d-mode-hook)
CyberShadow commented 3 years ago

What about adding this to d-mode.el?

Sounds good. It should mention that it attempts to implement https://dlang.org/dstyle.html as closely as possible.

nordlow commented 3 years ago

What about adding this to d-mode.el?

Sounds good. It should mention that it attempts to implement https://dlang.org/dstyle.html as closely as possible.

Do you want to add it or shall I?

CyberShadow commented 3 years ago

Yes, please submit a pull request.

If you could include a test that covers all of the offset settings, that would be great.

nordlow commented 3 years ago

I believe the setting should be activated by default.

CyberShadow commented 3 years ago

Not by default I think (unless that's common practice for cc-mode-based major modes? but even then I'm not sure about changing the current default), but we can document how to enable it in the README.