Author Topic: Add code alignment options in v22?  (Read 997 times)

jwiede

  • Community Member
  • Posts: 94
  • Hero Points: 11
Add code alignment options in v22?
« on: September 22, 2017, 07:05:30 pm »
Any chance we can get functionality similar to what the "Code Alignment" plugin offers in v22?

davehohl

  • Senior Community Member
  • Posts: 268
  • Hero Points: 22
Re: Add code alignment options in v22?
« Reply #1 on: September 22, 2017, 07:32:26 pm »
Never knew about that plug-in before. Looks like a very handy tool. It would be great for SE to support this kind of functionality.

Graeme

  • Senior Community Member
  • Posts: 2061
  • Hero Points: 248
Re: Add code alignment options in v22?
« Reply #2 on: September 22, 2017, 11:48:25 pm »
Can you give an example of what this does and what it's useful for?


LBCEi

  • Senior Community Member
  • Posts: 162
  • Hero Points: 11
Re: Add code alignment options in v22?
« Reply #3 on: September 23, 2017, 03:59:10 am »
Try this user contributed set of macros for a partial implementation of code alignment and a couple of other features that I use all the time in SE:

https://community.slickedit.com/index.php/topic,5899.msg24394.html#msg24394

It probably wouldn't be too hard to modify the aligneq macro to align on other tokens besides '=', if you so desire.

davehohl

  • Senior Community Member
  • Posts: 268
  • Hero Points: 22
Re: Add code alignment options in v22?
« Reply #4 on: September 25, 2017, 04:45:07 pm »
Can you give an example of what this does and what it's useful for?

See attached screenshot from Code Alignment web site:


jporkkahtc

  • Senior Community Member
  • Posts: 1491
  • Hero Points: 123
  • Text
Re: Add code alignment options in v22?
« Reply #5 on: September 25, 2017, 07:33:53 pm »
This is the same thing as Elastic-Tabstops, right?
Seems to be gaining a bit of traction.
It would be nice if you can get it right and avoid conflicting with things like beautify while typing.

https://community.slickedit.com/index.php/topic,14239.msg58881.html#msg58881
https://community.slickedit.com/index.php/topic,14650.msg52909.html#msg52909
http://nickgravgaard.com/elastic-tabstops/


davehohl

  • Senior Community Member
  • Posts: 268
  • Hero Points: 22
Re: Add code alignment options in v22?
« Reply #6 on: September 25, 2017, 08:36:48 pm »
This is the same thing as Elastic-Tabstops, right?
Seems to be gaining a bit of traction.
It would be nice if you can get it right and avoid conflicting with things like beautify while typing.

https://community.slickedit.com/index.php/topic,14239.msg58881.html#msg58881
https://community.slickedit.com/index.php/topic,14650.msg52909.html#msg52909
http://nickgravgaard.com/elastic-tabstops/

Thanks for the links! Looks like the elastic tabstops is a more sophisticated approach to the issue, but is certainly addressing the same basic problem. Elastic tabstops would be awesome, but I would be happy with just the ability to select some text and have things get aligned by adding spaces. (I need to check out that macro that LBCEi mentioned.)

davehohl

  • Senior Community Member
  • Posts: 268
  • Hero Points: 22
Re: Add code alignment options in v22?
« Reply #7 on: September 27, 2017, 04:12:44 pm »
Try this user contributed set of macros for a partial implementation of code alignment and a couple of other features that I use all the time in SE:

https://community.slickedit.com/index.php/topic,5899.msg24394.html#msg24394

It probably wouldn't be too hard to modify the aligneq macro to align on other tokens besides '=', if you so desire.

OK, I took up LBCEi's challenge and modified the original to add a new command -- align-custom -- which prompts the user for a string to align on. I have attached the macro file in case others are interested. Not as powerful as the elastic tabstops feature would be, but still pretty useful.

This is my first attempt at working with Slick-C, so the macro comes with no guarantees!

jwiede

  • Community Member
  • Posts: 94
  • Hero Points: 11
Re: Add code alignment options in v22?
« Reply #8 on: October 23, 2017, 11:16:09 pm »
The nice thing about Elastic Tabstop-like solutions is they manage multiple columns worth of aligned text, which for cases like variable declarations, defines, and so forth, can make for much greater readability overall than simply aligning a bunch of lines vertically on a string.

So for example, its the difference between this...
Quote
(aligned on '=')

        Messages::Content *msgContent = Message->mutable_content();
Messages::Destination msgDestination = Message->destination();
                   Messages::Type msgType = Message->type();
and something more like this...
Quote
(elastic tabstops)

Messages::Content     *msgContent      = Message->mutable_content();
Messages::Destination  msgDestination = Message->destination();
Messages::Type           msgType           = Message->type();

Given a choice, I'd much prefer the ability to generate something more like the latter.  The former seems useful at first, but you rapidly discover that you really want alignment on more than one char/string per line.

davehohl

  • Senior Community Member
  • Posts: 268
  • Hero Points: 22
Re: Add code alignment options in v22?
« Reply #9 on: October 23, 2017, 11:25:10 pm »
The nice thing about Elastic Tabstop-like solutions is they manage multiple columns worth of aligned text, which for cases like variable declarations, defines, and so forth, can make for much greater readability overall than simply aligning a bunch of lines vertically on a string.

So for example, its the difference between this...
Quote
(aligned on '=')

        Messages::Content *msgContent = Message->mutable_content();
Messages::Destination msgDestination = Message->destination();
                   Messages::Type msgType = Message->type();
and something more like this...
Quote
(elastic tabstops)

Messages::Content     *msgContent      = Message->mutable_content();
Messages::Destination  msgDestination = Message->destination();
Messages::Type           msgType           = Message->type();

Given a choice, I'd much prefer the ability to generate something more like the latter.  The former seems useful at first, but you rapidly discover that you really want alignment on more than one char/string per line.

Agreed.

However, note that it is possible to use the align-custom macro on block selections. This means you could align your example first on "msg", then on "=" and finally on "Message" to achieve what you want (or at least close to it), selecting only the columns having the text to align on. A bit of a pain to have to do multiple operations, but I have been using this technique lately and it works pretty well.

jwiede

  • Community Member
  • Posts: 94
  • Hero Points: 11
Re: Add code alignment options in v22?
« Reply #10 on: October 24, 2017, 09:31:54 pm »
The work-around helps, sure.  However, this is a forum (and thread) explicitly about asking for SE enhancement requests, and so that's what we're trying to provide:  An SE feature request for the desired functionality in question.