0

I have loaded a macro for < copying selective display > The macro name is copy_shown(). I can run the command by binding to some key. But how do I run it without binding to a key? The macro I am trying to use is by Mathew - see < Slickedit forum thread >.

////////////////////////////////////////////////////////////////////////////////////////////
#include "slick.sh"

/*
  Copy the lines currently shown in the current buffer to the clipboard.  This 
  should ignore lines that are hidden because of selective display settings.
*/
_command void copy_shown()
{
   int lines_copied = 0;
   // Create a new buffer to hold the displayed lines.
   int tempWID;
   int prevWID = _create_temp_view(tempWID);

   // Switch back to the previous buffer to find the lines to copy.
   p_window_id = prevWID;

   // Place cursor on line 0 before first line of the buffer.
   top(); up();

   // Iterate across the lines in the buffer, copying those that are not hidden.
   for (j=1; j<=p_Noflines; j++) {

      // Go down and get the next line.
      if (down()) break;
      get_line(line);

      // If this line is not hidden, copy it to the new buffer.
      if (!(_lineflags() & HIDDEN_LF)) {
         // Copy the line.
         lines_copied++;
         tempWID.insert_line(line);
      }
   }

   if (lines_copied == 0) {
      message('No displayed lines found!');
   }
   else {
      // Activate the temp view to copy the lines
      p_window_id = tempWID;
      select_all();
      copy_to_clipboard();
      // Switch back to original view
      p_window_id = prevWID;
      s = lines_copied==1 ? '' : 's';
      message(lines_copied ' line's ' copied to this buffer.');
   }
   // Clean up the temp view
   _delete_temp_view(tempWID);
}

////////////////////////////////////////////////////////////////////////////////////////////
Eden
  • 1,110
  • 1
  • 12
  • 18
  • Note: My Slickedit is configured to the default CUA emulation. – Eden Mar 13 '14 at 14:36
  • I updated with CUA info as well – nhed Mar 13 '14 at 20:56
  • Thanks, @nhed, I succesfully ran it from the command-line. But the macro is **not** listed in 'Macro->List Macros' even though the macro is loaded in 'Macro->List USer-loaded modules'. – Eden Mar 17 '14 at 12:53
  • can you post the macro? Specifically I wonder what flags are specified in the signature – nhed Mar 18 '14 at 14:47
  • updated my response based on your paste. Next time also follow up with a comments with `@username`, I only noticed that you made the update by chance (and hence why it took me so long to answer). Also (hint, hint), you could also uptick the answer you accepted if it was useful. – nhed Mar 24 '14 at 15:35
  • 1
    Thanks, @nhed, now List-macros works. (Thanks also for the hint ;-) – Eden Mar 26 '14 at 07:17

1 Answers1

1

[updated] You can run it by name from the command prompt

  • In CUA mode you get to the command-line just by pressing esc
  • In EMACS mode it is esc+x

Then type your command, copy_shown, or even copy-shown. (Other emulations may have other sequences to get to the "command-line")

You can also use the menus: Macros -> List Macros Then select your macro and click run

This is also a good way to check that it was really loaded


Edit

Add the name_info as follows to have your macro listed in Macros -> List Macros

_command void copy_shown() name_info(',' VSARG2_MACRO )
nhed
  • 5,774
  • 3
  • 30
  • 44