Community
    • 登入

    Adding leading zeros or additional leading space for line numbers

    已排程 已置頂 已鎖定 已移動 General Discussion
    7 貼文 4 Posters 2.4k 瀏覽
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • codenotworkingC
      codenotworking
      最後由 編輯

      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 條回覆 最後回覆 回覆 引用 1
      • EkopalypseE
        Ekopalypse @codenotworking
        最後由 編輯

        @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 條回覆 最後回覆 回覆 引用 2
        • Alan KilbornA
          Alan Kilborn @codenotworking
          最後由 編輯

          @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 條回覆 最後回覆 回覆 引用 4
          • guy038G
            guy038
            最後由 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 條回覆 最後回覆 回覆 引用 3
            • guy038G
              guy038
              最後由 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 條回覆 最後回覆 回覆 引用 2
              • Alan KilbornA
                Alan Kilborn @guy038
                最後由 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 條回覆 最後回覆 回覆 引用 2
                • Alan KilbornA
                  Alan Kilborn @guy038
                  最後由 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 條回覆 最後回覆 回覆 引用 3
                  • 第一個貼文
                    最後的貼文
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors