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

if (constraint) misindents the following block (which is the function/struct/etc. body) #127

Open
jibal opened this issue Dec 25, 2024 · 6 comments

Comments

@jibal
Copy link

jibal commented Dec 25, 2024

A type constraint on a generic function, struct, etc. apparently looks to emacs like an if statement within the "knr area" (the region between the function signature and the opening brace, which in K&R C consisted of parameter declarations) and so it thinks the function body is a block belonging to the if statement, and indents it as such.

Workaround: (c-set-offset 'knr-argdecl-intro 0) and putting the constraint on a separate line and the opening brace of the function on the same line minimizes the damage, but the function's closing brace is indented by 1 space. e.g.,

void  foo()
if (constraint) {
    ...
 } // indented 1 space

With the opening brace on a separate line, the whole function is indented 1 space:

void foo()
if (contraint)
 {
     ...
 }

(Apparently none of the phobos maintainers use emacs, because the library is chock full of constraints and this bug has apparently always be present in d-mode.el)

@CyberShadow
Copy link
Member

but the function's closing brace is indented by 1 space. e.g.,

Strange, I don't get that side effect if I apply the suggested workaround.

@CyberShadow
Copy link
Member

This Emacs-D-Mode test passes for me on Emacs 29.1:

// #run: (progn (c-set-offset 'substatement-open 0) (c-set-offset 'knr-argdecl-intro 0) (d-test-indent))

void foo()()
{
  bar();
}

void foo()()
if (true)
{
  bar();
}

void foo()()
if (true) {
  bar();
}

(Save as tests/I0127.d and run make test to reproduce.)

@jibal
Copy link
Author

jibal commented Dec 25, 2024

I've never be able not to, but maybe I have some other offsets that are causing it. I'll look into it further when I get a chance.

@jibal
Copy link
Author

jibal commented Dec 25, 2024

still indents for me under emacs -q so the mystery remains

image

@CyberShadow
Copy link
Member

Is that with (c-set-offset 'substatement-open 0)?

Maybe it could be one of the other offset settings that Emacs-D-Mode sets for indentation tests?

(c-offsets-alist
. ((string . c-lineup-dont-change)
(c . c-lineup-C-comments)
(defun-open . 0)
(defun-close . 0)
(defun-block-intro . +)
(class-open . 0)
(class-close . 0)
(inline-open . 0)
(inline-close . 0)
(func-decl-cont . +)
(topmost-intro . 0)
(topmost-intro-cont . 1)
(member-init-intro . +)
(member-init-cont . c-lineup-multi-inher)
(inher-intro . +)
(inher-cont . c-lineup-multi-inher)
(block-open . 0)
(block-close . 0)
(brace-list-open . 0)
(brace-list-close . 0)
(brace-list-intro . +)
(brace-list-entry . 0)
(statement . 0)
(statement-cont . +)
(statement-block-intro . +)
(statement-case-intro . +)
(statement-case-open . 0)
(substatement . +)
(substatement-open . +)
(substatement-label . *)
(case-label . 0)
(access-label . -)
(label . *)
(do-while-closure . 0)
(else-clause . 0)
(catch-clause . 0)
(comment-intro . c-lineup-comment)
(arglist-intro . +)
(arglist-cont . (c-lineup-gcc-asm-reg 0))
(arglist-cont-nonempty . (c-lineup-gcc-asm-reg c-lineup-arglist))
(arglist-close . +)
(stream-op . c-lineup-streamop)
(inclass . +)
(extern-lang-open . 0)
(extern-lang-close . 0)
(inextern-lang . +)
(namespace-open . 0)
(namespace-close . 0)
(innamespace . +)
(module-open . 0)
(module-close . 0)
(inmodule . 0)
(composition-open . 0)
(composition-close . 0)
(incomposition . 0)
(template-args-cont . (c-lineup-template-args +))
(inlambda . c-lineup-inexpr-block)
(lambda-intro-cont . +)
(inexpr-statement . +)
(inexpr-class . +)
(knr-argdecl-intro . 0)))

@jibal
Copy link
Author

jibal commented Dec 25, 2024

Is that with (c-set-offset 'substatement-open 0)?

Yes.

And FWIW,

GNU Emacs 29.4 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0) of 2024-06-23
running on Ubuntu Jammy Jellyfish on Windows 11 WSL2.

Out of time for now, gotta go.

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

No branches or pull requests

2 participants