Home Download Buy Blog Forum Support

Multi-Selection Alignment

Re: Multi-Selection Alignment

Postby FalconNL on Wed Aug 31, 2011 9:15 pm

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.
FalconNL
 
Posts: 67
Joined: Thu May 29, 2008 8:17 pm

Re: Multi-Selection Alignment

Postby standard_error on Thu Sep 01, 2011 12:30 pm

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:

Code: Select all
1 & 2 & 3
4       & 5   & 6
7  & 8      & 9


What I get is this:
Code: Select all
1   & 2 & 3
4   & 5   & 6
7   & 8      & 9


but what I want is something like this:
Code: Select all
1   & 2   & 3
4   & 5   & 6
7   & 8   & 9


This is how my user settings look:
Code: Select all
   "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?
standard_error
 
Posts: 2
Joined: Thu Sep 01, 2011 12:23 pm

Re: Multi-Selection Alignment

Postby wbond on Thu Sep 01, 2011 4:29 pm

FalconNL wrote: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.


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.
wbond
 
Posts: 493
Joined: Mon Feb 28, 2011 5:33 am

Re: Multi-Selection Alignment

Postby wbond on Thu Sep 01, 2011 4:32 pm

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


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.
wbond
 
Posts: 493
Joined: Mon Feb 28, 2011 5:33 am

Re: Multi-Selection Alignment

Postby wbond on Thu Sep 01, 2011 4:42 pm

oxman wrote:Very nice work.

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


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.
wbond
 
Posts: 493
Joined: Mon Feb 28, 2011 5:33 am

Re: Multi-Selection Alignment

Postby wbond on Thu Sep 01, 2011 4:44 pm

FalconNL wrote: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.


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.
wbond
 
Posts: 493
Joined: Mon Feb 28, 2011 5:33 am

Re: Multi-Selection Alignment

Postby standard_error on Fri Sep 02, 2011 7:39 am

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:

Code: Select all
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?

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


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.
standard_error
 
Posts: 2
Joined: Thu Sep 01, 2011 12:23 pm

Re: Multi-Selection Alignment

Postby wbond on Thu Sep 08, 2011 3:36 am

standard_error wrote: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:

Code: Select all
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?


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.
wbond
 
Posts: 493
Joined: Mon Feb 28, 2011 5:33 am

Re: Multi-Selection Alignment

Postby wbond on Mon Sep 19, 2011 3:21 am

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.
wbond
 
Posts: 493
Joined: Mon Feb 28, 2011 5:33 am

Re: Multi-Selection Alignment

Postby judecrot on Sat Aug 11, 2012 3:09 pm

I had the same issue with LaTeX tables and I fixed it by patching the Alignment.py script.

I also wrote a issue in the GitHub repository but I got no reply yet.

This is my patch: replace the code at the end of the script with the following
Code: Select all
        # This handles aligning multiple selections
        else:
            col = {}
            curline = view.rowcol(sel[0].begin())[0]
            j=0
            for i in range(0,len(sel)):
                ln = view.rowcol(sel[i].begin())[0]
                if ln != curline:
                    j=0
                    curline = ln
                if j in col.keys():
                    col[j].append(i)
                else:
                    col[j] = [i]
                j+=1
            for j in col.keys():
                max_col = max([normed_rowcol(view, sel[i].b)[1] for i in col[j]])
                for i in col[j]:
                    region = sel[i]
                    length = max_col - normed_rowcol(view, region.b)[1]
                    view.insert(edit, region.b, ' ' * length)
                    if settings.get('mid_line_tabs') and not use_spaces:
                        convert_to_mid_line_tabs(view, edit, tab_size, region.b, length)


With this in place you can align the table as follows:
  • Select the table code
  • Find all the '&' in the selection (with findall you get all of them selected at once)
  • Press Ctrl+Alt+a (or whatever the shortcut for Alignment is in your setup) et voilà!

I hope it helps!
judecrot
 
Posts: 8
Joined: Sat Jun 30, 2012 10:28 pm

PreviousNext

Return to Plugin Announcements

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests

cron