Author Topic: deleting white space between words  (Read 6636 times)

sbusch

  • Community Member
  • Posts: 27
  • Hero Points: 0
deleting white space between words
« 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
« Last Edit: January 20, 2007, 04:01:51 PM by sbusch »

Graeme

  • Senior Community Member
  • Posts: 2793
  • Hero Points: 347
Re: deleting white space between words
« Reply #1 on: January 20, 2007, 12:47:12 PM »
I've posted some code here
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

sbusch

  • Community Member
  • Posts: 27
  • Hero Points: 0
Re: deleting white space between words
« Reply #2 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
« Last Edit: January 20, 2007, 04:02:52 PM by sbusch »

Kohei

  • Senior Community Member
  • Posts: 192
  • Hero Points: 25
Re: deleting white space between words
« Reply #3 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
« Last Edit: January 20, 2007, 06:03:03 PM by Kohei »

sbusch

  • Community Member
  • Posts: 27
  • Hero Points: 0
Re: deleting white space between words
« Reply #4 on: January 20, 2007, 08:10:30 PM »
Kohei,

Works like a charm.

Thanks.

Steve