Sublime Forum

Multi-Selection Alignment

#18

@wbond: thanks for this awesome plugin, my code never looked that good!
There is a way of changing space indent to tab?

Thanks!

0 Likes

#19

@iamntz

The left indent should automatically use tabs or spaces based on the current settings. In terms of mid-line indenting, unfortunately I was not able to figure out last night how to measure the actual displayed width of a tab character via the API. I can get the row and column, but the column is just the number of characters from the beginning of the line. I know ST2 can get the real column number since it is displayed in the status bar, I just couldn’t find a method to translate to that. Without being able to tell how wide each tab is being displayed, I wouldn’t be able to do mid-line tab spacing.

0 Likes

#20

To get the ‘visual’ column of a point, you could replace

view.rowcol(pt)

by

import indentation indentation.line_and_normed_pt(view, pt)
Row is always the same for both.

An addition to the API for it would be nice.

Thanks for your work wbond.

0 Likes

#21

Thanks guys! I’ll work on trying to get mid-line tab alignment done tonight.

0 Likes

#22

I’ve updated to the latest and it doesn’t seem to work at all for me (JavaScript):

var tabBar = me.getTabBar(), initialConfig = card.getInitialConfig(), tabConfig = initialConfig.tab || {}, tabTitle = initialConfig.title, tabIconCls = initialConfig.iconCls, index = card.getIndex(), tabs = tabBar.getItems(), cards = me.getInnerItems(), currentTabInstance = (tabs.length >= cards.length) && tabs.getAt(index), tabInstance;

0 Likes

#23

@rdougan

I just copied and pasted that code into my editor and it all seemed to align properly. Are there any errors in the console? Is anything happening at all? What platform are you running ST2 on, and what build of ST2 are you using?

0 Likes

#24

@wbond

For some reason it is now working. It may have been an issue with another plugin I had. There were no errors in the console.

Thanks for adding the align_indent setting! :smile:

0 Likes

#25

[quote=“iamntz”]@wbond: thanks for this awesome plugin, my code never looked that good!
There is a way of changing space indent to tab? [/quote]

I just released version 1.1.0 which includes the setting mid_line_tabs. When enabled, mid-line indentation will be done via tabs if indentation is set to tabs. This could have some side effects when working with editors that have a different tab width, and changes the way in which multi-character operators are indented.

The original post has been updated with the full changelog.

0 Likes

#26

Thanks!
Works amazing!

0 Likes

#27

Thank You Will! Greate job, works good for me too.

New version (1.1.1) of Allignment. Will fixed a bug ‘Fixed a math error when converting mid-line spaces to tabs’

0 Likes

#28

Very nice work.

Could you make it works in realtime like elastic tabstop ?
You can see a live demonstration here : nickgravgaard.com/elastictabstops/

0 Likes

#29

Love the plugin. There’s one little issue I ran across today though: after updating to build 2111 I read the changelog and noticed the new Expand to tag shortcut, which is bound to ctrl+shift+a by default. I tried it out and obviously nothing happened, since it’s overridden by the Alignment plugin. This is of course simple enough to fix, but I would still suggest making ctrl+alt+a the only default keybinding for selection alignment to prevent confusion in new users.

0 Likes

#30

What an excellent plugin!

One question: I’m trying to use this to make latex tables neat and readable in the source code (by changing the alignment symbol to &), but it seems that only the first instance of the & symbol is actually aligned. To demonstrate, say I have this:

1 & 2 & 3
4 		& 5   & 6
7  & 8		& 9

What I get is this:

1	& 2 & 3
4	& 5   & 6
7	& 8		& 9

but what I want is something like this:

1	& 2	& 3
4	& 5	& 6
7	& 8	& 9

This is how my user settings look:

	"font_size": 10,
	"mid_line_tabs": true,
	"alignment_chars": "&"],
	"alignment_space_chars": "&"],
	"alignment_prefix_chars": 	]

Is there any way to make the plugin do what I want, or is it just out of the scope of the project?

0 Likes

