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

Indent about Chained Method Calls #43

Closed
guweigang opened this issue Dec 17, 2012 · 16 comments
Closed

Indent about Chained Method Calls #43

guweigang opened this issue Dec 17, 2012 · 16 comments

Comments

@guweigang
Copy link
Contributor

hey, there is another indentation problem.

it should be indented align with "->", but actually, it will not, just 4 chars indentation. codes:

        $di->getShared('dispatcher')                          
            ->setDefaultNamespace("Tycoon\Web\Controllers\\");

        $test->count()                                        
            ->test();                                         

@ejmr
Copy link
Collaborator

ejmr commented Dec 17, 2012

Sorry but I cannot duplicate this. If I take your example and run indent-region on it then the code lines up with the -> operator as expected. However, this may be because we are using different versions of Emacs and/or php-mode. Please let me know what version of Emacs you have (i.e. from C-h C-a) and values of php-mode-version-number and php-mode-modified so I can try to replicate it. Thanks.

@guweigang
Copy link
Contributor Author

@ejmr i use TAB or C-j to indent next line. i will check emacs version and php-mode version later.

thank you for the patience.

@guweigang
Copy link
Contributor Author

php-mode-version: PHP mode 1.5.0-nxhtml-1.94 of 2009-08-12
GNU Emacs 24.2.1 (x86_64-unknown-linux-gnu)

i can not excute `php-mode-modified' command, but i opened php-mode.el and get things like below:

;; Maintainer: Eric James Michael Ritz <lobbyjones at gmail dot com>
;; Original Author: Turadg Aleahmad, 1999-2004
;; Keywords: php languages oop
;; Created: 1999-05-17
;; X-URL:   https://github.com/ejmr/php-mode

(defconst php-mode-version-number "1.9"
  "PHP Mode version number.")

(defconst php-mode-modified "2012-12-11"
  "PHP Mode build date.")

are these all right?

@ejmr
Copy link
Collaborator

ejmr commented Dec 18, 2012

Thank you, that is very helpful :)

Also, php-mode-modified is a variable and not a command, so in the future you can use the command C-h v to see its value; and for php-mode-version-number too.

@guweigang
Copy link
Contributor Author

hi, @ejmr have you duplicated this?

@ejmr
Copy link
Collaborator

ejmr commented Dec 20, 2012

Sorry @cnwggu but not yet, unfortunately. I will continue to work on tracking down the problem though.

@ejmr
Copy link
Collaborator

ejmr commented Dec 21, 2012

I can replicate this problem now, so that is one step towards fixing it. :)

@guweigang
Copy link
Contributor Author

@ejmr you are so nice

@ejmr
Copy link
Collaborator

ejmr commented Dec 21, 2012

@cnwggu Thanks :)

So here is the problem. There are lots of calls to c-set-offset in php-mode to setup the indentation and alignment rules. By default php-mode sets three offsets to c-lineup-cascaded-calls; this is what aligns the -> operator. However, commit 89eefdf by @zapad changes the offset for statement-cont to the value +. I cannot simply revert that commit because it fixes an indentation bug and we need his fix in php-mode.

i am thinking a solution may be to write a 'custom line-up function' (section 11.4 of the CC Mode manual) which looks at the previous line and decides whether or not to use the + offset or c-linup-cascaded-calls. My first idea was to simply check to see if there is a brace at the end of the previous line, but that does not work. So instead the function will have to determine if the previous line is something that may be potentially followed a single line, such as

foreach ($x as $y)
    echo $y;

But if anyone knows a more simple solution, or sees a problem with my approach, I would greatly appreciate the feedback.

@guweigang
Copy link
Contributor Author

@ejmr seems there is no better solutions for this, huh?

@ejmr
Copy link
Collaborator

ejmr commented Dec 22, 2012

seems there is no better solutions for this, huh?

There probably is a better solution since I am no expert with Elisp, but the approach I described above is what I am going to work on implementing. I will try to patch php-mode to fix this problem in the next few days.

@guweigang
Copy link
Contributor Author

i never write elisp before.

so it's kind of difficult for me

@ejmr
Copy link
Collaborator

ejmr commented Dec 24, 2012

That's ok @cnwggu because I was not trying to ask you to write the patch. I was only explaining the approach I intend to take and give insight for any others who may have a better idea than mine. I will try to write the Elisp to fix this problem in the next week, but with it being Christmas in the United States I may not have the time.

@guweigang
Copy link
Contributor Author

@ejmr heh, Merry Christmas eve and Christmas day.

@ejmr
Copy link
Collaborator

ejmr commented Dec 24, 2012

Thank you @cnwggu :)

And the same to you as well, and to everyone else who helps me work on php-mode. Thank you everyone.

@ejmr
Copy link
Collaborator

ejmr commented Jan 15, 2013

I applied a patch to my local copy of master which addresses this problem, which I will be pushing out soon after merging in a few other updates. So for now I am going to close this issue.

@ejmr ejmr closed this as completed Jan 15, 2013
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