Community
    • Login

    Is there a way to get the current line number into the copy/paste buffer?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    13 Posts 3 Posters 3.5k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mkupperM
      mkupper
      last edited by

      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

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @mkupper
        last edited by PeterJones

        @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 because lineFromPosition() returns a line-number that starts at 0 for the first line of the file.)

        mkupperM 1 Reply Last reply Reply Quote 3
        • Alan KilbornA
          Alan Kilborn
          last edited by

          Somewhat related:

          I was experimenting with the Go to window and noticed this:

          077c93e5-e817-454c-adf6-e134626ba455-image.png

          The funny part is the You can’t go further than number is less than the You are here number.

          PeterJonesP 1 Reply Last reply Reply Quote 0
          • mkupperM
            mkupper @PeterJones
            last edited by

            @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.

            Alan KilbornA PeterJonesP 4 Replies Last reply Reply Quote 0
            • Alan KilbornA
              Alan Kilborn @mkupper
              last edited by Alan Kilborn

              @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))
              
              1 Reply Last reply Reply Quote 2
              • Alan KilbornA
                Alan Kilborn @mkupper
                last edited by

                @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.

                1 Reply Last reply Reply Quote 1
                • PeterJonesP
                  PeterJones @mkupper
                  last edited by PeterJones

                  @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.

                  1 Reply Last reply Reply Quote 2
                  • Alan KilbornA
                    Alan Kilborn @mkupper
                    last edited by Alan Kilborn

                    @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. :-)

                    1 Reply Last reply Reply Quote 3
                    • PeterJonesP
                      PeterJones @Alan Kilborn
                      last edited by

                      @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 then Ctrl+G, I always see akin to:
                      1d340b2e-d9d9-46b3-9c37-5e41216960bc-image.png

                      Alan KilbornA 1 Reply Last reply Reply Quote 0
                      • Alan KilbornA
                        Alan Kilborn @PeterJones
                        last edited by

                        @PeterJones

                        cannot replicate

                        You are doing Line.
                        I was doing Offset (or Position Offset).

                        PeterJonesP 1 Reply Last reply Reply Quote 0
                        • PeterJonesP
                          PeterJones @Alan Kilborn
                          last edited by

                          @Alan-Kilborn said in Is there a way to get the current line number into the copy/paste buffer?:

                          @PeterJones

                          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”

                          mkupperM 1 Reply Last reply Reply Quote 0
                          • mkupperM
                            mkupper @PeterJones
                            last edited by

                            @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.

                            Alan KilbornA 1 Reply Last reply Reply Quote 0
                            • Alan KilbornA
                              Alan Kilborn @mkupper
                              last edited by

                              @mkupper

                              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++.

                              1 Reply Last reply Reply Quote 1
                              • mkupperM mkupper referenced this topic on
                              • First post
                                Last post
                              The Community of users of the Notepad++ text editor.
                              Powered by NodeBB | Contributors