<?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[Style token not saved]]></title><description><![CDATA[<p dir="auto">I am a newbie, so hope I am not wasting peoples time. I am using the Style token to ‘highlight’ some lines of code.   I save the file and when I reopen it, the highlighting  is gone.  I have also tried to ‘save session’ but the results are the same.</p>
<p dir="auto">Please advise if what I am asking for is possible, or the steps I should be doing to acomplish my goal.</p>
<p dir="auto">Thanks in advance for your time to reply.</p>
<p dir="auto">John R. in NC</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/18134/style-token-not-saved</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 10:38:33 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/18134.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 23 Aug 2019 16:33:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Style token not saved on Fri, 13 Sep 2024 21:45:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/3841">@PeterJones</a> thank u sir I got it</p>
]]></description><link>https://community.notepad-plus-plus.org/post/96612</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/96612</guid><dc:creator><![CDATA[Salep]]></dc:creator><pubDate>Fri, 13 Sep 2024 21:45:57 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Fri, 13 Sep 2024 21:26:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/31609">@Salep</a> said in <a href="/post/96609">Style token not saved</a>:</p>
<blockquote>
<p dir="auto">but I dont know how can bind keys to those scripts.<br />
can u help me with that?</p>
</blockquote>
<p dir="auto">The  “Basic instructions on PythonScripting may be found <a href="https://community.notepad-plus-plus.org/topic/23039/faq-desk-how-to-install-and-run-a-script-in-pythonscript/1">HERE</a>” link from Alan’s 2022-Nov-19 post contains the instructions on how to bind keys to those scripts, in installation step 4, in the point starting with “<a href="https://community.notepad-plus-plus.org/topic/23039/faq-how-to-install-and-run-a-script-in-pythonscript#:~:text=now%20list%20ProvidedScript-,To%20give%20it%20a%20keyboard%20shortcut,-%3A">To give it a keyboard shortcut</a>”</p>
]]></description><link>https://community.notepad-plus-plus.org/post/96610</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/96610</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Fri, 13 Sep 2024 21:26:08 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Fri, 13 Sep 2024 21:18:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@Alan-Kilborn</a> said in <a href="/post/81755">Style token not saved</a>:</p>
<blockquote>
<p dir="auto">Bind the running of these two scripts to keycombos of your choosing</p>
</blockquote>
<p dir="auto">hi I followed your guide it works perfect thank u.<br />
but I dont know how can bind keys to those scripts.<br />
can u help me with that?<br />
sorry for necro if it is not allowed</p>
]]></description><link>https://community.notepad-plus-plus.org/post/96609</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/96609</guid><dc:creator><![CDATA[Salep]]></dc:creator><pubDate>Fri, 13 Sep 2024 21:18:10 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Fri, 23 Jun 2023 11:21:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/28642">@nsk7even</a> said in <a href="/post/87343">Style token not saved</a>:</p>
<blockquote>
<p dir="auto">It seems to be arbitrary how much occurrences of the word that is to be styled are missing.<br />
Do you have an idea of the reason of this behaviour?</p>
</blockquote>
<p dir="auto">I can see the same thing; currently I don’t know why it is happening. :-(</p>
]]></description><link>https://community.notepad-plus-plus.org/post/87356</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/87356</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Fri, 23 Jun 2023 11:21:07 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Thu, 22 Jun 2023 16:24:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@Alan-Kilborn</a> thank you for this great script! I tried it and it works kind of.<br />
Interestingly I have to run the script multiple times to let it apply (load) all word highlightings for a style token.<br />
It seems to be arbitrary how much occurrences of the word that is to be styled are missing.</p>
<p dir="auto">Do you have an idea of the reason of this behaviour?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/87343</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/87343</guid><dc:creator><![CDATA[nsk7even]]></dc:creator><pubDate>Thu, 22 Jun 2023 16:24:15 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Wed, 05 Apr 2023 11:34:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@Alan-Kilborn</a> Works!!! I don’t use notepad++ to develop code, only to create content for my websites, and that helped me a lot, thank you very much.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/85499</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/85499</guid><dc:creator><![CDATA[Jane Eyre]]></dc:creator><pubDate>Wed, 05 Apr 2023 11:34:53 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Sat, 19 Nov 2022 12:01:31 GMT]]></title><description><![CDATA[<p dir="auto">It appears I didn’t give the original script a name in this thread, although I called it <code>StylingSaveOrLoad.py</code> on my setup.  Thus, for a new script, I’ll call it <code>StylingSaveOrLoad2.py</code>.</p>
<p dir="auto">The new script is similar to the old, but a major way it is different is that it saves a <code>.sty</code> file in the same folder as the original file, to hold the styling data.  Thus, if you’re editing <code>test.txt</code> and then save the styling by running the script, you’ll see <code>test.sty</code> in the same folder.</p>
<p dir="auto">Basic instructions on PythonScripting may be found <a href="https://community.notepad-plus-plus.org/topic/23039/faq-desk-how-to-install-and-run-a-script-in-pythonscript/1">HERE</a>.</p>
<p dir="auto">Here’s the script listing:</p>
<pre><code># -*- coding: utf-8 -*-
from __future__ import print_function

# references:
#  https://community.notepad-plus-plus.org/topic/18134/style-token-not-saved/

from Npp import *
import inspect
import os

#-------------------------------------------------------------------------------

class SSOL2(object):

    def __init__(self):

        self.debug = True if 0 else False
        if self.debug:
            pass
            #console.show()
            #console.clear()
        self.this_script_name = inspect.getframeinfo(inspect.currentframe()).filename.split(os.sep)[-1].rsplit('.', 1)[0]

        # identifiers pulled from N++ source code:
        SCE_UNIVERSAL_FOUND_STYLE_EXT1 = 25  # N++ style 1 indicator number
        SCE_UNIVERSAL_FOUND_STYLE_EXT2 = 24  # N++ style 2 indicator number
        SCE_UNIVERSAL_FOUND_STYLE_EXT3 = 23  # N++ style 3 indicator number
        SCE_UNIVERSAL_FOUND_STYLE_EXT4 = 22  # N++ style 4 indicator number
        SCE_UNIVERSAL_FOUND_STYLE_EXT5 = 21  # N++ style 5 indicator number
        SCE_UNIVERSAL_FOUND_STYLE      = 31  # N++ red-"mark" feature highlighting style indicator number

        self.indicator_number_list = [
            SCE_UNIVERSAL_FOUND_STYLE_EXT1,
            SCE_UNIVERSAL_FOUND_STYLE_EXT2,
            SCE_UNIVERSAL_FOUND_STYLE_EXT3,
            SCE_UNIVERSAL_FOUND_STYLE_EXT4,
            SCE_UNIVERSAL_FOUND_STYLE_EXT5,
            SCE_UNIVERSAL_FOUND_STYLE,
        ]

    def get_data_file_path_for_active_tab(self):
        active_file_pathname = notepad.getCurrentFilename()
        if not os.path.isfile(active_file_pathname): return None
        if active_file_pathname.endswith('.sty'): return None
        data_file_for_active_tab = active_file_pathname.rsplit('.', 1)[0] + '.sty'
        return data_file_for_active_tab

    def save_data_file(self):
        data_file_for_active_tab = self.get_data_file_path_for_active_tab()
        if data_file_for_active_tab == None:
            self.mb('Problem saving styling data for active tab file')
            return
        with open(data_file_for_active_tab, 'w') as fo:
            for indic_number in self.indicator_number_list:
                for (styled_start_pos, styled_end_pos) in self.highlight_indicator_range_tups_generator(indic_number):
                    fo.write('{i} {start} {stop}\n'.format(i=indic_number, start=styled_start_pos, stop=styled_end_pos))

    def load_data_file(self):
        data_file_for_active_tab = self.get_data_file_path_for_active_tab()
        if data_file_for_active_tab == None or not os.path.isfile(data_file_for_active_tab):
            self.mb('Problem loading styling data for active tab file')
            return
        with open(data_file_for_active_tab) as fi:
            for line in fi:
                (indic, start, end) = line.rstrip().split()
                editor.setIndicatorCurrent(int(indic))
                editor.indicatorFillRange(int(start), int(end) - int(start))

    def run(self):
        saving_not_loading = self.yes_no_cancel('\r\n'.join([
            "SAVE current doc's styling to disk file?\r\n",
            "YES = Yes, please SAVE it",
            "NO = LOAD styling info from file and apply to current doc",
            "CANCEL = I'm outta here"]))
        if saving_not_loading == None: return
        self.save_data_file() if saving_not_loading else self.load_data_file()

    def highlight_indicator_range_tups_generator(self, indicator_number):
        '''
        the following logic depends upon behavior that isn't exactly documented;
        it was noticed that calling editor.indicatorEnd() will yield the "edge"
        (either leading or trailing) of the specified indicator greater than the position
        specified by the caller
        this is definitely different than the scintilla documentation:
        "Find the start or end of a range with one value from a position within the range"
        '''
        if editor.indicatorEnd(indicator_number, 0) == 0: return
        indicator_end_pos = 0  # set special value to key a check the first time thru the while loop
        while True:
            if indicator_end_pos == 0 and editor.indicatorValueAt(indicator_number, 0) == 1:
                # we have an indicator starting at position 0!
                # when an indicator highlight starts at position 0, editor.indicatorEnd()
                #  gives us the END of the marking rather than the beginning;
                #  have to compensate for that:
                indicator_start_pos = 0
            else:
                indicator_start_pos = editor.indicatorEnd(indicator_number, indicator_end_pos)
            indicator_end_pos = editor.indicatorEnd(indicator_number, indicator_start_pos)
            if indicator_start_pos == indicator_end_pos: break  # no more matches
            yield (indicator_start_pos, indicator_end_pos)

    def print(self, *args):
        if self.debug:
            print(self.__class__.__name__ + ':', *args)

    def mb(self, msg, flags=0, title=''):  # a message-box function
        return notepad.messageBox(msg, title if title else self.this_script_name, flags)

    def yes_no_cancel(self, question_text):
        retval = None
        answer = self.mb(question_text, MESSAGEBOXFLAGS.YESNOCANCEL, self.this_script_name)
        if answer == MESSAGEBOXFLAGS.RESULTYES: retval = True
        elif answer == MESSAGEBOXFLAGS.RESULTNO: retval = False
        return retval

#-------------------------------------------------------------------------------

if __name__ == '__main__':
    SSOL2().run()
</code></pre>
<p dir="auto">You can directly invoke this script, to get a prompt box much like the original script:</p>
<p dir="auto"><img src="/assets/uploads/files/1668858857272-37125189-04c3-47d1-9e61-c66a9c2d6c23-image.png" alt="37125189-04c3-47d1-9e61-c66a9c2d6c23-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Or, if you prefer, you can set two up new keycombo-invoked scripts, such that one directly saves the data file, and one applies the styling from the data file (i.e., loads it).</p>
<p dir="auto">If you like the two-keycombo approach, here’s how to set up the additional scripts needed for that:</p>
<ul>
<li>Add these lines to (user) <code>startup.py</code>:</li>
</ul>
<pre><code>import StylingSaveOrLoad2
ssol2 = StylingSaveOrLoad2.SSOL2()
</code></pre>
<ul>
<li>Create a new script file called <code>StylingSaveForCurrentFile.py</code> with content:</li>
</ul>
<pre><code># -*- coding: utf-8 -*-
ssol2.save_data_file()
</code></pre>
<ul>
<li>Create a new script file called <code>StylingLoadForCurrentFile.py</code> with content:</li>
</ul>
<pre><code># -*- coding: utf-8 -*-
ssol2.load_data_file()
</code></pre>
<ul>
<li>Bind the running of these two scripts to keycombos of your choosing</li>
</ul>
]]></description><link>https://community.notepad-plus-plus.org/post/81755</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81755</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Sat, 19 Nov 2022 12:01:31 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Fri, 18 Nov 2022 10:26:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/26911">@BallardiniFANS</a></p>
<p dir="auto">OK, with the more detailed error reporting I can see what failed with the script.  While running as administrator solves the problem, it is rather like cutting off your arm because you have a hangnail – problem solved, but…</p>
<p dir="auto">Note that I believe the intent of the script was just to demo the functionality, not really be useful in a general sense.  Why do I say this?  Because a single file is used for the data, it is only useful with a single source file.  (There are some other logistical problems with saving and restoring styling, as well).</p>
<p dir="auto">Let me rework the script a little, I’ll post a new one here; check back here in a few days…</p>
]]></description><link>https://community.notepad-plus-plus.org/post/81707</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81707</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Fri, 18 Nov 2022 10:26:10 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Fri, 18 Nov 2022 10:21:03 GMT]]></title><description><![CDATA[<p dir="auto">Now it works fine!!!<br />
Running Notepad as administrator the issue is fixed.</p>
<p dir="auto">Thank you very much <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@Alan-Kilborn</a></p>
]]></description><link>https://community.notepad-plus-plus.org/post/81706</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81706</guid><dc:creator><![CDATA[BallardiniFANS]]></dc:creator><pubDate>Fri, 18 Nov 2022 10:21:03 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Fri, 18 Nov 2022 10:26:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@Alan-Kilborn</a><br />
There is an error when I choose YES or NO:</p>
<p dir="auto"><img src="/assets/uploads/files/1668767159049-461397546.png" alt="461397546.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/81705</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81705</guid><dc:creator><![CDATA[BallardiniFANS]]></dc:creator><pubDate>Fri, 18 Nov 2022 10:26:00 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Fri, 18 Nov 2022 09:58:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/26911">@BallardiniFANS</a></p>
<p dir="auto">Yes, it works fine for me.  I would have mentioned it if it didn’t.</p>
<p dir="auto">I’m sort of out of ideas on why it isn’t working for you.</p>
<p dir="auto">It might be nice to have some independent verification from others that the script works fine for them.  <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/3841">@PeterJones</a> maybe?</p>
<p dir="auto">You could certainly try the script with a newer version of Notepad++ than 8.1.* and see if that makes a difference.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/81703</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81703</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Fri, 18 Nov 2022 09:58:56 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Fri, 18 Nov 2022 09:07:14 GMT]]></title><description><![CDATA[<p dir="auto">Update: I tried with the v8.1.9.2, but nothing changes.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@Alan-Kilborn</a> Have you any idea? Is it work in your environment?<br />
Let me know, this function is fundamental for me eheh.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/81698</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81698</guid><dc:creator><![CDATA[BallardiniFANS]]></dc:creator><pubDate>Fri, 18 Nov 2022 09:07:14 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Thu, 17 Nov 2022 14:37:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/26911">@BallardiniFANS</a> said in <a href="/post/81626">Style token not saved</a>:</p>
<blockquote>
<p dir="auto">Click on yes, the script should save the style token, but when I close and reopen the file .txt the style token of the file is disappear.</p>
</blockquote>
<p dir="auto">The problem can be due to the Notepad++ version?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/81637</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81637</guid><dc:creator><![CDATA[BallardiniFANS]]></dc:creator><pubDate>Thu, 17 Nov 2022 14:37:27 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Thu, 17 Nov 2022 14:04:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@Alan-Kilborn</a> said in <a href="/post/81629">Style token not saved</a>:</p>
<blockquote>
<p dir="auto">Are you running the script again, and choosing No this time?</p>
</blockquote>
<p dir="auto">I’m doing these steps:</p>
<ol>
<li>I put a style token on a word.</li>
<li>Run the script and click on YES.</li>
<li>Close and Reopen the file .txt</li>
<li>I don’t see the style token, I Run  the script again and click on NO.</li>
</ol>
<p dir="auto">After step 4 I see the text without style token.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/81630</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81630</guid><dc:creator><![CDATA[BallardiniFANS]]></dc:creator><pubDate>Thu, 17 Nov 2022 14:04:01 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Thu, 17 Nov 2022 13:57:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/26911">@BallardiniFANS</a> said in <a href="/post/81626">Style token not saved</a>:</p>
<blockquote>
<p dir="auto">It works now</p>
</blockquote>
<p dir="auto">GREAT!</p>
<blockquote>
<p dir="auto">but when I close and reopen the file .txt the token style of the file is disappear</p>
</blockquote>
<p dir="auto">Are you running the script again, and choosing <code>No</code> this time?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/81629</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81629</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Thu, 17 Nov 2022 13:57:00 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Thu, 17 Nov 2022 13:56:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@Alan-Kilborn</a><br />
It works now, I see the windows of the script.<br />
Click on yes, the script should save the style token, but when I close and reopen the file .txt the style token of the file is disappear.</p>
<p dir="auto"><img src="/assets/uploads/files/1668692755200-4789534564.png" alt="4789534564.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/81626</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81626</guid><dc:creator><![CDATA[BallardiniFANS]]></dc:creator><pubDate>Thu, 17 Nov 2022 13:56:43 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Thu, 17 Nov 2022 13:27:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/26911">@BallardiniFANS</a> said in <a href="/post/81624">Style token not saved</a>:</p>
<blockquote>
<p dir="auto">This is the path where the script is located</p>
</blockquote>
<p dir="auto">As long as you can see the script when you go here in the N++ menu (as you need to do to run it), the location of the script should be fine:</p>
<p dir="auto"><img src="/assets/uploads/files/1668691453257-a8fe5330-9a8d-47bf-973f-1f2ef286641d-image.png" alt="a8fe5330-9a8d-47bf-973f-1f2ef286641d-image.png" class=" img-fluid img-markdown" /></p>
<blockquote>
<p dir="auto">In this path I putted also a file called <code>styling.txt</code></p>
</blockquote>
<p dir="auto">Well the script puts that file there, not you.  So I don’t think knowing this gets us anywhere with the debugging.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/81625</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81625</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Thu, 17 Nov 2022 13:27:12 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Thu, 17 Nov 2022 13:25:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@Alan-Kilborn</a> said in <a href="/post/81621">Style token not saved</a>:</p>
<blockquote>
<p dir="auto">Does the Notepad++ status bar indicate that your file’s encoding is UTF-8?</p>
</blockquote>
<p dir="auto">yep, I checked it now, it is setted on:  Format -&gt; Coding in UTF-8.<br />
However, I explain the step that i’m doing, probably I wrong something:</p>
<ol>
<li>This is the path where the script is located : C:\Program Files\Notepad++\plugins\Config\PythonScript</li>
</ol>
<p dir="auto">In this path I putted also a file called styling.txt</p>
<ol start="2">
<li>I’m using Python 3.10 to run the script.</li>
</ol>
]]></description><link>https://community.notepad-plus-plus.org/post/81624</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81624</guid><dc:creator><![CDATA[BallardiniFANS]]></dc:creator><pubDate>Thu, 17 Nov 2022 13:25:41 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Thu, 17 Nov 2022 13:07:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/26911">@BallardiniFANS</a></p>
<p dir="auto">Hmm, at this point, I’m not sure.</p>
<p dir="auto">Does the Notepad++ status bar indicate that your file’s encoding is <code>UTF-8</code>?</p>
<p dir="auto">I just tried the script as written above in a fresh setup of N++ v8.4.7 and PythonScript v3.0.12, as well as also trying it with PS v2.0, and the script ran fine, either with or without the new first line I asked you to add.</p>
<p dir="auto">Aside from having you examine your copy of the script file in a hex editor, to see if somehow an oddball character has crept in (at the position indicated by the error message), I’m not sure what else to do here.</p>
<p dir="auto">Maybe <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/3841">@PeterJones</a> has an idea?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/81621</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81621</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Thu, 17 Nov 2022 13:07:29 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Thu, 17 Nov 2022 12:49:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@Alan-Kilborn</a><br />
I tried putting it at the first row.</p>
<pre><code># -*- coding: utf-8 -*-
</code></pre>
<p dir="auto">The error is the same :/</p>
]]></description><link>https://community.notepad-plus-plus.org/post/81620</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81620</guid><dc:creator><![CDATA[BallardiniFANS]]></dc:creator><pubDate>Thu, 17 Nov 2022 12:49:38 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Thu, 17 Nov 2022 11:55:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/26911">@BallardiniFANS</a> said in <a href="/post/81617">Style token not saved</a>:</p>
<blockquote>
<p dir="auto">Can you help me?</p>
</blockquote>
<p dir="auto">I’ll certainly try.</p>
<blockquote>
<p dir="auto">SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 16-17: malformed \N character escape</p>
</blockquote>
<p dir="auto">A <code>SyntaxError</code> is a problem with the script, not with the data you are running it on.</p>
<p dir="auto">Perhaps as a first step to debugging this problem, try changing the script to put this as line 1 of it:</p>
<pre><code># -*- coding: utf-8 -*-
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/81619</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81619</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Thu, 17 Nov 2022 11:55:20 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Thu, 17 Nov 2022 11:12:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@Alan-Kilborn</a><br />
Hi, I know that the topic is so old, but I try the same to explain my problem:</p>
<p dir="auto">I executed your code, but the script returns the following error:</p>
<p dir="auto">SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 16-17: malformed \N character escape</p>
<p dir="auto">Can you help me? I’m not a Python expert, so I don’t understand how to fix this issue. I’m using a v8.4.2 of Notepad++.</p>
<p dir="auto">Thanks</p>
]]></description><link>https://community.notepad-plus-plus.org/post/81617</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81617</guid><dc:creator><![CDATA[BallardiniFANS]]></dc:creator><pubDate>Thu, 17 Nov 2022 11:12:55 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Thu, 03 Feb 2022 05:04:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@alan-kilborn</a>   Thank you, Alan!</p>
<p dir="auto">I was looking for something like this, and have verified this Python script still works on Notepad++ v8.1.9.2.</p>
<p dir="auto">For me it saved the styling.txt file in the same folder as the Python scripts, under [install path]\Notepad++\plugins\config\PythonScript\scripts.</p>
<p dir="auto">When I tried to use the Python script to reload/apply the saved styles, at first I got a “No such file or directory” error.</p>
<p dir="auto">That went away after I changed the script to save the styling file in the same folder as the file being edited.<br />
I also changed the styling filename to match the name of the file being edited with “_nppStyling.txt” appended.<br />
This lets you save multiple styling files, and you can easily see by browsing your folders, which files you’ve saved styles for.</p>
<p dir="auto">To do that, I added these lines to the beginning of the main() method:</p>
<pre><code>    currentFilePath = notepad.getCurrentFilename()
    stylingFileName = currentFilePath + '_nppStyling.txt'
