<?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[Is this possible, suffix text based on a list.]]></title><description><![CDATA[<p dir="auto">I’m new to Notepad++ and I’m wondering if this task is possible with a pluggin or a macro etc.</p>
<p dir="auto">I’d like to open a file and within the file there would be specific code/groups of text such as G21 as an example. What I would like to do is within the file after the text is suffix with another piece of text based on a list i would populate within either the pluggin or macro.</p>
<p dir="auto">An example of this would be</p>
<p dir="auto">Initial lines of code</p>
<p dir="auto">G90<br />
G21 G40 G80</p>
<p dir="auto">After a scan and inserted additional text it would read like this.</p>
<p dir="auto">G90 ;Absolute programming<br />
G21 ;Programming in millimeters (mm)	 G40 ;Tool radius compensation off G80 ;Cancel canned cycle</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/22028/is-this-possible-suffix-text-based-on-a-list</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Jul 2026 08:25:11 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/22028.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 21 Oct 2021 18:54:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Is this possible, suffix text based on a list. on Thu, 21 Oct 2021 23:12:09 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">That’s run through great now, thank you. :)</p>
<p dir="auto"><img src="/assets/uploads/files/1634857912111-capture2.jpg" alt="Capture2.JPG" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/70786</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/70786</guid><dc:creator><![CDATA[Mark Littlefair]]></dc:creator><pubDate>Thu, 21 Oct 2021 23:12:09 GMT</pubDate></item><item><title><![CDATA[Reply to Is this possible, suffix text based on a list. on Thu, 21 Oct 2021 23:03:02 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a></p>
<p dir="auto">Thank you Guy, this is the problem with your method though if I’m limited in the replacement zone to 2048 characters</p>
<p dir="auto"><img src="/assets/uploads/files/1634857324217-capture2.jpg" alt="Capture2.JPG" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/70785</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/70785</guid><dc:creator><![CDATA[Mark Littlefair]]></dc:creator><pubDate>Thu, 21 Oct 2021 23:03:02 GMT</pubDate></item><item><title><![CDATA[Reply to Is this possible, suffix text based on a list. on Thu, 21 Oct 2021 23:06:39 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-littlefair" aria-label="Profile: mark-littlefair">@<bdi>mark-littlefair</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: peterjones">@<bdi>peterjones</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">Given your <strong>new</strong> conditions about the <strong>ouptut</strong> text, the regex S/R, provided in my <strong>last</strong> post, becomes :</p>
<p dir="auto">SEARCH <strong><code>(G90)|(G21)|(G40)|(G80)</code></strong></p>
<p dir="auto">REPLACE <strong><code>$0 \((?1Absolute programming)(?2Programming in millimeters \(mm\))(?3Tool radius compensation off)(?4Cancel canned cycle)\)</code></strong></p>
<p dir="auto">BR</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/70784</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/70784</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Thu, 21 Oct 2021 23:06:39 GMT</pubDate></item><item><title><![CDATA[Reply to Is this possible, suffix text based on a list. on Thu, 21 Oct 2021 22:40:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-littlefair" aria-label="Profile: Mark-Littlefair">@<bdi>Mark-Littlefair</bdi></a> ,</p>
<p dir="auto">It’s probably failing because in the replacement, parentheses are a special character, so to get a literal paren wrapped around the replacement, you will need to use the \( and \) … so to replicate the final line on the left in your screenshot, you would want</p>
<pre><code class="language-py">    editor.rereplace(search_re, '$0 \({}\)'.format(suffix))
</code></pre>
<p dir="auto">… yes, with that line in the script, the output for your original example input yielded:</p>
<pre><code>G90 (Absolute programming)
G21 (Programming in millimeters (mm)) G40 (Tool radius compensation off) G80 (Cancel canned cycle)
</code></pre>
<p dir="auto">The PythonScript plugin uses the boost regex engine (the same that Notepad++ uses) for the <code>editor.research()</code> calls, so the substitution follows all the same rules as for Notepad++ replacements, as described <a href="https://npp-user-manual.org/docs/searching/#substitutions" rel="nofollow ugc">here</a></p>
]]></description><link>https://community.notepad-plus-plus.org/post/70782</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/70782</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 21 Oct 2021 22:40:48 GMT</pubDate></item><item><title><![CDATA[Reply to Is this possible, suffix text based on a list. on Thu, 21 Oct 2021 22:26:04 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">Sorry to be a pain Peter,</p>
<p dir="auto">My mistake the semi colon should be open bracket then the text suffix then close bracket</p>
<p dir="auto">I’ve tried to edit the code where i thought it should work and failed.</p>
<p dir="auto"><img src="/assets/uploads/files/1634855040532-capture.jpg" alt="Capture.JPG" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/70781</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/70781</guid><dc:creator><![CDATA[Mark Littlefair]]></dc:creator><pubDate>Thu, 21 Oct 2021 22:26:04 GMT</pubDate></item><item><title><![CDATA[Reply to Is this possible, suffix text based on a list. on Thu, 21 Oct 2021 19:58:33 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">all good</p>
<p dir="auto"><img src="/assets/uploads/files/1634846298325-capture.jpg" alt="Capture.JPG" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/70775</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/70775</guid><dc:creator><![CDATA[Mark Littlefair]]></dc:creator><pubDate>Thu, 21 Oct 2021 19:58:33 GMT</pubDate></item><item><title><![CDATA[Reply to Is this possible, suffix text based on a list. on Thu, 21 Oct 2021 19:58:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-littlefair" aria-label="Profile: Mark-Littlefair">@<bdi>Mark-Littlefair</bdi></a> ,</p>
<p dir="auto">Your screenshot didn’t show line 59 of <code>addSuffixes.py</code>, but that’s where the error lies.</p>
<p dir="auto">If you really have the same input as mine, line 59 was the last line of the file, beyond <code>editor.endUndoAction()</code> … if so, just make sure there are no characters on the last line of the file (make it an empty line, without any spaces).</p>
<p dir="auto">Looking at the error message, you appear to have an <code>l</code> or a <code>1</code> or something at the end of the file, which may or may not be indented.  There shouldn’t be.</p>
<p dir="auto"><img src="/assets/uploads/files/1634846288911-f5c20e96-27d0-4f02-9e03-2002113fa36a-image.png" alt="f5c20e96-27d0-4f02-9e03-2002113fa36a-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/70774</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/70774</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 21 Oct 2021 19:58:17 GMT</pubDate></item><item><title><![CDATA[Reply to Is this possible, suffix text based on a list. on Thu, 21 Oct 2021 19:56:53 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">Sorry I’ve just seen it myself now, not sure how that 1 got in there sorry again :)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/70773</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/70773</guid><dc:creator><![CDATA[Mark Littlefair]]></dc:creator><pubDate>Thu, 21 Oct 2021 19:56:53 GMT</pubDate></item><item><title><![CDATA[Reply to Is this possible, suffix text based on a list. on Thu, 21 Oct 2021 19:54:20 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><br />
1,2 and 3 all ok</p>
<p dir="auto">Here is the screenshot.</p>
<p dir="auto"><img src="/assets/uploads/files/1634846055352-capture.jpg" alt="Capture.JPG" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/70772</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/70772</guid><dc:creator><![CDATA[Mark Littlefair]]></dc:creator><pubDate>Thu, 21 Oct 2021 19:54:20 GMT</pubDate></item><item><title><![CDATA[Reply to Is this possible, suffix text based on a list. on Thu, 21 Oct 2021 19:52:56 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> said in <a href="/post/70770">Is this possible, suffix text based on a list.</a>:</p>
<blockquote>
<p dir="auto">I’ll fix that in a future post.</p>
</blockquote>
<p dir="auto">The easiest fix is to always use \( and \) for parentheses in the suffixes map</p>
<pre><code>    'G21': "Programming in millimeters \(mm\)",
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/70771</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/70771</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 21 Oct 2021 19:52:56 GMT</pubDate></item><item><title><![CDATA[Reply to Is this possible, suffix text based on a list. on Thu, 21 Oct 2021 19:49:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-littlefair" aria-label="Profile: Mark-Littlefair">@<bdi>Mark-Littlefair</bdi></a> ,</p>
<blockquote>
<p dir="auto">It hasn’t worked Peter, is this likely because the file is a .nc file rather than a .txt file ?</p>
</blockquote>
<p dir="auto">If it failed, then it has nothing to do with the extension of the file.  Unless the script specifically calls out certain extensions (this script didn’t), a PythonScript script will act the same regardless of file extension.</p>
<p dir="auto">I created a file that had the two lines from your example,</p>
<pre><code>G90
G21 G40 G80
</code></pre>
<p dir="auto">and after running the script, I get:</p>
<pre><code>G90 ;Absolute programming
G21 ;Programming in millimeters mm G40 ;Tool radius compensation off G80 ;Cancel canned cycle
</code></pre>
<p dir="auto">I did just notice a bug – the parentheses around <code>(mm)</code> in the replacement were lost… I’ll fix that in a future post.</p>
<p dir="auto">But in general, the script works for me.</p>
<p dir="auto">Debugging steps:</p>
<ol>
<li>Does the menu entry <strong>Plugins &gt; Python Script</strong> exist?  If no, then revisit the INSTRUCTIONS</li>
<li>Does the menu entry <strong>Plugins &gt; Python Script &gt; Scripts &gt; addSuffixes</strong> exist?  If no, then revisit the INSTRUCTIONS</li>
<li>Try running <strong>Plugins &gt; Python Script &gt; Show Console</strong>.  Does a new console window show up in Notepad++?</li>
<li>Select the .nc file and then run <strong>Plugins &gt; Python Script &gt; Scripts &gt; addSuffixes</strong> .  If there is any output in the Python Script console, copy/paste or screenshot it and include it in your reply</li>
</ol>
<p dir="auto">BTW: <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a>’s regex solution will also work for a small number of replacements, like in your example.<br />
But it will get unwieldy if you have 10 or more suffix replacements to do, whereas this script should handle any number of search/suffix pairs you want to throw at it.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/70770</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/70770</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 21 Oct 2021 19:49:05 GMT</pubDate></item><item><title><![CDATA[Reply to Is this possible, suffix text based on a list. on Thu, 21 Oct 2021 23:09:46 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-littlefair" aria-label="Profile: mark-littlefair">@<bdi>mark-littlefair</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: peterjones">@<bdi>peterjones</bdi></a> and All,</p>
<p dir="auto">Of course, the <strong>Peter</strong>’s method, with a <strong>script</strong> language, is very powerful and <strong>universal</strong> !</p>
<p dir="auto">However, if your <strong>number</strong> of spotted items is not <strong>important</strong>, a simple <strong>regex</strong> S/R could be enough !</p>
<p dir="auto">In your case, the regex S/R would be :</p>
<p dir="auto">SEARCH <strong><code>(G90)|(G21)|(G40)|(G80)</code></strong></p>
<p dir="auto">REPLACE <strong><code>$0 ;(?1Absolute programming)(?2Programming in millimeters \(mm\))(?3Tool radius compensation off)(?4Cancel canned cycle)</code></strong></p>
<hr />
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">The <strong>logic</strong> of this regex S/R is almost obvious !</p>
</li>
<li>
<p dir="auto">In <strong>search</strong>, it looks for, either, each <strong><code>Gxx</code></strong> item described</p>
</li>
<li>
<p dir="auto">In <strong>replacement</strong>, the <strong><code>$0</code></strong> syntax represents the <strong>current</strong> search value ( <strong><code>Gxx</code></strong> ) which is rewritten, followed with a <strong>space</strong> char and a <strong>semicolon</strong></p>
</li>
<li>
<p dir="auto">Then, depending on the <strong><code>Gxx</code></strong> matched ( group <strong><code>1</code></strong> to <strong><code>4</code></strong> ), the corresponding <strong>comment</strong> part is just <strong>added</strong></p>
</li>
<li>
<p dir="auto">Note that the parentheses around <strong>mm</strong> must be <strong>escaped</strong> as they have a <strong>special</strong> meaning in <strong>replacement</strong></p>
</li>
<li>
<p dir="auto"><em>IMPORTANT</em> : Do not exceed <strong><code>2,048</code></strong> characters in the <strong>replacement</strong> zone !</p>
</li>
</ul>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/70769</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/70769</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Thu, 21 Oct 2021 23:09:46 GMT</pubDate></item><item><title><![CDATA[Reply to Is this possible, suffix text based on a list. on Thu, 21 Oct 2021 19:38:13 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">It hasn’t worked Peter, is this likely because the file is a .nc file rather than a .txt file ?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/70767</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/70767</guid><dc:creator><![CDATA[Mark Littlefair]]></dc:creator><pubDate>Thu, 21 Oct 2021 19:38:13 GMT</pubDate></item><item><title><![CDATA[Reply to Is this possible, suffix text based on a list. on Thu, 21 Oct 2021 19:24:02 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">Thank you for the quick reply, I will give this a try now.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/70766</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/70766</guid><dc:creator><![CDATA[Mark Littlefair]]></dc:creator><pubDate>Thu, 21 Oct 2021 19:24:02 GMT</pubDate></item><item><title><![CDATA[Reply to Is this possible, suffix text based on a list. on Thu, 21 Oct 2021 19:23:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-littlefair" aria-label="Profile: Mark-Littlefair">@<bdi>Mark-Littlefair</bdi></a> ,</p>
<p dir="auto">Natively to Notepad++, no.  And I don’t know of any plugin that has that specific feature.</p>
<p dir="auto">However, the PythonScript plugin (and other scripting plugins) allow you to use a common scripting language to write scripts to manipulate Notepad++ and the contents of the open files.</p>
<p dir="auto">For example, the following should do what you want.  The installation instructions are found in the black box of text.</p>
<h4><a href="http://addSuffixes.py" rel="nofollow ugc">addSuffixes.py</a></h4>
<pre><code class="language-py"># encoding=utf-8
"""https://community.notepad-plus-plus.org/topic/22028/is-this-possible-suffix-text-based-on-a-list

Enter your list of suffixes here:
"""

suffixes = {
    # your search string and suffix go here, using the same format as these examples, including colons and commas
    'G90': "Absolute programming",
    'G21': "Programming in millimeters (mm)",
    'G40': "Tool radius compensation off",
    'G80': "Cancel canned cycle",

    # leave this one alone
    None: None
}

"""
INSTRUCTIONS:
1. Install PythonScript Plugin
   * Plugins &gt; Plugins Admin
   * Click ☑ PythonScript checkbox until checked
   * click INSTALL
   * restart Notepad++ as necessary
2. Create new PythonScript script
   * Plugins &gt; PythonScript &gt; New Script
   * Give it a reasonable name, like addSuffixes.py
   * Paste in all the code from this black box
   * Save
3. Switch to the document where you want to search/replace
4. Plugins &gt; PythonScript &gt; Scripts &gt; addSuffixes

To assign a keyboard shortcut:
1. Plugins &gt; PythonScript &gt; Configuration
2. In the User Scripts, click on addSuffixes.py
3. Click the left ADD button (above Menu Items)
    * This adds "addSuffixes" to the main Plugins &gt; PythonScript menu, rather
      than requiring you to dig down into the Scripts submenu
4. Exit Notepad++ and restart
    * This is required for ShortcutMapper to be able to see the new entry
      in the PythonScript menu
5. Settings &gt; ShortcutMapper &gt; Plugin Commands
6. Filter by addSuffixes
7. Click on addSuffixes, then click the MODIFY button and
    set the keyboard shortcut in the dialog
"""


from Npp import *

editor.beginUndoAction()

for search,suffix in suffixes.items():
    if search is None: continue
    search_re = r'\b\Q' + str(search) + r'\E\b'
    editor.rereplace(search_re, '$0 ;{}'.format(suffix))

editor.endUndoAction()
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/70765</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/70765</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 21 Oct 2021 19:23:24 GMT</pubDate></item></channel></rss>