Is there a way to get the current line number into the copy/paste buffer?
-
With Microsoft notepad I can go to a line, press ctrl-G which brings up the Go To Line dialog box, and the current line number is both the default value and is sitting in the input field to select which line to go to. It’s easy enough to then load the line number into the copy/paste buffer.
With Notepad++ ctrl-G brings up the Go To… dialog box which shows
You are here: (current number) You want to go to: [blank input box]
There’s no way to load the current line number into the copy/paste buffer.
While editing I tried right clicking on the left margin where the line numbers are and looked through TextFX menu offerings but don’t see a way to get the current line number.
I’m running
Notepad++ v7.9 (32-bit)
Build time : Sep 22 2020 - 03:24:22
Path : C:\Program Files (x86)\Notepad++\notepad++.exe
Admin mode : OFF
Local Conf mode : OFF
OS Name : Windows 10 Home (64-bit)
OS Version : 1909
OS Build : 18363.1139
Current ANSI codepage : 1252
Plugins : DSpellCheck.dll HexEditor.dll mimeTools.dll NppConverter.dll NppExport.dll NppTextFX.dll PythonScript.dll -
@mkupper said in Is there a way to get the current line number into the copy/paste buffer?:
PythonScript.dll
You have PythonScript, so why not make a script which puts
editor.lineFromPosition(editor.getCurrentPos())+1
into the clipboard, and assign it to a keyboard shortcut of your choosing. (The+1
is needed becauselineFromPosition()
returns a line-number that starts at 0 for the first line of the file.) -
Somewhat related:
I was experimenting with the Go to window and noticed this:
The funny part is the You can’t go further than number is less than the You are here number.
-
@PeterJones Thank you. Can you provide a more complete script? I don’t know the code to get a value into the copy/paste buffer for example.
Is there an easy way to discover which keyboard sequences are in use? For example, as crtl-g is the current go-to dialog I’d want to see if ctrl-shift-g or something similar is available on my system to map to a new script.
Are there ways to add menu items to the main editor’s right click menu that can be linked to a new script? I see Plugin commands and under that Base64 Encode, Base64 Decode, and copy text with syntax highlighting.
Thank you.
-
@mkupper said in Is there a way to get the current line number into the copy/paste buffer?:
Can you provide a more complete script? I don’t know the code to get a value into the copy/paste buffer for example.
Try this as your “complete script”:
editor.copyText(str(editor.lineFromPosition(editor.getCurrentPos())+1))
-
@mkupper said in Is there a way to get the current line number into the copy/paste buffer?:
Is there an easy way to discover which keyboard sequences are in use?
See HERE.
-
@mkupper said in Is there a way to get the current line number into the copy/paste buffer?:
Are there ways to add menu items to the main editor’s right click menu that can be linked to a new script? I see Plugin commands and under that Base64 Encode, Base64 Decode, and copy text with syntax highlighting.
Alan answered the others. This one is Settings > Edit Popup Context Menu (see for reference https://npp-user-manual.org/docs/config-files/#the-context-menu-contextmenu-xml)
edit: if you search the forum for “contextMenu.xml”, you will see examples of people’s edited context menus, if the official docs aren’t sufficient.
-
@mkupper said in Is there a way to get the current line number into the copy/paste buffer?:
Are there ways to add menu items to the main editor’s right click menu that can be linked to a new script?
Yes. in
contextMenu.xml
you can put a line like this:<Item PluginEntryName = "Python Script" PluginCommandItemName = "name_of_script_as_appears_in_plugin_menu" ItemNameAs = "name_you_want_to_see_in_context_menu" />
EDIT: Peter answered before me, but we both gave good information so I won’t delete mine. :-)
-
@Alan-Kilborn said in Is there a way to get the current line number into the copy/paste buffer?:
The funny part is the You can’t go further than number is less than the You are here number.
I cannot replicate. If I
Ctrl+End
thenCtrl+G
, I always see akin to:
-
-
@Alan-Kilborn said in Is there a way to get the current line number into the copy/paste buffer?:
cannot replicate
You are doing Line.
I was doing Offset (or Position Offset).You’re right. Offset is 0-based when the cursor is before the character. So when your document is 757 bytes, then the cursor is before offset=757, but the last character (“you can’t go further than”) is at offset=756. But if you type a number of 757 or greater in the box, it will properly move your cursor to after the last character. So you can try to go further. But it’s bad phrasing. I would suggest that piece of text should be “offset of last character in file” rather than “you can’t go further than”
-
@PeterJones I don’t think there’s an easy wording fix for the lines vs offset thing. Any choice of words seems likely to be confusing to someone in the community of npp users.
Changing the offsets for the Go To dialog box so that they start at 1, much like lines, seems to be a better fix. Offset 1 would be the first character. This would also make it consistent with the column number, which starts at 1. That change would break scripts that invoke the Go To box and use offset mode.
-p on the command line likely should remain zero based.
-
Changing the offsets for the Go To dialog box so that they start at 1…
Actually, “offset” (being zero-based) makes perfect sense.
If it were strictly “position” maybe it would make less sense, as that seems to more imply one-based.
Although, in Scintilla-speak, SCI_GETCURRENTPOS returns a 0 if the caret is at beginning-of-file.I think I saw that a change is coming to Notepad++ where “position” is going to be displayed on the status bar. I can’t remember if it is zero-based or one-based.
That change would break scripts that invoke the Go To box and use offset mode.
I don’t think there are any such scripts as the Go To box isn’t scriptable?
-p on the command line likely should remain zero based.
It seems like Notepad++ should get its act together and be internally consistent, be either 0-based or 1-based when dealing with “position”, no matter what existing functionality it might break. :-)
I just noticed in a UTF-8 document, if I put my caret just before a Unicode character that encodes into 4 bytes, I get an
editor.getCurrentPos()
return of N and if I move it just after that character and repeat that Pythonscript command, I get N+4. This seems wrong to me; I should get N+1… I guess it is one more thing that needs “evaluation” in Notepad++.