</code></pre>
<p dir="auto">Then I used the <em>stylingFileName</em> variable in place of ‘styling.txt’.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/73641</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/73641</guid><dc:creator><![CDATA[djinncoyote]]></dc:creator><pubDate>Thu, 03 Feb 2022 05:04:50 GMT</pubDate></item><item><title><![CDATA[Reply to Style token not saved on Fri, 23 Aug 2019 19:00:24 GMT]]></title><description><![CDATA[<p dir="auto">So as luck would have it I had some time immediately. :)</p>
<p dir="auto">I would caution users to work with this with documents that are read-only, otherwise be very careful about not changing any data until you’ve reloaded the styles with it from a previous run of N++.  Otherwise the styling that is loaded will be “skewed” and will be, well, basically lost and unrecoverable.  You’ve been warned.  No actual text data will be harmed in any event.</p>
<p dir="auto">Here’s the Pythonscript that works for either saving or loading the styling.  It works for the currently loaded Notepad++ file (name doesn’t matter) and saves its info to a fixed-name data file.  All this behavior can be changed, but that’s left as an exercise for the reader; I’m just trying to get the core logic expressed here.  Error-checking is minimal to non-existent. Niceties: missing-in-acton as well.  Much of the core of the script copied from the link referenced earlier.</p>
<pre><code>def main():

    result = notepad.messageBox("SAVE current doc's styling to disk file?\r\n\r\nYES = Yes, please\r\nNO = LOAD styling info from file and apply to current doc\r\nCANCEL = I'm outta here", '', MESSAGEBOXFLAGS.YESNOCANCEL)
    if result == MESSAGEBOXFLAGS.RESULTCANCEL: return
    saving_not_loading = True if result == MESSAGEBOXFLAGS.RESULTYES else False

    # identifiers pulled from N++ source code:
    SCE_UNIVERSAL_FOUND_STYLE_EXT1 = 25  # N++ style 1 indicator number
    SCE_UNIVERSAL_FOUND_STYLE_EXT2 = 24  # N++ style 2 indicator number
    SCE_UNIVERSAL_FOUND_STYLE_EXT3 = 23  # N++ style 3 indicator number
    SCE_UNIVERSAL_FOUND_STYLE_EXT4 = 22  # N++ style 4 indicator number
    SCE_UNIVERSAL_FOUND_STYLE_EXT5 = 21  # N++ style 5 indicator number
    SCE_UNIVERSAL_FOUND_STYLE = 31  # N++ red-"mark" feature highlighting style indicator number

    indicator_number_list = []
    indicator_number_list.append(SCE_UNIVERSAL_FOUND_STYLE_EXT1)
    indicator_number_list.append(SCE_UNIVERSAL_FOUND_STYLE_EXT2)
    indicator_number_list.append(SCE_UNIVERSAL_FOUND_STYLE_EXT3)
    indicator_number_list.append(SCE_UNIVERSAL_FOUND_STYLE_EXT4)
    indicator_number_list.append(SCE_UNIVERSAL_FOUND_STYLE_EXT5)
    indicator_number_list.append(SCE_UNIVERSAL_FOUND_STYLE)

    if saving_not_loading:

        def highlight_indicator_range_tups_generator(indicator_number):
            '''
            the following logic depends upon behavior that isn't exactly documented;
            it was noticed that calling editor.indicatorEnd() will yield the "edge"
            (either leading or trailing) of the specified indicator greater than the position
            specified by the caller
            this is definitely different than the scintilla documentation:
            "Find the start or end of a range with one value from a position within the range"
            '''
            if editor.indicatorEnd(indicator_number, 0) == 0: return
            indicator_end_pos = 0  # set special value to key a check the first time thru the while loop
            while True:
                if indicator_end_pos == 0 and editor.indicatorValueAt(indicator_number, 0) == 1:
                    # we have an indicator starting at position 0!
                    # when an indicator highlight starts at position 0, editor.indicatorEnd()
                    #  gives us the END of the marking rather than the beginning;
                    #  have to compensate for that:
                    indicator_start_pos = 0
                else:
                    indicator_start_pos = editor.indicatorEnd(indicator_number, indicator_end_pos)
                indicator_end_pos = editor.indicatorEnd(indicator_number, indicator_start_pos)
                if indicator_start_pos == indicator_end_pos: break  # no more matches
                yield (indicator_start_pos, indicator_end_pos)

        with open('styling.txt', 'w') as f:
            for indic_number in indicator_number_list:
                for (styled_start_pos, styled_end_pos) in highlight_indicator_range_tups_generator(indic_number):
                    f.write('{i} {start} {stop}\n'.format(i=indic_number, start=styled_start_pos, stop=styled_end_pos))

    else:

        with open('styling.txt') as f:
            for line in f:
                (indic, start, end) = line.rstrip().split()
                editor.setIndicatorCurrent(int(indic))
                editor.indicatorFillRange(int(start), int(end) - int(start))

main()
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/46533</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/46533</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Fri, 23 Aug 2019 19:00:24 GMT</pubDate></item></channel></rss>