colonelpanic8 / multi-line

multi-line everything from function invocations and definitions to array and map literals in a wide variety of languages
57 stars 6 forks source link

Add Leading Commas Support (C++, Haskell) #6

Open articuluxe opened 8 years ago

articuluxe commented 8 years ago

My compliments on a slick package. It looks very powerful, although it is not very clear how to configure it.

On to my question. Is it possible to configure multi-line for a c++ signature such that the parameters take one per line, but the commas lead the parameters, not trail them?

void func(
    int a
    , char b
    , double c
    , bool b = false
    );
colonelpanic8 commented 8 years ago

My compliments on a slick package. It looks very powerful, although it is not very clear how to configure it.

Yeah, configuration is pretty complicated because of how multi-line aims to support so many different languages, indentation styles.

On to my question. Is it possible to configure multi-line for a c++ signature such that the parameters take one per line, but the commas lead the parameters, not trail them?

Wow, I've never heard of that multi-lining style before. Yes, that should be possible but it will require writing a tiny bit of elisp. Let me see if I can cook something up.

colonelpanic8 commented 8 years ago

Hah, okay, this is a mouthful, but it was actually pretty easy. Single lining doesn't really work, but I'm pretty sure that I could get it there, but I think that I would need to tweak the way respacing works.

(defvar multi-line-leading-commas-strategy
  (make-instance 'multi-line-strategy
                 :find
                 (make-instance 'multi-line-forward-sexp-find-strategy
                                :split-advance-fn (lambda ()))
                 :respace
                 (multi-line-default-respacers
                  (multi-line-clearing-reindenting-respacer
                   (make-instance 'multi-line-always-newline)))))

EDIT: oh and to make it active in C++ buffers you would add:

(multi-line-defhook c++ multi-line-leading-commas-strategy)

If you want this strategy everywhere:

(setq-default multi-line-leading-commas-strategy)
colonelpanic8 commented 8 years ago

@danrharms can let me know when you get a chance to test this out so I can close this issue

articuluxe commented 8 years ago

Sure will do, sorry I'm away from my computer today.

On Sep 8, 2016, at 1:48 PM, Ivan Malison notifications@github.com wrote:

@danrharms can let me know when you get a chance to test this out so I can close this issue

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.