Community
    • Login

    Ignoring empty lines counting

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    24 Posts 9 Posters 5.4k 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.
    • Владислав ПестриковВ
      Владислав Пестриков @PeterJones
      last edited by

      @PeterJones
      thanks very much for answering!

      Did you try it to see?

      Yes, firstly, @Terry said:

      If however you want to get a count of the number of lines that contain text that is a different matter.

      And i answering, that it is not i want.
      Secondly, @Ekopalupse suggest:

      print(len([line for line in editor.getText().splitlines() if line.strip() != '' ]))
      

      So i installed PythonScript plugin and test it, and if i right, its about non-empty lines to count (that i not need).

      Do you understand that counting non-empty lines is what you appeared to be asking for, especially when you said “how to ignore empty lines counting”?

      Im not appeared to counting empty or not lines. I want to change how count npp lines bar what is 1341f2dc-02af-4231-9e94-f79fde12a330-image.png

      Why did it magically change frm 23 to 24?
      Why “of course”? How should we know that? Did you tell us that before?
      In my opinion, you have not successfully communicated your desires in this instance. I really doubt any of us are going to be able to help you until you are able to communicate those desires.

      ok i must explain it better, my bad.
      dfc518cc-ad8e-4058-8357-6e5c9b9ca58e-image.png
      As a left pucture it goes ok for me as programmer that easely find line that provides jump instruction using npp lines counting bar.
      But after adding temporary empty lines for more code readability that you can see on right side picture npp bar digits increases lines count as it should. But for me it means bar digits is not now associated with code jump command, it brings to another print command because correct print now is 23. This issue hinders only me as programmer because empty lines that i added should be removed after publication.

      Please see the Formatting Forum Posts FAQ, because otherwise, we cannot easily read your example text. Also if 4| isn’t literally part of the text, please don’t include it in your example.

      Thanks, now much better.

      How to Develop A Plugin => this section of the user manual takes you through the four steps (which are also shown in the plugin template) to get to a point where you can compile a plugin. After that, you have to understand enough about programming to make the plugin actually do something useful.

      I did steps stopping on 3rd step, you can see my answer upper with picture contains cppPluginTemplate. All just i need its menu on task bar swithing these bar styles and directly my function.
      It is means that if there is not enought plugin template for me i cant create my own plugin?

      Extreemply thanks for help supporting.

      Terry RT EkopalypseE 2 Replies Last reply Reply Quote 0
      • Terry RT
        Terry R @Владислав Пестриков
        last edited by

        @Владислав-Пестриков said in Ignoring empty lines counting:

        It is means that if there is not enought plugin template for me i cant create my own plugin?

        I can see what you require now that you have provided a better example of the issue you have.

        I had mentioned a plugin called CustomLineNumbers. The website is here.

        As a suggestion, make contact with the plugin developer. Since they already have the code sorted for some functionality, maybe with a bit of input from you they may be inclined to expand on their plugin. Alternatively you could take the code (assuming it is “public domain”) and create a “fork” implementing additional code to support your need, since you seem to be OK with programming.

        Of course you should consult with the plugin developer first as it is their code.

        Terry

        1 Reply Last reply Reply Quote 2
        • EkopalypseE
          Ekopalypse @Владислав Пестриков
          last edited by

          @Владислав-Пестриков

          I understand that you want something like that, right?

          1a088ec1-46f2-4546-9689-b982a0dc43a0-image.png

          What do you mean by taskbar? The taskbar is handled by the operating system itself, not Notepad++.
          And if you mean the toolbar, then you need to provide the information when you get a nppn-tbmodification
          by sending nppm-addtoolbaricon message.

          Владислав ПестриковВ 1 Reply Last reply Reply Quote 2
          • Владислав ПестриковВ
            Владислав Пестриков @Ekopalypse
            last edited by

            @Ekopalypse
            Oh yeah! Give it me please!

            What do you mean by taskbar? The taskbar is handled by the operating system itself, not Notepad++.
            And if you mean the toolbar, then you need to provide the information when you get a nppn-tbmodification
            by sending nppm-addtoolbaricon message.

            Sorry, language barrier.
            a5e66104-7193-45a9-8853-cbfc662c3e6c-image.png
            like these buttons

            EkopalypseE 1 Reply Last reply Reply Quote 0
            • EkopalypseE
              Ekopalypse @Владислав Пестриков
              last edited by

              @Владислав-Пестриков

              Sorry, what do you mean?
              The code on the right does what your plugin needs to do, and probably more, since this is just a proof of concept.
              For example, how to deal with line wrapping, hidden/collapsed lines, etc.

              If it’s how to add an icon to the toolbar, you can see that in the demo code here.

              Владислав ПестриковВ 1 Reply Last reply Reply Quote 2
              • Владислав ПестриковВ
                Владислав Пестриков @Ekopalypse
                last edited by

                @Ekopalypse
                Oh! Godness, thanks a lot!
                I was confused your right side line counting bar is different instead left, i thought it was just a text.

                Now i write code in python scrypt plugin and if works extreemly fine (without minor issues, but nvm).

                Interesting that digit style is different. Looks like bar displaying works harder then i thought.

                Bless you and happy x-mas to you and npp community!

                1 Reply Last reply Reply Quote 0
                • madara sanM
                  madara san @Владислав Пестриков
                  last edited by

                  @Владислав-Пестриков said in Ignoring empty lines counting:

                  Hello there!
                  Im searching option how to ignore empty lines counting. For example:
                  1 | line1
                  2 |
                  3 | line2
                  And i want
                  1 | line 1
                  1 |
                  2 | line2
                  is there any function or plugin?
                  Thanks!

                  Yes, there are several ways to ignore empty lines when counting lines in a document. Here are a few options:

                  Use a text editor with a line counting feature that allows you to exclude blank lines. For example, in Notepad++, you can go to “View” > “Summary” to see a summary of the document, including the number of lines with and without blank lines.

                  Use a regular expression (regex) to match and replace the blank lines. In most text editors, you can use the find and replace function and search for the regex pattern “^$” (which matches an empty line) and replace it with nothing. This will effectively remove the blank lines and adjust the line numbering accordingly.

                  Use a scripting language like Python or Perl to read the file and count only non-empty lines. This would require some coding, but it can be a more flexible solution if you need to perform more complex operations on the file.

                  I hope this helps!

                  Mark OlsonM 1 Reply Last reply Reply Quote -4
                  • Mark OlsonM
                    Mark Olson @madara san
                    last edited by

                    @madara-san
                    I appreciate your (apparent?) desire to help people, but using generative AI is not the way to do this. StackOverflow has banned people from using ChatGPT, and for good reason.

                    For example:

                    For example, in Notepad++, you can go to “View” > “Summary” to see a summary of the document, including the number of lines with and without blank lines.
                    

                    This is false, the View->Summary tab does not include information on how many lines are empty.

                    Use a regular expression (regex) to match and replace the blank lines. In most text editors, you can use the find and replace function and search for the regex pattern “^$” (which matches an empty line) and replace it with nothing.
                    

                    This is almost helpful, except that a quick attempt to actually do the thing you suggested reveals that while the find/replace form finds empty lines, the count feature does not count them. Also, the user doesn’t want to replace empty lines.

                    Honestly I don’t know why I waste my breath. I’d strongly urge the forum mods to ban this user if they don’t stop wasting people’s time with uncurated crud out of ChatGPT.

                    1 Reply Last reply Reply Quote 6
                    • Mark OlsonM
                      Mark Olson
                      last edited by

                      While I’m here, here’s a no-plugin way to get the answer (indirectly):

                      1. Go to Find/replace form.
                      2. Count the occurrences of the following regex: ^\h*\S+\h*$.
                      • This is the number of lines that don’t have only whitespace.
                      • You can then subtract this number from the number of lines in the document, and that’s how many empty or whitespace-only lines you have.

                      TBH I think it’s pretty weird that the Count feature doesn’t count empty matches, and this could arguably be considered a bug.

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

                        @Mark-Olson said in Ignoring empty lines counting:

                        I think it’s pretty weird that the Count feature doesn’t count empty matches, and this could arguably be considered a bug.

                        Mark All also won’t do matches of zero-length (e.g. assert-only matches like ^$), but this perhaps is more understandable since there is no text to “mark”.

                        Were you going to open a bug report issue about Count?

                        Mark OlsonM 2 Replies Last reply Reply Quote 1
                        • Mark OlsonM
                          Mark Olson @Alan Kilborn
                          last edited by

                          @Alan-Kilborn
                          Not sure if I want to open a bug report, because I can see why this could be considered intended behavior.

                          I may open one later today.

                          1 Reply Last reply Reply Quote 1
                          • Mark OlsonM
                            Mark Olson @Alan Kilborn
                            last edited by

                            @Alan-Kilborn
                            Actually, I came up with a good solution to the issue of Count not counting empty matches.
                            Show something like 20 matches (including 10 empty matches)

                            I’ll create an issue if you haven’t already, and then I’ll start on a PR.

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

                              Hello, @mark-olson, @alan-kilborn and All,

                              Regarding counting of lines, here are my solutions !


                              • First, insert this dummy text, below, in a new N++ tab
                              This
                              is
                              
                              
                              
                              a
                              
                              small
                              test
                              to
                              			
                                    
                              
                              see if
                                    this       test   
                              			is		OK		
                              That's the
                              END
                              
                              • Open the Find dialog ( Ctrl + F )

                              • Unchek all box options

                              • Check the Wrap around option

                              • Click on the Count button or use the Alt + T shortcut for all the examples below


                              
                              So, for one hand :
                              
                              
                                  ^\R          count ALL lines with NO character ( True EMPTY lines )    =>     5 lines
                              
                               +
                              
                                  ^\h+$        count ALL lines with horizontal BLANK characters ONLY     =>     2 lines
                              
                               =
                              
                                  ^\h*\R       count ALL lines WITHOUT any NON-SPACE character           =>     7 lines
                              
                               +
                              
                                  (?-s)\S.*    count ALL lines with, at LEAST, 1 NON-SPACE character     =>    11 lines    ( as well as  (?-s).*\S )
                              
                               =
                              
                                  (?-s).*\R    count ALL lines                                           =>    18 lines
                              
                              
                              
                              And for the other hand :
                              
                              
                                  ^\R           count ALL lines with NO character ( True EMPTY lines )    =>    5 lines
                              
                               +
                              
                                  (?-s).*       count ALL lines with, at LEAST, 1 character               =>   13 lines 
                              
                               =
                              
                                  (?-s).*\R     count ALL lines                                           =>   18 lines
                              
                              

                              Notes :

                              • Just repeat the counting , using the Mark dialog, to better identify the class of the counted lines !

                              • Of course, you may use a normal selection of text and check the in selection option to restrict the counting to that selection

                              Best Regards,

                              guy038

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

                                I’ll create an issue if you haven’t already…

                                The issue that was opened:

                                https://github.com/notepad-plus-plus/notepad-plus-plus/issues/13608

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

                                  Hi, @mark-olson, @alan-kilborn and All,

                                  Did you notice this fact :

                                  • The regex ^$, indeed, does not count true empty lines !

                                  but :

                                  • The regex ^\R does count empty lines !!

                                  BR

                                  guy038

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

                                    @guy038 said in Ignoring empty lines counting:

                                    The regex ^$, indeed, does not count true empty lines !

                                    but :

                                    The regex ^\R does count empty lines !!

                                    If the regex is purely an assertion, e.g. ^$ or \b (to name but two), then its match won’t be counted by Count.

                                    CoisesC 1 Reply Last reply Reply Quote 5
                                    • CoisesC
                                      Coises @Alan Kilborn
                                      last edited by

                                      @Alan-Kilborn said in Ignoring empty lines counting:

                                      @guy038 said in Ignoring empty lines counting:

                                      The regex ^$, indeed, does not count true empty lines !

                                      but :

                                      The regex ^\R does count empty lines !!

                                      If the regex is purely an assertion, e.g. ^$ or \b (to name but two), then its match won’t be counted by Count.

                                      True (since a pure assertion is always an empty match), but empty matches aren’t counted regardless of how the regular expression is specified. In a file that has empty lines, but no lines containing only capital Ws, ^W*$ counts zero matches. ^\R counts all empty lines (except the last line, if it’s empty) because it isn’t an empty match: it matches line ending characters. ^.*$ and ^.+$ both count all lines that are not empty.

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