Skip to content

Indentation of anonymous functions as arguments #29

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

Closed
BobuSumisu opened this issue Nov 25, 2012 · 9 comments
Closed

Indentation of anonymous functions as arguments #29

BobuSumisu opened this issue Nov 25, 2012 · 9 comments

Comments

@BobuSumisu
Copy link

I am testing out the Slim framework and noticed an annoying indentation problem when supplying an anonymous function as an argument; I am using 2-spaces indentation I want my code to look like:

$app->get("/index", function() {
  $app->redirect("foo");
});

But it gets indented as.

$app->get("/index", function() {
    $app->redirect("foo");
  });

Is is possible to achieve indentation as in the first example?

@ejmr
Copy link
Collaborator

ejmr commented Nov 26, 2012

Yes, it is possible to get the first form of indentation. In fact that is what should be the default, which means that is a bug I need to fix. Thanks for bringing this to my attention. I am a little busy with other things but I will make it a point to address this issue this week (along with some other open issues).

@BobuSumisu
Copy link
Author

Fantastic. Thanks for the great job maintaining an up-to-date php-mode :)

@ejmr
Copy link
Collaborator

ejmr commented Nov 27, 2012

I am looking into a more 'proper' way of adding these settings to php-mode without messing up any of the existing indentation rules, but in the mean time you could use this hook:

(add-hook 'php-mode-hook
          (lambda ()
            (c-set-offset 'statement-block-intro '/)
            (c-set-offset 'block-close -100)))

I tried this against some of the files in the tests/ directory to see if it messed up their indentation and things were fine. But something about using a large negative number like that makes me think there is a better solution available, heh.

@BobuSumisu
Copy link
Author

Thanks for the hook, but it messed up the indentation of code blocks for me.

Now every code block after "{" are indented at level 0.

  // code at lvl1
  if(x == y) {
// code is now at lvl0 :(
}
  // code is back at lvl1

@ejmr
Copy link
Collaborator

ejmr commented Nov 27, 2012

Ah, yes, I knew something was going to go wrong with that cheap hack of a hook, lol. I'm looking into a proper solution though while I brush up on the indentation engine of cc-mode, which php-mode uses. I forget how that system works as soon as I'm done working with it every time...

@BobuSumisu
Copy link
Author

Nice, no hurry though, as long as we know you know the issue ;)

I really should pick up elisp and start hacking this stuff myself :P

@ejmr
Copy link
Collaborator

ejmr commented Nov 27, 2012

I'm not trying to toot my own horn, but something that helped me learn a lot about Elisp was to write a major mode from scratch, like https://github.com/ejmr/tup-mode

This is also a good introduction: http://ergoemacs.org/emacs/elisp.html

And of course in Emacs itself you have C-h i m Emacs Lisp Intro.

@BobuSumisu
Copy link
Author

Thanks! I think writing an own major mode is a good start. Guess I'll just have to jump into it.

@ejmr
Copy link
Collaborator

ejmr commented Nov 29, 2012

This is now fixed as of v1.8 by ea5392c.

@ejmr ejmr closed this as completed Nov 29, 2012
haxney added a commit to haxney/php-mode that referenced this issue Feb 8, 2013
ejmr pushed a commit that referenced this issue Feb 8, 2013
This massively cuts back on the elisp code needed.

Signed-off-by: Eric James Michael Ritz <[email protected]>
ejmr pushed a commit that referenced this issue Feb 8, 2013
* haxney/tests-with-magic-comments:
  Use magic for tests of issues #14, #19, #27, #29, #42
  Use "magic" comments in PHP files to simplify indentation testing
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