Hide comments mode
-
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.
-
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.
-
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*)\RREPLACE
Leave EMPTYwhich 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 1Obviously, 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*)\RREPLACE
Leave EMPTY-
In this condensed code, bookmark some parts of your code, that you’re interesting in, for later modifications
-
Performs a
Ctrl+Zoperation to restore the original contents of your code -
From beginning of file, press the
F2orShift + F2shortcuts to navigate throughout these bookmarks ( which are kept ! ) and modify your code just as you want to ;-))
Best Regards,
guy038
-
@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? -
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.
-
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 EMPTYThis new formulation decrease, drastically, the number of replacements ;-)) From
301to13, in our example !
REMARK : Do note the difference between :
-
(?1)which is a routine call to the referenced group1itself (^\h*(?:[#;].*|)\R) -
\1which is a back-reference to the present value of group1
For instance :
-
The regex
(\d\d\d)(?1)*would match any range of digits, which is a multiple of3, where as : -
The regex
(\d\d\d)\1*would just match any range of3digits, 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 EMPTYWhere 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
-
-
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. -
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??
-
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. -
There’s a possible solution for this thread’s topic, HERE.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login