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

Indentation of Multi-Line UFCS-Chains #26

Closed nordlow closed 9 years ago

nordlow commented 10 years ago

I would love to see the indentation mechanism in d-mode be tweaked to enable indentation of multi-line UFCS-chains in ways such as

        foreach (file; dirPath.expandTilde()
                              .buildNormalizedPath() 
                              .dirEntries(SpanMode.shallow)()
                              .filter!(name => name.extension == ".csv")) // I love D :)

Does any one know if this is possible without changing the internals of Emacs?

http://www.emacswiki.org/emacs/IndentingC might be of service for ideas. I cannot find the symbol align-mode-rules-list in my Emacs though. Misspelling?

russel commented 10 years ago

Everything is possible in Emacs, the question is whether anyone has the patience to write the E-Lisp to do it. Is this alignment something people in C++ are going to start to want? It may certainly become a demand for Java mode now (with Java 8) if it hasn't already. Currently Java just uses continuation indent here as D and C++ do. Mayhap just relent and use:

  foreach (file; dirPath
           .expandTilde()
           .buildNormalizedPath()
           .dirEntries(SpanMode.shallow)()
           .filter!(name => name.extension == ".csv")) { // I love D :)
  }
nordlow commented 10 years ago

I just got an answer and here

https://stackoverflow.com/questions/25797945/adjusting-alignment-rules-for-ucfs-chains-in-d/25843155#25843155

My first try didn't have any effect unfortunately. I'll try some more in Vanilla Emacs later on. Maybe you could try it out?

Correction: It works only with function calls with parens.

Update: The latest update works flawlessly in my Emacs!

russel commented 10 years ago

So I guess we add the function to the d-mode.el but leave people to use it via a d-mode-hook if they wish to?

I have prepared the ground by adding the code from the StackOverflow page in my clone of the repository. I can push the changes and the you can send in a pull request for the necessary changes to make things work?

nordlow commented 10 years ago

Sounds like a good plan.

Here's what I use:

https://github.com/nordlow/elisp/blob/master/mine/dotemacs.el#L1581

russel commented 10 years ago

I committed code and pushed to the mainline repository before reading the above. Apologies for that. Could I get you to do a diff of what you know works against what we now have in mainline and create a pull request?

snosov1 commented 10 years ago

You have a typo in the comment above the function - it adds c-lineup... instead of d-lineup... function to the list.

russel commented 10 years ago

Sergei, thanks for spotting that. I had just cut and paste from the StackOverflow page, so I'll blame StackOverflow rather than me not checking things properly :-) It will be corrected momentarily.

snosov1 commented 10 years ago

Great! Thanks!

Also, as a side note. I really think that this kind of stuff (i.e. available options and customization) should be put to the readme file and not to the source code alone. Because I doubt that a lot of people dig through the source looking for documentation.

So maybe it makes sense to move the appropriate comments from the heading of the d-mode.el file and info about this hack (and possibly other useful info) to readme to give it more publicity.

russel commented 10 years ago

Not so much a side note, more "I should have done that in the first place!" :-) I'll transfer more material onto the README.md file and/or take pull requests.

russel commented 9 years ago

I believe this issue was addressed in changesets f487a71dcea6c378f8c5004d13dfbb0116d87edb , 86930c37b94c3824adbac04923b4413f171ba496 and f4176c0338d78460701af9df3b286a5350bd5a4f so I am closing this issue. Please re-open if there is still and issue to be addressed.