Showing Line Numbers in Script/Code Blocks

##Removed by author.

See the posts below for the reason. (If you’re reading this right as I type, give me a few minutes to complete the other post.)

Thanks for sharing, Dan.

Looks like you have put a lot of hard work into this.
But, to be honest I am not sure I understand the use case. Perhaps you could expound to help me and others better understand?

Here is a related macro, that is much simpler.

It just takes a script on the clipboard, replaces the TAB characters, and pastes into a Discourse forum (like Keyboard Maestro) with the appropriate forum codes. It uses a Typed Text trigger to support both AppleScript and JXA scripts.

MACRO: KM Forum -- Paste Script Block

I use this all the time.

Dan, I have noticed that you have started posting scripts with embedded line numbers. Are you aware of the issue this creates?

Readers/Users of your script can no longer just copy and paste your script, as it obviously won't compile with the line numbers as part of the script.

Script Editor does not show line numbers, and I have been using it for years without them. IMO, the benefit of posting with line numbers is far outweighed by the loss of ease of copy/paste into Script Editor.

Please consider not using line numbers when you post scripts.

Thanks.

Jim - In the long run, you’re correct, and I’ve removed the macro because we don’t want people to get in the habit of using line numbers. Hadn’t thought about that.

The reason I used line numbers in the other posts was because I was trying to explain a point, and I wanted to be able to refer to specific lines.

So I may choose to use line numbers in some future posts, but I think I’ll find a way to make it easy to remove them also. I’ve got an idea, so give me a few to see if it works.

OK, check out the edit in this post and tell me what you think:

Sorry, but I don't think that is a good solution.

  • I was surprised that it opened up the Regex101.com web site
  • I think it would be confusing to most readers.
  • It breaks all of my macros/scripts that clip a script and paste into Quiver/Script Editor/Script Debugger.

I can understand that, but I'd suggest that you just copy/paste the lines you want to refer to. A little more trouble, but actually easier on the reader.

GitHub also shows line numbers for code files, but puts the line number in a different column of the HTML table. I was able to use JavaScript to pull just the code without the line numbers. However, I'm not sure that would work here because it may interfere with the forum code that formats scripts.

Having said all that, please feel free to use line numbers whenever you feel it is necessary.

Just had another idea:

If you post with line numbers, just attach the actual script file as a zip file.

Crap, I sure don't want that. All other arguments are irrelevant.

I'll be good from now on, I promise! :slight_smile:

1 Like

I’m late to this party.

I don’t know “script” but I love line numbers.

Especially when teaching/explaining, as @DanThomas is doing with “point of interest” in the example.

So, this question:
Is it possible to put line numbers within “comments”.
Something like this:

/* 1 */   Here is some code
/* 2 */   And more code
/* 3 */   Plus more code

Or not?

@peternlewis - According to the Discourse forum, as of version 1.7, Discourse supports Oneboxing, and it should show line numbers.

Here’s what I get when I post a link to one of my GitHub files:

https://github.com/dagware/DanThomas/blob/master/_Examples%20for%20External%20Reference/ElapsedTime.js

Do you know why this example isn’t showing line numbers, and can you alter the settings to show more lines (characters)?

Thanks.

Dan, I changed your Topic Title to:

Showing Line Numbers in Script/Code Blocks

and the category to "general"

More useful, I hope.

1 Like

The forum is on 1.6.7 currently (soon to be 1.6.8). Not 1.7 which is still in beta. 1.7 has those horrible new summary email style which I'm not looking forward to :frowning: but I'll install it when it is final (plus a bit).

1 Like

I started new thread on that interesting comment above: