<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[working use-case for SCI_REPLACETARGETRE]]></title><description><![CDATA[<p dir="auto">Trying to fix my “<a href="https://metacpan.org/pod/Win32::Mechanize::NotepadPlusPlus" rel="nofollow ugc">PerlScript</a>” implementation of <code>editor-&gt;replaceTargetRE</code>, and trying to use a PythonScript as proof of concept.</p>
<p dir="auto">I started with <a href="https://community.notepad-plus-plus.org/topic/11804/">https://community.notepad-plus-plus.org/topic/11804/</a>, and added prints and sleeps (so I can see what’s going on… not because the script needed delay), but it seems to be replacing the <em>whole</em> text with <code>great</code> instead of just replacing the <code>beautiful</code></p>
<pre><code># encoding=utf-8
"""
https://community.notepad-plus-plus.org/topic/11804/ with LuaScript/PythonScript
"""
from Npp import *
from time import sleep

console.show()
console.clear()

notepad.new()
editor.setText("""This is a not selected line !!!
This is line one !!!
Today is a beautiful day !!!
This is line three !!!
This is a not selected line !!!
""")

editor.setTargetRange(32,105)           # use hardcoded range instead of editor.targetFromSelection
console.write("-----\n"+editor.getTargetText()+"=====\n")   # added for debug
console.write("target=({},{})\n".format(editor.getTargetStart(),editor.getTargetEnd()))
if False:
    editor.replaceTarget("HAHAHA!\r\n")
    console.write("laughing target=({},{})\n".format(editor.getTargetStart(),editor.getTargetEnd()))
elif True:
    editor.searchInTarget(r'beautiful')
    console.write("beautiful target=({},{})\n".format(editor.getTargetStart(),editor.getTargetEnd()))
    sleep(1)
    editor.replaceTargetRE('great')
    console.write("great target=({},{})\n".format(editor.getTargetStart(),editor.getTargetEnd()))
    sleep(1)

console.write("final target=({},{})\n".format(editor.getTargetStart(),editor.getTargetEnd()))
console.write("-----\n"+editor.getTargetText()+"=====\n")   # added for debug

# pretend that nothing has changed, and close the file without saving
sleep(5)
editor.setSavePoint()
notepad.close()
</code></pre>
<p dir="auto">And the console output contains:</p>
<pre><code>-----
This is line one !!!
Today is a beautiful day !!!
This is line three !!!
=====
target=(32,105)
beautiful target=(64,137)
great target=(0,5)
final target=(0,5)
-----
great=====
</code></pre>
<p dir="auto">The first <code>getTargetText</code> results between <code>----</code> and <code>=====</code> are what I expect.  But I would have thought that the “great target” would have been about the same size as the “beautiful target” (maybe a few chars shorter because <code>length(great)=5</code> &lt; <code>length(beautiful)=9</code>.  Instead, it drops to a length of 5, and the whole final text is <code>great</code> without any newlines and without any of the original text.</p>
<p dir="auto">So now I have what looks like a bug or misunderstanding in the PythonScript, let alone being able to debug my source code for PerlScript.  :-(</p>
<p dir="auto">Debug Info:</p>
<pre><code>Notepad++ v7.8.5   (64-bit)
Build time : Mar  3 2020 - 17:39:56
Path : C:\usr\local\apps\notepad++\notepad++.exe
Admin mode : OFF
Local Conf mode : ON
OS Name : Windows 10 Enterprise (64-bit) 
OS Version : 1903
OS Build : 18362.720
Plugins : ComparePlugin.dll LuaScript.dll MarkdownViewerPlusPlus.dll mimeTools.dll NppConsole.dll NppConverter.dll NppEditorConfig.dll NppExec.dll NppExport.dll NppFTP.dll PreviewHTML.dll PythonScript.dll QuickText.dll XMLTools.dll 
</code></pre>
<p dir="auto">with PythonScript v1.5.2</p>
<p dir="auto">Can anyone confirm that my script does the same for them?</p>
<p dir="auto">And any suggestions for a example of a working <code>editor.replaceTargetRE()</code> example sequence?</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/19217/working-use-case-for-sci_replacetargetre</link><generator>RSS for Node</generator><lastBuildDate>Wed, 10 Jun 2026 02:35:22 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/19217.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 13 Apr 2020 20:18:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to working use-case for SCI_REPLACETARGETRE on Tue, 14 Apr 2020 20:55:52 GMT]]></title><description><![CDATA[<p dir="auto">Disclaimer: I did not fully read every single line of this thread…but hopefully I can contribute a bit of helpful info.</p>
<p dir="auto">Accessing Scintilla on a background thread can be very problematic. There are Scintilla calls that have <a href="https://enterprisecraftsmanship.com/posts/temporal-coupling-and-immutability/" rel="nofollow ugc">temporal coupling</a> and since you cannot guarantee any two calls made from PythonScript (or outside of Notepad++) are executed without being interrupted by another thread, then weird things can happen. Even doing something simple like:</p>
<pre><code>editor.setTargetRange(0, 100)
x = editor.getTargetText()
</code></pre>
<p dir="auto">could potentially give unexpected results. Notepad++ does its own work (search/replace, function list, auto completion, smart highlighting, URL highlighting, etc) which changes the target quite frequently.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52601</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52601</guid><dc:creator><![CDATA[dail]]></dc:creator><pubDate>Tue, 14 Apr 2020 20:55:52 GMT</pubDate></item><item><title><![CDATA[Reply to working use-case for SCI_REPLACETARGETRE on Tue, 14 Apr 2020 14:52:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> said in <a href="/post/52583">working use-case for SCI_REPLACETARGETRE</a>:</p>
<blockquote>
<p dir="auto">if it is called from the main thread or better the thread<br />
which created the scintilla window.</p>
</blockquote>
<p dir="auto">PerlScript is an outside-looking-in application, unlike most plugin development (which starts inside).  So I won’t have that, which will make it more important for me to warn users (here and elsewhere, really) that Notepad++ is still running, and could still be influencing things separately from PerlScript.</p>
<p dir="auto">When I get to v2, with a full plugin that uses my perl module from the inside of Notepad++, I might have better control of such things.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52585</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52585</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Tue, 14 Apr 2020 14:52:10 GMT</pubDate></item><item><title><![CDATA[Reply to working use-case for SCI_REPLACETARGETRE on Tue, 14 Apr 2020 14:37:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> said in <a href="/post/52577">working use-case for SCI_REPLACETARGETRE</a>:</p>
<blockquote>
<p dir="auto">isn’t any use of target-related functions problematic</p>
</blockquote>
<p dir="auto">I would say no, if it is called from the main thread or better the thread<br />
which created the scintilla window.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52583</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52583</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Tue, 14 Apr 2020 14:37:42 GMT</pubDate></item><item><title><![CDATA[Reply to working use-case for SCI_REPLACETARGETRE on Tue, 14 Apr 2020 14:34:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> said in <a href="/post/52577">working use-case for SCI_REPLACETARGETRE</a>:</p>
<blockquote>
<p dir="auto">isn’t any use of target-related functions going to be potentially problematic</p>
</blockquote>
<p dir="auto">Probably true.  I think I will add a caveat to the “target” documentation that explains that Notepad++ might interfere with the Scintilla targets, and suggest they code defensively when using targets.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52581</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52581</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Tue, 14 Apr 2020 14:34:08 GMT</pubDate></item><item><title><![CDATA[Reply to working use-case for SCI_REPLACETARGETRE on Tue, 14 Apr 2020 14:20:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a></p>
<p dir="auto">Since, as <a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> pointed out, Notepad++ itself uses the “target” concept, and apparently(?) there can only be one of these that Scintilla knows about, isn’t any use of target-related functions (be it in Pythonscript or your Perl-based thing) going to be potentially problematic when a user tries to use it?</p>
<p dir="auto">I know you are just trying to get thru implementing/testing/documenting of the function under discussion, but…</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52577</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52577</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Tue, 14 Apr 2020 14:20:38 GMT</pubDate></item><item><title><![CDATA[Reply to working use-case for SCI_REPLACETARGETRE on Thu, 12 Feb 2026 18:44:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> said in <a href="/post/52571">working use-case for SCI_REPLACETARGETRE</a>:</p>
<blockquote>
<p dir="auto">sorry for kinda high jacking your thread.</p>
</blockquote>
<p dir="auto">Not a problem.</p>
<p dir="auto">Ran some more experiments this morning: I upgraded from PythonScript 1.5.2 to 1.5.3 (didn’t really change the behavior, but I thought it was worth mentioning).  I played around with a sleep between when I generate the initial text and when I do the setSearchFlags – either before or after the setTargetRange.</p>
<p dir="auto">If I have <em>no</em> sleep, then I get unrepeatable results, where sometimes the final getText is only <code>great</code>, and sometimes it’s the whole paragraph, with <code>great</code> rather than <code>beautiful</code> (as I expect).  If I put a small sleep (whether before or after setTargetRange), the final getText is much more reliable.  If I use 10ms (ie, <code>sleep(0.01)</code>), it was at least 10/10 reliable; if I drop to 1ms, it seemed better than 50% reliable, but it wasn’t <em>every</em> run; if I have no wait, getText shows just <code>great</code> many/most runs.</p>
<p dir="auto">I cleaned out some of the debug stuff, and added a loop with a counter for how many runs it got right, and tried a few different delays:</p>
<pre><code class="language-py"># encoding=utf-8
""" https://community.notepad-plus-plus.org/topic/19217/working-use-case-for-sci_replacetargetre

I am working on implementing editor.replaceTargetRE in Win32::Mechanize::NotepadPlusPlus::Editor,
but it's currently not working.

Found https://community.notepad-plus-plus.org/topic/11804/ with LuaScript/PythonScript examples that _should_ work
"""
from Npp import *
from time import sleep

console.show()
#console.clear()

tWait = 0.005
N = 100
right = 0
srctxt = """This is a not selected line !!!
This is line one !!!
Today is a beautiful day !!!
This is line three !!!
This is a not selected line !!!
"""
cmptxt = """This is a not selected line !!!
This is line one !!!
Today is a great day !!!
This is line three !!!
This is a not selected line !!!
"""

for x in range(N):
    notepad.new()
    editor.setText(srctxt)
    sleep(tWait)

    editor.setTargetRange(32,105)

    editor.setSearchFlags(FINDOPTION.REGEXP)
    editor.searchInTarget(r'beautiful')

    editor.replaceTargetRE('great')

    if editor.getText() == cmptxt:
        right = right + 1

    editor.setSavePoint()
    notepad.close()

console.write("Final Score: tWait={} gave {}/{} right!\n".format(tWait,right,N))
</code></pre>
<p dir="auto">which gives, on my various runs:</p>
<pre><code class="language-txt">Final Score: tWait=0.001 gave 30/100 right!
Final Score: tWait=0.01 gave 100/100 right!
Final Score: tWait=0.002 gave 67/100 right!
Final Score: tWait=0.003 gave 95/100 right!
Final Score: tWait=0.004 gave 99/100 right!
Final Score: tWait=0.005 gave 100/100 right!
Final Score: tWait=0.005 gave 99/100 right!
</code></pre>
<p dir="auto">So, somewhere between 5-10ms, it reliably replaces just the expected text, rather than the whole file.  At least for me, with PythonScript v1.5.3 (in 64bit Notepad++ v7.8.5), on the machine I’m currently using.  Smaller than that, it appears there’s a race condition, where Scintilla gets ahead of itself (tries to do the search before it’s finished writing its buffer?).  Given that most of my professional programming involves programming electronics to generate and measure voltages and other signals, I am so used to adding delays in my software to avoid non-deterministic delays on the order of 1-10ms, it seems rather natural to me to add delays to my code – but I can see why someone who doesn’t come from the world of programming physical devices might balk at adding delays to code.</p>
<p dir="auto">Also, given that the <a href="https://community.notepad-plus-plus.org/topic/11804/">topic from 2016</a> had to do with oddities in the final Target location after the replacement, I am not going to worry about that.  I think this sequence of setText, wait, setTarget, setSearchFlag, searchInTarget, replaceTargetRE seems reliable enough now in PythonScript that I can use it to help debug my PerlScript version.</p>
<p dir="auto">Thanks for the hints, confirmations, and experiments.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52575</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52575</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 12 Feb 2026 18:44:37 GMT</pubDate></item><item><title><![CDATA[Reply to working use-case for SCI_REPLACETARGETRE on Tue, 14 Apr 2020 13:15:50 GMT]]></title><description><![CDATA[<p dir="auto">The biggest and in my opinion the only advantage of threads is that<br />
Npp itself can’t be disturbed by PS.<br />
Even if someone has programmed an endless loop, npp should,<br />
most of the time, still be able to terminate itself cleanly.<br />
The disadvantage of threads can be seen in this problem.<br />
There is the possibility that 2 or more threads work on the same thing<br />
and cause problems. Scintilla, to my knowledge, is not thread-safe.</p>
<p dir="auto">PySnack does more or less the same thing as PythonScript.<br />
Except for the obvious, i.e. using Python3 and Cython.<br />
Boost::Regex is, unfortunately, also implemented a bit differently - but I’m not 100% sure if I keep it that way.</p>
<p dir="auto">At first, threading has nothing to do with the notifications but on the<br />
second view it does if we look at the asynchronous callbacks from PS.<br />
Actually, it works like this.</p>
<p dir="auto">Npp has a NotificationHandler that is called from Scintlla.<br />
Any plugin can register via the beNotified Callback function,<br />
methods which are called then.</p>
<p dir="auto">This normally runs synchronously.</p>
<p dir="auto">But if I now know that I need longer to calculate something,<br />
then my plugin, kindly give this task to a separate thread and<br />
thus return control to Npp more quickly, so nothing is blocked.<br />
But now this thread should not make any changes to scintilla but<br />
inform the actual main thread, that something has to be done.<br />
So this is the theory - sometimes easier, mostly more difficult to implement.</p>
<p dir="auto">What is worse or better with PySnack is like with art in the eye of the beholder.<br />
I think that, at the moment, almost everything that PS has, PySnack can do too and a little bit more.<br />
But to be honest, it is always easier to create something new from an<br />
existing source then to invent it intially.<br />
So without PS there would never have been the idea to develop PySnack.</p>
<blockquote>
<p dir="auto">BTW, unfortunate that both plugins could be abbreviated as “P.S.”. :-(</p>
</blockquote>
<p dir="auto">Maybe not that bad at all, - switching over could be easier :-)<br />
One of the goals of PySnack is to be able to run the scripts of PS<br />
with almost no changes. Won’t be 100%, but I hope 99% are in.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> - sorry for kinda high jacking your thread.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52571</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52571</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Tue, 14 Apr 2020 13:15:50 GMT</pubDate></item><item><title><![CDATA[Reply to working use-case for SCI_REPLACETARGETRE on Tue, 14 Apr 2020 12:32:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> said in <a href="/post/52566">working use-case for SCI_REPLACETARGETRE</a>:</p>
<blockquote>
<p dir="auto">because npp itself changes the target for different purposes,</p>
</blockquote>
<p dir="auto">Methinks you are onto something here.</p>
<blockquote>
<p dir="auto">PS uses threads when executing scripts, which is not the case with PySnack</p>
</blockquote>
<p dir="auto">Is now the time/place to go into how PySnack is going to be <em>better</em> than PythonScript?  :-)<br />
A discussion of the different architectures?</p>
<p dir="auto">I mean, I presume “script” does things with threads because it needs to?  And you decided “snack” doesn’t need to?</p>
<p dir="auto">What’s better in “snack”?  What’s “worse”?</p>
<p dir="auto">How are things like NOTIFICATIONs and synchronous / asynchronous callbacks going to work with “snack”, without threading (maybe making it seem like I know more than I do here, hehehe, maybe one thing has nothing to do with the other).</p>
<p dir="auto">I’m definitely in favor of the KISS principle, where it works.</p>
<p dir="auto">Maybe a separate thread for this type of discussion, but maybe you are not even ready for that yet! :-)</p>
<p dir="auto">BTW, unfortunate that both plugins could be abbreviated as “P.S.”. :-(</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52568</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52568</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Tue, 14 Apr 2020 12:32:32 GMT</pubDate></item><item><title><![CDATA[Reply to working use-case for SCI_REPLACETARGETRE on Tue, 14 Apr 2020 12:21:24 GMT]]></title><description><![CDATA[<p dir="auto">I was using a clean 7.8.4 portable, disabled all Auto* features such as smart highlighting, auto-complete, etc. of npp and even disabled the 3 built-in plugins, and it happened anyway.</p>
<p dir="auto">Then I used PySnack and ran it ~100 times and it never happened.<br />
So I suppose the reason why PS has this problem is that PS uses threads when executing scripts, which is not the case with PySnack.<br />
And because npp itself changes the target for different purposes, I assume that there is a conflict while PS is still running.</p>
<blockquote>
<p dir="auto">It’s going to make it really difficult to see if I’ve implemented correctly in Perl.</p>
</blockquote>
<p dir="auto">Tell me about it. :-)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52566</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52566</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Tue, 14 Apr 2020 12:21:24 GMT</pubDate></item><item><title><![CDATA[Reply to working use-case for SCI_REPLACETARGETRE on Mon, 13 Apr 2020 22:56:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> said</p>
<blockquote>
<p dir="auto"><code>editor.setSearchFlags(FINDOPTION.REGEXP)</code></p>
</blockquote>
<p dir="auto">So when I add that line, and comment out the sleeps, it goes back and forth between your two output pairs.  If I add in the</p>
<pre><code>console.write(".....\n"+editor.getText()+":::::\n")
</code></pre>
<p dir="auto">after the final <code>getTargetText()</code>, it duplicates whatever was printed above.</p>
<h4>first</h4>
<pre><code class="language-z">-----
This is line one !!!
Today is a beautiful day !!!
This is line three !!!
=====
target=(32,105)
beautiful target=(64,73)
great target=(64,69)
final target=(64,69)
-----
This is a not selected line !!!
This is line one !!!
Today is a great day !!!
This is line three !!!
This is a not selected line !!!
=====
.....
This is a not selected line !!!
This is line one !!!
Today is a great day !!!
This is line three !!!
This is a not selected line !!!
:::::
</code></pre>
<h4>second</h4>
<pre><code class="language-z">-----
This is line one !!!
Today is a beautiful day !!!
This is line three !!!
=====
target=(32,105)
beautiful target=(64,73)
great target=(0,5)
final target=(0,5)
-----
great=====
.....
great:::::
</code></pre>
<p dir="auto">If I have the <code>sleep(1)</code> between <code>beautiful</code> and <code>great</code>, it always does the second.  But the first is closer to what I would expect (except that the final <code>getTargetText</code> should be <code>great</code>, not the full text)</p>
<p dir="auto">This is weird.</p>
<p dir="auto">It’s going to make it really difficult to see if I’ve implemented correctly in Perl. :-)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52549</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52549</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Mon, 13 Apr 2020 22:56:44 GMT</pubDate></item><item><title><![CDATA[Reply to working use-case for SCI_REPLACETARGETRE on Mon, 13 Apr 2020 22:33:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> said in <a href="/post/52547">working use-case for SCI_REPLACETARGETRE</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a><br />
Peter you are confusing me :-D</p>
</blockquote>
<p dir="auto">I’m confused.  For some reason, I thought the most recent had been another Alan reply, rather than two Eko’s in a row.  Sorry.</p>
<blockquote>
<p dir="auto">Too late for me - I go to bed :-)</p>
</blockquote>
<p dir="auto">Maybe I should to, but since the sun is still up and I haven’t had dinner yet, that’s probably not wise. ;-)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52548</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52548</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Mon, 13 Apr 2020 22:33:00 GMT</pubDate></item><item><title><![CDATA[Reply to working use-case for SCI_REPLACETARGETRE on Mon, 13 Apr 2020 21:42:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a></p>
<p dir="auto">Peter you are confusing me :-D</p>
<blockquote>
<p dir="auto">… as <code>you</code> showed …</p>
</blockquote>
<p dir="auto">but then</p>
<blockquote>
<p dir="auto">… to be what <code>@Ekopalypse</code> showed …</p>
</blockquote>
<blockquote>
<p dir="auto">I’ll try the explicit setSearchFlags later – hopefully in an hour or two – and report back results when I’ve had a chance.</p>
</blockquote>
<p dir="auto">Too late for me - I go to bed :-)</p>
<p dir="auto">A good night and stay safe and healthy to everyone</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52547</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52547</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Mon, 13 Apr 2020 21:42:23 GMT</pubDate></item><item><title><![CDATA[Reply to working use-case for SCI_REPLACETARGETRE on Mon, 13 Apr 2020 21:38:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> said in <a href="/post/52545">working use-case for SCI_REPLACETARGETRE</a>:</p>
<blockquote>
<p dir="auto">But the result is wrong anyway, isn’t it?<br />
So the expected result should be …<br />
Right?</p>
</blockquote>
<p dir="auto">I was about to say no, that I expected to see what <a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> showed, with the full text printed out the second time… but then I remembered I’m printing the target text, which should just be the <code>great</code>, as you showed.  I would expect the full <code>notepad.getText()</code> printout (not in my code, but it should have been) to be what <a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> showed.</p>
<p dir="auto">I’ll try the explicit <code>setSearchFlags</code> later – hopefully in an hour or two – and report back results when I’ve had a chance.  Thanks for the help.</p>
<p dir="auto">(Trying to implement/verify calls to methods I’ve never used can be difficult, because I don’t know whether it’s me or my software that’s misbehaving. :-) )</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52546</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52546</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Mon, 13 Apr 2020 21:38:15 GMT</pubDate></item><item><title><![CDATA[Reply to working use-case for SCI_REPLACETARGETRE on Mon, 13 Apr 2020 21:27:58 GMT]]></title><description><![CDATA[<p dir="auto">But the result is wrong anyway, isn’t it?<br />
From the documentation</p>
<p dir="auto">SCI_REPLACETARGETRE(position length, const char *text) → position</p>
<p dir="auto"><em>This replaces the target using regular expressions. If length is -1, text is a zero terminated string, otherwise length is the number of characters to use. The replacement string is formed from the text string with any sequences of \1 through \9 replaced by tagged matches from the most recent regular expression search. \0 is replaced with all the matched text from the most recent search.</em><br />
<em><strong>After replacement, the target range refers to the replacement text. The return value is the length of the replacement string.</strong></em></p>
<p dir="auto">So the expected result should be</p>
<pre><code class="language-z">-----
This is line one !!!
Today is a beautiful day !!!
This is line three !!!
=====
target=(32,105)
beautiful target=(64,73)
great target=(64,69)
final target=(64,69)
-----
great=====
</code></pre>
<p dir="auto">Right?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52545</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52545</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Mon, 13 Apr 2020 21:27:58 GMT</pubDate></item><item><title><![CDATA[Reply to working use-case for SCI_REPLACETARGETRE on Mon, 13 Apr 2020 21:17:14 GMT]]></title><description><![CDATA[<p dir="auto">Ok - I guess I got it.<br />
Running the script as provided, well I’ve commented the sleeps, I get this</p>
<pre><code class="language-z">-----
This is line one !!!
Today is a beautiful day !!!
This is line three !!!
=====
target=(32,105)
beautiful target=(64,137)
great target=(0,5)
final target=(0,5)
-----
great=====
</code></pre>
<p dir="auto">I didn’t expected but I thought I know where the issue is.<br />
setSearchFlags have not been set. So I did this</p>
<pre><code class="language-py">...
elif True:
    editor.setSearchFlags(FINDOPTION.REGEXP)
    editor.searchInTarget(r'beautiful')
    console.write("beautiful target=({},{})\n".format(editor.getTargetStart(),editor.getTargetEnd()))
    # sleep(1)
    editor.replaceTargetRE('great')
    console.write("great target=({},{})\n".format(editor.getTargetStart(),editor.getTargetEnd()))
    # sleep(1)
...
</code></pre>
<p dir="auto">and run the script which returned</p>
<pre><code class="language-z">-----
This is line one !!!
Today is a beautiful day !!!
This is line three !!!
=====
target=(32,105)
beautiful target=(0,137)
great target=(0,5)
final target=(0,5)
-----
great=====
</code></pre>
<p dir="auto">Was confused did something different and tried it again,<br />
same script no other modification, result</p>
<pre><code class="language-z">-----
This is line one !!!
Today is a beautiful day !!!
This is line three !!!
=====
target=(32,105)
beautiful target=(64,73)
great target=(64,133)
final target=(0,133)
-----
This is a not selected line !!!
This is line one !!!
Today is a great day !!!
This is line three !!!
This is a not selected line !!!
=====
</code></pre>
<p dir="auto">Not sure why this happens, but I’m more or less sure that<br />
in order to get the target search/replace done like one wants to have<br />
I would always set the search flags explicitly.</p>
<p dir="auto">Btw. this has been written by me - not by deepl<br />
I just gave it a try. :-)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52544</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52544</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Mon, 13 Apr 2020 21:17:14 GMT</pubDate></item><item><title><![CDATA[Reply to working use-case for SCI_REPLACETARGETRE on Mon, 13 Apr 2020 21:11:52 GMT]]></title><description><![CDATA[<p dir="auto">I get the same results each time, but with the <code>sleep</code> calls in there I get a weirdness:  My normally transparent Find window briefly goes non-transparent while the script runs.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52543</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52543</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 13 Apr 2020 21:11:52 GMT</pubDate></item><item><title><![CDATA[Reply to working use-case for SCI_REPLACETARGETRE on Mon, 13 Apr 2020 21:05:39 GMT]]></title><description><![CDATA[<p dir="auto">My result</p>
<pre><code class="language-z">-----
This is line one !!!
Today is a beautiful day !!!
This is line three !!!
=====
target=(32,105)
beautiful target=(64,73)
great target=(64,133)
final target=(0,133)
-----
This is a not selected line !!!
This is line one !!!
Today is a great day !!!
This is line three !!!
This is a not selected line !!!
=====
</code></pre>
<p dir="auto">but I had a different result the first time I did it. Hmm …</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52542</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52542</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Mon, 13 Apr 2020 21:05:39 GMT</pubDate></item><item><title><![CDATA[Reply to working use-case for SCI_REPLACETARGETRE on Mon, 13 Apr 2020 21:00:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a></p>
<p dir="auto">This is what your script outputs for me (slightly different than yours):</p>
<pre><code>-----
This is line one !!!
Today is a beautiful day !!!
This is line three !!!
=====
target=(32,105)
beautiful target=(64,73)
great target=(64,69)
final target=(64,69)
-----
great=====
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/52541</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52541</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 13 Apr 2020 21:00:47 GMT</pubDate></item></channel></rss>