#31

Yes, I plan on doing that, I just need to add functionality to Package Control to make it possible to alert users during an upgrade so I can let users know that the key binding has changed. I hope to do this over the next few days.

0 Likes

#32

For advanced alignment issues the solution is to use multiple selections. For your situation you would:

  • Select all lines

  • Hit ctrl+shift+l/cmd+shift+l to split into lines

  • Use end/cmd+right to go to the end of the line

  • Use ctrl+left to move your cursors to right before the & characters

  • Hit ctrl+shift+a/cmd+shift+a to align the selection points

It probably sounds more complicated than it is.

0 Likes

#33

[quote=“oxman”]Very nice work.

Could you make it works in realtime like elastic tabstop ?
You can see a live demonstration here : nickgravgaard.com/elastictabstops/[/quote]

This plugin probably wouldn’t work in real time, it would probably have to be written from scratch to get elastic tabstop functionality. Unfortunately I don’t have the time to work on that right now.

0 Likes

#34

Sorry, as a temporary fix you can edit the Default (Your OS).sublime-keymap file in the Packages/Alignment folder and remove the binding for ctrl+shift+a.

0 Likes

#35

Thanks for the quick reply! that works great for the example I posted, but trying it out I realized it does not work for some more complicated cases, such as the one pasted below:

Q 1	&29.52&	7.57&	4.86&	4.61&	2.59&	31.23&	19.61\\
Q 2	&8.28	&21.40&	9.44&	5.76&	5.76&	27.65&	21.71\\
Q 3	&4.42	&6.59	&23.11&	9.05&	6.48&	27.83&	22.52\\
Q 4	&2.83	&3.89	&7.54	&32.31&	7.88&	24.74&	20.81\\
Q 5	&1.58	&2.51	&4.19	&4.17	&36.36&	25.55&	25.65\\
Age 3-17	&26.72&	20.59&	19.89&	18.52&	14.28&	0	&0\\
Not empl.	&32.88	&20.67	&14.22	&14.55	&17.68	&0	&0\\

Is there anyway to make that work?

[quote=“wbond”]

For advanced alignment issues the solution is to use multiple selections. For your situation you would:

  • Select all lines

  • Hit ctrl+shift+l/cmd+shift+l to split into lines

  • Use end/cmd+right to go to the end of the line

  • Use ctrl+left to move your cursors to right before the & characters

  • Hit ctrl+shift+a/cmd+shift+a to align the selection points

It probably sounds more complicated than it is.[/quote]

0 Likes

#36

[quote=“standard_error”]Thanks for the quick reply! that works great for the example I posted, but trying it out I realized it does not work for some more complicated cases, such as the one pasted below:

Q 1	&29.52&	7.57&	4.86&	4.61&	2.59&	31.23&	19.61\\
Q 2	&8.28	&21.40&	9.44&	5.76&	5.76&	27.65&	21.71\\
Q 3	&4.42	&6.59	&23.11&	9.05&	6.48&	27.83&	22.52\\
Q 4	&2.83	&3.89	&7.54	&32.31&	7.88&	24.74&	20.81\\
Q 5	&1.58	&2.51	&4.19	&4.17	&36.36&	25.55&	25.65\\
Age 3-17	&26.72&	20.59&	19.89&	18.52&	14.28&	0	&0\\
Not empl.	&32.88	&20.67	&14.22	&14.55	&17.68	&0	&0\\

Is there anyway to make that work?[/quote]

It seems to me I should probably add two commands to Alignment, jump to next whitespace and jump to previous whitespace. If those commands were added then it should be pretty easy to align the content you have there. I try to find time to do this in the next few days.

0 Likes

#37

I just released version 2.0.0, which removes the original key bindings of ctrl+shift+a for Windows/Linux and cmd+shift+a on OS X. These key binding ended up conflicting with Expand to Tag when it was released. The new key bindings, which have been around for a while, are ctrl+alt+a for Windows/Linux and ctrl+cmd+a for OS X.

0 Likes