-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for multiline search, and for searching for 0x0A bytes. #400
Comments
|
Replying to Hubbitus (#400):
This is already possible by typing CTRL-Q, Enter for the newline |
By CTRL+Q pressing "Insert Literal" dialog appeared. |
No, one can't search over multiple lines in mcedit.
The search library searches line by line. See mc_search__run_regex() in lib/search/regex.c. There's a loop there that accumulates a line:
(You can find the last \n on a line, but this has no real benefit. BTW, you don't have to use CTRL-Q: if you choose "Regular expression" you can simply type the two characters "\n".)
mc2 comes with a snippet that lets one search over multiple lines. |
We can solve this by adding to the search dialog a "[x] Search over lines" checkbox what would turn off the "current_chr == '\n'" check I quoted in comment 4. This would make the text accumulate in one giant string instead of line-by-line (but we should set some limit in case one searches in a 20 terabyte file...).
If we detect a newline in the regexp, we'll search-over-lines automatically. But having a checkbox is good for the case one wants to search for things like "struct \{.*?\}", where it's a dot that stands for a newline. |
|
Since we can't find 0x0A bytes (in hex search), I'm changing this to 'defect'. |
Ok, here's a series of three small patches to fix this ticket: What's in it?
(1) "introduce slurp mode"
This mode disables the "\n" chunking, which, as comment comment:4 explains, is the cause of all the problems. There's very little actual code here.
(2) "hex search: make it possible to search for 0x0A bytes."
This patch uses slurp mode to fix the hex search bug.
(3) "mcedit: make it possible to search across lines."
This patch uses slurp mode to implement a new feature: letting users search across lines. It adds an "Across lines" checkbox to the search and search-replace dialogs:
(In comment:5 I also suggested enabling this feature automatically if the pattern has newlines in it, but I no longer think this "extra wisdom" it a good idea; it will just add confusion.) What's next?
Andrew, if you're fine with this solution, let me know and I'll work on some refinements:
Performance
Initially I thought backwards-search, which is not implemented quite efficiently, would put the kibosh on slurp mode. Surprisingly, however, I didn't notice a substantial difference in performance between slurp and non-slurp mode when doing backwards-search. Neither was the memory strained. Maintainability
There's very little code added, and the patches essentially modify only two lines --in regex.c. To me this looks like a safe solution. |
|
|
|
"Across lines" sounds a bit weird to me, do you know how it is done/called in other editors? I quickly checked gedit and kate, and they don't seem to have such a checkbox, but if the pattern contains \n, they capture multiple lines by default... Is there a downside to this behavior? |
Replying to zaytsev:
Once we agree that a checkbox is necessary, the bonus issue of automatically detecting \n can be blissfully handled independently, in a separate ticket.
So I think there are two possibilities:
(A) We can delegate the \n detection to a separate ticket. |
"spanning lines" seems like a reasonable label.
defaulting to this behavior also seems reasonable. the user just needs to use "[^\n]" instead of ".". |
I submitted a fix as ticket #4395, but I probably should have added a comment here and uploaded the bugfix by attaching the diff file here. |
|
Replying to sxmboer2:
A tests in tests/lib/search are highly desirable for this patch. |
Test suite was a good idea, but it took me a significant amount of time to figure out how to use the unit test system. The added source code includes tests that are somewhat specific to this ticket. |
Adding a test suite for lib/search |
Cool. Thanks!
Branch: 400_multiline_search |
|
|
Multi-line search has some bugs. See #4429 for details. |
Important
This issue was migrated from Trac:
Hubbitus
(@Hubbitus)So, as I known, now search made line by line, and no chance match/replace pattern like "Some text\n+Another text".
This possibilities is highly appreciated.
Note
Original attachments:
mooffie
(@mooffie) onDec 7, 2016 at 21:16 UTC
mooffie
(@mooffie) onDec 7, 2016 at 21:17 UTC
mooffie
(@mooffie) onDec 7, 2016 at 21:17 UTC
sxmboer2
(sxmboer@….com) onJul 29, 2022 at 2:33 UTC
sxmboer
(sxmboer@….net) onAug 7, 2022 at 2:20 UTC
The text was updated successfully, but these errors were encountered: