Community
    • Login

    Adding leading zeros or additional leading space for line numbers

    Scheduled Pinned Locked Moved General Discussion
    7 Posts 4 Posters 2.1k 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.
    • codenotworkingC
      codenotworking
      last edited by

      I’m curious if there is a way to add leading zeros or additional leading space for line numbers.

      I have a situation where I have a file that has nearly 3000 lines. From 1 to 999, the line numbers are properly padded. But once I reach line 1000, the area expands to accommodate the larger number, shifting the main area to the right slightly, which is a bit annoying as I scroll and view the file.

      I made an example gif of what is occurring.

      Just wondering if there is some setting or secret file in Notepad++ I can modify. Currently I am using version 7.5.7.

      EkopalypseE Alan KilbornA 2 Replies Last reply Reply Quote 1
      • EkopalypseE
        Ekopalypse @codenotworking
        last edited by

        @codenotworking

        I don’t think so and it seems that changing width via a scripting language isn’t successful either. Seems you need to open an issue at github but as far as I remember there has one been opened recently. Please check before reopen another one.

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

          @codenotworking said:

          …once I reach line 1000, the area expands to accommodate the larger number, shifting the main area to the right slightly, which is a bit annoying as I scroll and view…

          There’s a workaround proposed by xylographe that works for this, and it is found here: https://github.com/notepad-plus-plus/notepad-plus-plus/issues/5670

          1 Reply Last reply Reply Quote 4
          • guy038G
            guy038
            last edited by guy038

            Hello, @codenotworking, @ekopalypse, @alan-kilborn, and All,

            Many thanks, Alan, for pointing out this GitHub article !

            So, to summarize, as the predefined STYLE_LINENUMBER is numbered 33 ( Refer below )

            https://www.scintilla.org/ScintillaDoc.html#StyleDefinition

            And, from the two links, below, as we can, obviously, choose any string, in order to calculate the LINENUMBER margin

            https://www.scintilla.org/ScintillaDoc.html#SCI_SETMARGINWIDTHN

            https://www.scintilla.org/ScintillaDoc.html#SCI_TEXTWIDTH


            Let’s use the simple format “12345678”, which allows number lines between values 1 and 99,999,999 ( 8 digits )

            Hence, the two commands, that I’ve personally tested :

            • With the Python script : editor.setMarginWidthN(0, editor.textWidth(33, "12345678"))

            • With the Lua script : editor.MarginWidthN[0] = editor:TextWidth(33, "12345678")


            Note that if your current file contains more than 99,999,999 lines, any digit, on the left, is, then, truncated !

            So, the transition between the two lines 99,999,999 and 100,000,000, bookmarked would look like, as below :

            99999999 ● ( Line  99,999,999 )
            00000000 ● ( Line 100,000,000 )
            

            Best Regards,

            guy038

            1 Reply Last reply Reply Quote 3
            • guy038G
              guy038
              last edited by guy038

              Hi, All,

              Regarding my previous post, I’ve noticed that, after running the script commands, if you increase the zoom factor, significantly, you may miss the leftmost number digit :-((

              In that case, just re-run the appropriate script command, with the same parameters !

              Note that, with the native N++ numbering; this is done automatically ;-))

              Cheers,

              guy038

              Alan KilbornA 2 Replies Last reply Reply Quote 2
              • Alan KilbornA
                Alan Kilborn @guy038
                last edited by Alan Kilborn

                @guy038 said:

                …zoom…

                True, but this would be a rare thing (for most people). Much rarer than that little visual blip that occurs as you move through line # 1000.

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

                  @guy038 said:

                  …zoom…

                  But if it is really a factor for you, you could put it in a zoom-notify :

                  try:
                      zoom_notify_installed
                  except NameError:
                      def callback_sci_ZOOM(_): editor.setMarginWidthN(0, editor.textWidth(33, "12345678"))
                      editor.callback(callback_sci_ZOOM, [SCINTILLANOTIFICATION.ZOOM])
                      zoom_notify_installed = True
                  editor.setMarginWidthN(0, editor.textWidth(33, "12345678"))
                  

                  (for Pythonscript; I don’t know the Luascript way of doing that)

                  1 Reply Last reply Reply Quote 3
                  • First post
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors