Author Topic: Selecting columns of data  (Read 1229 times)

jporkkahtc

  • Senior Community Member
  • Posts: 1425
  • Hero Points: 112
  • Text
Selecting columns of data
« on: May 12, 2016, 05:28:58 pm »
When I have a large file and I'm trying to use a block selection to pick out a column of data -- particularly from say column 42 to the end of the line, I have to guess how far right to extend the block.

For example - imagine if this was a long file:
line   one
line   two
really really long line somewhere in the middle
line   three
line   four
....
I put the cursor at line 1, column 7, then jump to the bottom of the file.
Now I have to move right - but I don't know how far right because I can't easily tell what the longest line is.


Is there are particularly clever way to do this?




When creating a block selection it might be nice if "end" would move the cursor to the right of the longest line in the block, not just the end of the line that the cursor is on.


Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4035
  • Hero Points: 269
Re: Selecting columns of data
« Reply #1 on: May 13, 2016, 02:11:27 am »
I've run into this myself. Not sure if the end key should do this though. Maybe if your already at the end of the line, then the end key should do this?

Graeme

  • Senior Community Member
  • Posts: 1992
  • Hero Points: 228
Re: Selecting columns of data
« Reply #2 on: May 13, 2016, 06:19:28 am »
Hey, look at that, I wrote a macro for it a year ago today.

https://community.slickedit.com/index.php/topic,11383.msg48081.html#msg48081

« Last Edit: May 13, 2016, 06:21:59 am by Graeme »

jporkkahtc

  • Senior Community Member
  • Posts: 1425
  • Hero Points: 112
  • Text
Re: Selecting columns of data
« Reply #3 on: May 13, 2016, 06:26:20 pm »
Cool ... though that just finds the max.


So, I was trying to make that function operate on a selection, but I got stuck right away.


My code:

Code: [Select]

_command void column_select() name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_READ_ONLY)
{
    say("T '" _select_type('', "T") "'");
    say("S '" _select_type('', "S") "'");
    say("P '" _select_type('', "P") "'");
    say("I '" _select_type('', "I") "'");
}




Now, use the Right mouse button to create a block selection (or shift-LMB+drag to create a regular selection), and run the macro.
The results I get:



T ''
S ''
P ''
I ''


If I use the keyboard to select, then run the macro, I get this:

T 'BLOCK'
S 'C'
P 'BB'
I '0'


[size=78%]So, how does one tell if there is an active selection?[/size]
What type?
What are the bounds? (Well, I just care about top/bottom line numbers).









Graeme

  • Senior Community Member
  • Posts: 1992
  • Hero Points: 228
Re: Selecting columns of data
« Reply #4 on: May 14, 2016, 12:05:42 pm »
Here's some code you can play with if you want.

xblock_resize_right() finds the max line and adjusts the selection.

xblock_resize_editor() finds the max line and adjusts the selection, then shows a non modal on-top dialog that lets you move around the selected block or expand/ contract it.  I don't like using global variables but don't have a quick solution.
[edit - fixed something]
« Last Edit: May 14, 2016, 12:26:16 pm by Graeme »

jporkkahtc

  • Senior Community Member
  • Posts: 1425
  • Hero Points: 112
  • Text
Re: Selecting columns of data
« Reply #5 on: May 14, 2016, 11:19:35 pm »
Thanks. That's a pretty neat little selection toy.

Still, I wonder about the odd behavior of _select_type.

I found in my code that if I add VSARG2_REQUIRES_BLOCK_SELECTION to the function, then _select_type() works correctly with a mouse selected block or a keyboard selected block.

I thought that this flag would just require a selection be active before allowing this function to be called, but it appears to also affect the behavior of functions like _select_type.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4035
  • Hero Points: 269
Re: Selecting columns of data
« Reply #6 on: May 14, 2016, 11:52:02 pm »
Those flags don't effect select_type but when your command gets called, the selection will be auto deselected without the correct arg2 flags.

jporkkahtc

  • Senior Community Member
  • Posts: 1425
  • Hero Points: 112
  • Text
Re: Selecting columns of data
« Reply #7 on: May 16, 2016, 05:05:24 pm »
Ah ... VSARG2_MARK
So, why doesn't it clear a selection started from the keyboard?
I can type Ctrl-B (select-block), move the cursor a bit to make a rect, run my function (with only VSARG2_REQUIRES_EDITORCTL|VSARG2_READ_ONLY), and the selection remains.
This only works for block selections - normal char selections are deselected.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4035
  • Hero Points: 269
Re: Selecting columns of data
« Reply #8 on: May 17, 2016, 05:06:04 pm »
have you able to find arg2 flags that work for you? I usually just use the same flags as some other command which works.

jporkkahtc

  • Senior Community Member
  • Posts: 1425
  • Hero Points: 112
  • Text
Re: Selecting columns of data
« Reply #9 on: May 17, 2016, 07:48:01 pm »
Yeah, I have it working fine, I was just curious about the odd behavior here.