Author Topic: Hungry delete  (Read 3492 times)

mcarlson

  • Community Member
  • Posts: 15
  • Hero Points: 0
Hungry delete
« on: August 19, 2008, 04:31:18 pm »
I've done a search of the forums, but I am failing to find any answers.

Is there an option or macro to emulate emacs "hungry-delete" mode?
This removes all whitespace between the cursor and the previous non-whitespace char including new lines.

I tried to write a macro to do this, but have to admit that I'm not yet familiar enough with Slick-C.
BTW - is there a way to break a Slick-C macro when you write an infinite loop? :-[

Matt

hs2

  • Senior Community Member
  • Posts: 2744
  • Hero Points: 288
Re: Hungry delete
« Reply #1 on: August 19, 2008, 04:35:07 pm »
Howto break Slick-C macro code: SHIFT-CTRL-ALT-F2
HS2

Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1299
  • Hero Points: 130
Re: Hungry delete
« Reply #2 on: August 19, 2008, 06:06:42 pm »
Try gnu_delete_space command, bound to Alt-\ in default GNU Emacs emulation.  I think that's what you want.

mcarlson

  • Community Member
  • Posts: 15
  • Hero Points: 0
Re: Hungry delete
« Reply #3 on: August 19, 2008, 08:34:43 pm »
I think I found a solution and thought I would share it for the next person who comes over from emacs.
If you see an easier way to do something I've done here, I'd love to hear about it.

Code: [Select]
#include "slick.sh"

boolean is_whitespace( _str cur_char )
{
   boolean ws = false;

   if( (cur_char == " ")  ||
       (cur_char == "\n") ||
       (cur_char == "\t") ||
       (cur_char == "\r") )
   {
      ws = true;
   }

   return( ws );
}

_command void hungry_delete( ) name_info(','VSARG2_REQUIRES_EDITORCTL)
{
   int col = p_col;
   left();
   cur_char = get_text();
   if( col > 1 ) { right();}

   if( is_whitespace( cur_char) )
   {
      /* backspace until we find a char */
      while( is_whitespace( cur_char ) || (col == 1) )
      {
         linewrap_rubout();
         col = p_col;
         left();
         cur_char = get_text();
         if( col > 1) { right(); }
      }
   }
   else
      linewrap_rubout();
}

If the "Line Wrap on Text" option is selected ("Tools", "Options", "Redefine Common Keys...") hungry-delete will continue past the beginning of the current line.

Thanks for the help.
And also thanks for all the help you've given others.  The archives here are a great resource.

Matt

EDIT:
It's better if it also deletes non-whitespace chars  ::)
« Last Edit: August 19, 2008, 09:00:33 pm by mcarlson »