[New Plugin] MultiReplace
-
RC-4 has been finished, featuring:
- New Find and Replace functionality in 2Buttons Mode.
- Sort lists by clicking on the header.
Several optimizations and fixes, including:
- Update of INI Unicode support.
- Updates of Codepage assignments.
- Clipboard copy performance optimization.
- and a lot of other adjustments
Feel free to test it! You can find it on Github.
-
@Thomas-Knoefel said in [New Plugin] MultiReplace:
After marking all strings, the plugin should detect any changes.
Pretty sure the way to check if a file has been modified is to subscribed to the
SCN_MODIFIED
notification and check if thetext
field of the notification object has been populated (since the notification can fire if there are changes other than text changes).But of course your plugin changes the text itself, and so you need some way to distinguish from your plugin’s changes… Hmm…
-
Actually, there’s an even easier way that I just remembered to determine if a
SCN_MODIFIED
notification entails text changing:
check if(notification.modificationType & 3) != 0
This works because
3 = SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT
, and all text modifications trigger a notification with one of those flags set. -
@Mark-Olson said in [New Plugin] MultiReplace:
But of course your plugin changes the text itself, and so you need some way to distinguish from your plugin’s changes… Hmm…
Indeed, this can quickly turn into a complex issue. That’s why I’ve added a regular Find feature, which wasn’t originally planned but serves the same purpose I intended to implement. The advantage here is that it’s easier to maintain and isn’t solely limited to locating positions within Marked Strings. Sometimes, exploring alternative approaches proves to be simpler… thanks for your support; this will answer the questions I was looking for!
-
A tiny thing that confuses me with each update of the plugin: it’s physical name is “NppMultiReplace.dll” and, correspondingly, its folder name is “NppMultiReplace”, and in the same time the plugin identifies itself as “MultiReplace” (without “Npp”) in the main menu.
Maybe the same name in both places would be better? -
@Vitalii-Dovgan said in [New Plugin] MultiReplace:
Maybe the same name in both places would be better?
Agree. Drop the “Npp” - it’s obvious the plugin is for Notepad++. You can name the repo “npp…” if you like, but the plugin DLL itself (and thus folder) should drop the “Npp” prefix.
Cheers.
-
Leading off a plugin name with
Npp
is a sure way to cause it to get visually lost to someone looking for it in the PluginsAdmin list: “Damn, I know it is calledMultiReplace
, how come I can’t find it? Oh, it’s because it is in theN
’s because the dubious decision was made to putNpp
on the front of its name…” -
@Vitalii-Dovgan said in [New Plugin] MultiReplace:
Maybe the same name in both places would be better?
Good point, consistency matters. I’ve renamed project and files to ‘MultiReplace’ and dropped the ‘Npp’ prefix. Changes are in the new RC5 build.
-
@Thomas-Knoefel said in [New Plugin] MultiReplace:
@Vitalii-Dovgan said in [New Plugin] MultiReplace:
Maybe the same name in both places would be better?
Good point, consistency matters. I’ve renamed project and files to ‘MultiReplace’ and dropped the ‘Npp’ prefix.
Excellent, this should be the standard way of naming all plugins: so they can be found alphabetically ordered into the Plugin Menu too.
Thank you. -
Excellent, this should be the standard way of naming all plugins: so they can be found alphabetically ordered into the Plugin Menu too.
The plugin’s file name does not determine the display name in the install menu; that comes from the
"display-name"
property in the JSON manifest embedded in the Plugins Admin DLL.For example, selecting “F# Interactive” installs a module named
NPPFSIPlugin.dll
— with a pointless “-Plugin” suffix as well as prefix!
-
@Thomas-Knoefel said in [New Plugin] MultiReplace:
Changes are in the new RC5 build.
I realize that this is ‘release candidate’ stuff but…
I would guess from the size of the DLL in the “assets” that this is a “debug” build; you probably want to change this to a “release” build (forever more in all your releases of this plugin).
Should also consider a 32-bit build for our N++ family friends that use that one.
-
@Alan-Kilborn said in [New Plugin] MultiReplace:
Should also consider a 32-bit build for our N++ family friends that use that one.
All versions will ultimately be made available as “release” builds when plugin reaches 1.0.0.0 . I have updated RC5 now with all release builds. For all commits, I have an Action preparing the builds in the Git repository, which can be download here as well for the latest RC . (Kudos to @Michael-Vincent for his support with this.)
-
This post is deleted! -
It seems that regex replace with capture group ($1) doesn’t work. Would love to have this feature.
-
This post is deleted! -
This post is deleted! -
I’ve recently completed the Scope Function for the MultiReplace plugin. It lets you set the area (or scope) for Find, Replace, and Marking. Here’s what’s new:
@tomisk: Fix for capturing groups is include in this Pre-Release. Thanks for pointing it out,
Selection Scope:
- Supports single, multi, and rectangular selections.
Column Scope:
- Use the Replace, Find, and Mark functions within distcinct columns of delimited files. Plus, there’s an added highlight feature for these columns.
- Just a note: The file remains editable, even when the plugin is importing a CSV structure.
Marking Performance:
From my observations, highlighting seems a bit slow in N++, especially when marking a large number of unique terms. Thus, I’ve modified the plugin to allow users to cancel the marking process if required.If you cancel and then make edits to unmarked columns, they’ll automatically get highlighted inplace, regardless of their position in the file.
However, highlighting columns isn’t necessary for any operations. It primarily aids in visualization. -
CSV Support has reached its final goal and will be released soon.
Planned Features
m looking at introducing more flexibility in replacements. To achieve this, I am considering introducing a checkbox feature named “Contextual Mode” which, when activated, will employ a set of external parameters for more sophisticated and context-aware replacements. Here’s what I have in mind:
External Parameters:
When “Contextual Mode” is enabled, the following set of external parameters can be utilized in conjunction with replacement strings to provide more context and flexibility:
Parameter Description $CNT Number of the string to be replaced. $LINE Line position of the string to be replaced. $APOS Absolute position. $LPOS Position in line. $COL Column position of the string to be replaced. (works only if CSV Scope is enabled) Examples:
Use Case 1: Simple Replacement with Numbering:
Find String Replace String Before After key
$CNT
key key key
1 2 3
Use Case 2: Regex Combination with External Parameters:
Find String Replace String Before After \d+(key)
$CNT$1
1key key 4key
1key key 2key
Use Case 3: Conditional Replacements:
Find String Replace String Before After key
$if(CNT = 1, "newString", "key")
key key key
newString key key
The conditions should be < > =, later I’m aiming to expand the condition features with AND and OR , allowing users to target sections in their code with more precision.
Simplicity is my focus because complex syntax can make things more challenging.
I’d love to hear your insights on this approach. Do you find it beneficial? Additionally, are there any elements or strategies I should consider adding?
-
Hello, @thomas-knoefel and All,
I do support your future
Contextual Mode
feature ! This would greatly enhance the N++Replace
function ;-))
Now, I’m thinking about about a replacement feature, which had been requested many times : the possibility to add
counters
in replacement )For instance the simple regex S/R :
FIND
[\d.]+
REPLACE
$0\t(Test $NUM)
would change this list :
12 5.3 0 7.8
into :
12 (Test 1) 5.3 (Test 2) 0 (Test 3) 7.8 (Test 4)
Of course, this new meta-data
$NUM
should probably support parameters to take the start number and the increment in account !Refer to the part Counters and Cycles of the following FAQ :
https://community.notepad-plus-plus.org/topic/23170/faq-desk-can-i-do-a-mathematical-replacement
To find out useful ideas about this problem. But, as you said : simplicity is my focus !
Note that the
$NUM
is slightly different from your external parameter$CNT
. Of course, @thomas-knoefel, my request is just a suggestion. Do as you like !Best Regards,
guy038
As a remainder, the following syntaxes are reserved, in the replacement zones, by the Notepad++'s Boost regular expression engine :
$0
,${0}
,$&
,$MATCH
,${^MATCH}
$
followed with a backtick ,$PREMATCH
,${^PREMATCH}
$'
,$POSTMATCH
,${^POSTMATCH}
$^N
,$LAST_SUBMATCH_RESULT
,${^LAST_SUBMATCH_RESULT}
$+
,$LAST_PAREN_MATCH
,${^LAST_PAREN_MATCH}
$$
\l
,\u
,\L
,\U
,\E
\n
( with1 <= n <= 9
) and$N
or${N}
( withN > 0
)$+{Name}
, whereName
is a named group(?N......)
and(?N......:......)
, whereN
represents the numbered groupN
(?{N}......)
and(?{N}......:......)
, whereN
represents the numbered groupN
(?{Name}......)
and(?{Name}......:......)
, whereName
represents the named groupN
-
@guy038,
@Thomas-Knoefel said in [New Plugin] MultiReplace:I’d love to hear your insights on this approach. Do you find it beneficial? Additionally, are there any elements or strategies I should consider adding?
It looks like you and I are approaching related targets from different directions. I’m working on a plugin, Columns++, with the primary focus being documents with data arranged visually in columns. I introduced the notion of formulas for creating new columns based on calculations from existing columns. There is also a search-and-replace feature that works with rectangular selections.
In my last update, I extended the replace capability when using regular expressions to include formula substitutions of the form (?=formula) or (?=format:formula). Details are in the Formulas section of the documentation.
A simple example would be:
Find what:(?<=\bID)\d+\b
Replace with:(?=this+120)
to find all cases of “ID” followed by one or more digits, delimited by word boundaries, and add 120 to the number.I didn’t aim for simplicity, though. I gave up on that early (while I was still implementing column calculations) and decided instead to find a free and open source library of some sort that would avoid having to write my own expression parser. I chose ExprTk; so far, it is working well.