SlickEdit Community

SlickEdit Product Discussion => SlickEdit® => Topic started by: sbusch on January 19, 2007, 05:24:12 pm

Title: deleting white space between words
Post by: sbusch on January 19, 2007, 05:24:12 pm
I'd like to something seemingly very simple - if I had a line: "abc          = def", and my cursor was right after 'c', I'd like to remove all the white space until '=' (a non-whitespace). So, the end result would be "abc = def". I know this is easy to do (it's gotta be!), but I couldn't figure out how to it with a macro.

Thanks.

Steve
Title: Re: deleting white space between words
Post by: Graeme on January 20, 2007, 12:47:12 pm
I've posted some code here
http://community.slickedit.com/index.php?topic=929.msg3975#msg3975 (http://community.slickedit.com/index.php?topic=929.msg3975#msg3975)
that hopefully does what you want.  If not, you should be able to change it fairly easily.

Graeme
Title: Re: deleting white space between words
Post by: sbusch on January 20, 2007, 03:23:01 pm
Graeme,

The code below seems to work some of the time, but not all of the time. It's so trivial, but I just don't know enough about SE to know why it sometimes fails. I'm using 12.0.

execute('select-block'); // start the select block on a space/tab
find('[ \t]+','U');          // keep on searching for tab or space.
delete_selection();       // delete the tab|space
Title: Re: deleting white space between words
Post by: Kohei on January 20, 2007, 06:00:06 pm
Hi Steve,

This code may serve as a good starting point:

Code: [Select]
_command void remove_next_space() name_info(',')
{
   select_char(); // Set pivot point to current cursor location

   int status = search("[~ \t]", 'r'); // search for next non-blank.
   if (!status) {
      // next non-blank found.
      _GoToROffset(match_length('S0'));
      left();
      delete_selection();
   }
   deselect();
}

This code removes all blank characters (whitespace and tab) from the current cursor location to the next non-blank character location.  The only caveat of this code is that it keeps on searching on the next line(s) if non-blank characters is not found in the current line.  But that may or may not matter to your use case.

Hope this helps,
Kohei
Title: Re: deleting white space between words
Post by: sbusch on January 20, 2007, 08:10:30 pm
Kohei,

Works like a charm.

Thanks.

Steve