Author Topic: How to copy/paste code with line numbers?  (Read 575 times)

rowbearto

  • Senior Community Member
  • Posts: 2303
  • Hero Points: 132
How to copy/paste code with line numbers?
« on: January 03, 2023, 07:56:14 PM »
I often want to share some snippet of code with a colleague.

I'd like the code to show the line number for each line.

In SlickEdit editor window the line number display is not selectable text - I can put a screenshot in my email but that isn't so great as whoever is receiving it can't copy/paste.

How to get a buffer that shows line# next to the code so I can copy/paste it into an email?

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 3925
  • Hero Points: 515
Re: How to copy/paste code with line numbers?
« Reply #1 on: January 03, 2023, 10:22:32 PM »
This is not exactly great, but suppose you have a selection, you can do Edit > Other > Enumerate, make the start number the first line number, and enumerate decimal numbers counting up by one.  Copy, then Undo.  If you record a macro for this, you can change the call to "enumerate()" to replace the start line number with p_RLine.  For example (assuming you made the selection from bottom-up):
Code: [Select]
   _macro('R',1);
   enumerate(" "p_RLine" 1 6",null,null,'0');
   last_event(name2event('C_C'));copy_to_clipboard();
   undo();
   undo();

« Last Edit: January 03, 2023, 10:27:12 PM by Dennis »

rowbearto

  • Senior Community Member
  • Posts: 2303
  • Hero Points: 132
Re: How to copy/paste code with line numbers?
« Reply #2 on: January 04, 2023, 03:59:35 PM »
Thanks Dennis!

rowbearto

  • Senior Community Member
  • Posts: 2303
  • Hero Points: 132
Re: How to copy/paste code with line numbers?
« Reply #3 on: August 28, 2023, 04:56:25 PM »
I just tried to highlight my selection but when I do Edit->Other the 'enumerate' is greyed out and I can't select it.

I'm using 27.0.2 QT5 on Linux x64.

UPDATE: I tried running the command and it said not allowed in read only mode. So I'll have to copy this file somewhere else.