Author Topic: duplicate_lines macro  (Read 6448 times)

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
duplicate_lines macro
« on: May 07, 2008, 11:51:28 PM »
Hi, I found that I'm using my own duplicate_lines() alias 'dl' macro quite a lot. So I though I should post it here.
Maybe someone else also thinks that the stock duplicate_line() is too limited ;)
I even bound it to a key combination (SHIFT-ALT-INS in my case)...

Description:
If nothing is selected it behaves like duplicate_line() and dups the current line.
If something is selected (any selection can be used: CHAR/BLOCK/LINE) comprising one or more lines these lines are duplicated.
You can use top-down or bottom-up selections. The affected lines are always copied below the initial selection.
The resulting copy is still (LINE) selected to repeat the command a number of times.
The selection is cleared on next cursor move. Intentionally NO clipboard is created or used.
Unfortunately I'm not 100% sure if it works with all selection configurations.
Code: [Select]
_command void duplicate_lines,dl () name_info(','VSARG2_MARK|VSARG2_TEXT_BOX|VSARG2_REQUIRES_EDITORCTL)
{
   boolean single_line = !select_active ();
   if ( single_line )   select_line();
   else                 _select_type("",'T','LINE');

   int endsel = _end_select_compare();
   if ( endsel < 0 ) // handle bottom up selection
   {
      deselect();
      select_line();
      // - -N = +N
      p_line -= endsel;
   }
   _copy_to_cursor();

   if ( single_line )   deselect();

   // optionally go to the beginning of the dup'd lines
   down();
   // first_non_blank();
}

Have fun,
HS2
« Last Edit: May 07, 2008, 11:55:57 PM by hs2 »

ehab

  • Senior Community Member
  • Posts: 285
  • Hero Points: 15
  • coding with SE is like playing music
Re: duplicate_lines macro
« Reply #1 on: May 08, 2008, 06:02:43 AM »
can be handy one day ... thanks