• Login
Community
  • Login

Hide comments mode

Scheduled Pinned Locked Moved General Discussion
11 Posts 5 Posters 4.6k 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.
  • P
    PeterJones
    last edited by Jan 5, 2019, 12:59 AM

    That feature doesn’t exist natively, as far as I know.

    You can add a feature request, per the instructions in the FAQ – make sure you search the existing issues, to make sure you aren’t duplicating an existing request.

    There might be a workaround, using PythonScript or similar automation tool, but I cannot immediately see how to easily do that. If you’d like a workaround like that, speak up, and maybe someone here will find the time to ponder that.

    1 Reply Last reply Reply Quote 0
    • A
      Alan Kilborn @Александр Хренников
      last edited by Jan 5, 2019, 2:10 AM

      @Александр-Хренников

      Notepad++/Scintilla has a hide/unhide lines feature, but it doesn’t work very well (has inconsistencies). @Claudia-Frank was working on a Pythonscript-based replacement a while ago, but she seems to have departed us for greener pastures. :)

      Still, @PeterJones is on the right track–something could be done to make this a reality. Note that as you’ve defined it, it would only work for full line comments, not partial line comments.

      1 Reply Last reply Reply Quote 0
      • G
        guy038
        last edited by guy038 Jan 5, 2019, 1:21 PM Jan 5, 2019, 1:16 PM

        Hello, @александр-хренников, @peterjones, @alan-kilborn and All,

        I’m thinking of two possible work-arounds :

        First solution :

        You could create a simple Python or Lua script which pastes your code in a new tab, then executes, in the new tab’s text, the regex search/replacement, below :

        SEARCH (?-s)^(\h*[#;].*|\h*)\R

        REPLACE Leave EMPTY

        which just gives your expected text :

        port 1194
        proto udp
        dev tun
        ca ca.crt
        cert server.crt
        key server.key  # This file should be kept secret
        dh dh2048.pem
        server 10.8.0.0 255.255.255.0
        ifconfig-pool-persist ipp.txt
        keepalive 10 120
        cipher AES-256-CBC
        persist-key
        persist-tun
        status openvpn-status.log
        verb 3
        explicit-exit-notify 1
        

        Obviously, no code modification could be done, in the new tab ,only visualization !


        Second solution :

        • Run the regex search/replacement, below, in your real code file :

        SEARCH (?-s)^(\h*[#;].*|\h*)\R

        REPLACE Leave EMPTY

        • In this condensed code, bookmark some parts of your code, that you’re interesting in, for later modifications

        • Performs a Ctrl+Z operation to restore the original contents of your code

        • From beginning of file, press the F2 or Shift + F2 shortcuts to navigate throughout these bookmarks ( which are kept ! ) and modify your code just as you want to ;-))

        Best Regards,

        guy038

        E 1 Reply Last reply Jan 5, 2019, 1:43 PM Reply Quote 2
        • E
          Eko palypse @guy038
          last edited by Jan 5, 2019, 1:43 PM

          @guy038 said:

          (?-s)^(\h*[#;].|\h)\R

          if you could find a regex which results in a block instead of returning each line then
          we could use something like editor.research and editor.hideLines to make this work.
          What do you think?

          1 Reply Last reply Reply Quote 0
          • E
            Eko palypse
            last edited by Jan 5, 2019, 1:54 PM

            the reason for asking matching a block is because this

            def hideLine(match):
                line = editor.lineFromPosition(match.span()[0])
                editor.hideLines(line,line)
                
            editor.research(r'(?-s)^(\h*[#;].*|\h*)\R', hideLine)
            

            does work but is somehow slow.

            1 Reply Last reply Reply Quote 1
            • G
              guy038
              last edited by guy038 Jan 5, 2019, 3:20 PM Jan 5, 2019, 3:16 PM

              Hi, @александр-хренников, @peterjones, @alan-kilborn, @eko-palypse and All,

              Ah, OK, I understand ! I should have found it, directly :-(

              So, my second attempt would be :

              SEARCH (?-s)(^\h*(?:[#;].*|)\R)(?1)*

              REPLACE Leave EMPTY

              This new formulation decrease, drastically, the number of replacements ;-)) From 301 to 13, in our example !


              REMARK : Do note the difference between :

              • (?1) which is a routine call to the referenced group 1 itself ( ^\h*(?:[#;].*|)\R )

              • \1 which is a back-reference to the present value of group 1

              For instance :

              • The regex (\d\d\d)(?1)* would match any range of digits, which is a multiple of 3, where as :

              • The regex (\d\d\d)\1* would just match any range of 3 digits, possibly repeated

              Just test these two regexes, against text below :

              123123123          # 123, repeated 3 times
              123456789          # digits from 1 to 9
              123456456          # 123, followed with 456, twice
              123123123123123    # 123, repeated 5 times
              12345601234567890  # '123456' + '1234567890' ( 17 digits )
              

              As you can see, the regex (\d\d\d)(?1)* is strictly equivalent to the regex (\d\d\d)(\d\d\d)*


              I’ve, even, found out a shorter regex, for our problem :

              SEARCH (?-s)^\h*(?:[#;].*|)\R(?0)*

              REPLACE Leave EMPTY

              Where the (?0) syntax is a call routine to the entire regex. But, in that case, from my quick explanations, in the remark section, I don’t exactly understand WHY that regex does work too !!

              Indeed :

              • The regex (?-s)(^\h*(?:[#;].*|)\R)(?1)* is equivalent to the regex (?-s)(^\h*(?:[#;].*|)\R)(^\h*(?:[#;].*|)\R)* Right !

              • So the regex (?-s)^\h*(?:[#;].*|)\R(?0)* should be equivalent to the regex (?-s)^\h*(?:[#;].*|)\R(?-s)^\h*(?:[#;].*|)\R(?0)**, which has, again, a (?0)* syntax, leading to a second development, and so on… ??

              Anyway, it works fine ;-))

              BR,

              guy038

              1 Reply Last reply Reply Quote 3
              • E
                Eko palypse
                last edited by Eko palypse Jan 5, 2019, 3:38 PM Jan 5, 2019, 3:37 PM

                brilliant, and a script like

                regex = r'(?-s)(^\h*(?:[#;].*|)\R)(?1)*'
                
                def hideLine(match):
                    start, end = match.span()
                    _start = editor.lineFromPosition(start)
                    if _start == 0:
                        _start = 1
                    _end = editor.lineFromPosition(end) - 1
                    editor.hideLines(_start,_end)
                    
                editor.research(regex, hideLine)
                

                could hide the lines.
                Note, scintilla prevents hiding the first line.

                A 1 Reply Last reply Jan 10, 2019, 2:29 PM Reply Quote 3
                • A
                  Alan Kilborn @Eko palypse
                  last edited by Jan 10, 2019, 2:29 PM

                  @Eko-palypse

                  Anybody else notice that if you hide lines in this manner, then switch the tab you are editing in N++, then switch back, the lines are no longer hidden??

                  E 1 Reply Last reply Jan 11, 2019, 2:50 PM Reply Quote 2
                  • E
                    Eko palypse @Alan Kilborn
                    last edited by Jan 11, 2019, 2:50 PM

                    @Alan-Kilborn

                    yes, theory - looks like npp is explicitly unfolding code if it can find its own fold marker
                    when activating a buffer. Haven’t checked source code yet. If this is the case, then by
                    either using npps fold marker or buffer activated callback to rehide the lines might solve
                    the issue.

                    1 Reply Last reply Reply Quote 0
                    • A
                      Alan Kilborn
                      last edited by Dec 19, 2022, 2:33 AM

                      There’s a possible solution for this thread’s topic, HERE.

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