<?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[What is BUFFERENCODING.COOKIE ??]]></title><description><![CDATA[<p dir="auto">I’m aware of what is referred to as “baking cookies” on this site, but I’ve encountered a different type of cookie and I’d like to know where it comes from and what it means.</p>
<p dir="auto">In a Pythonscript, when I run these commands with a UTF-8 encoded file as the active one, I get the result indicated:</p>
<pre><code>&gt;&gt;&gt; notepad.getEncoding()
Npp.BUFFERENCODING.COOKIE
&gt;&gt;&gt; notepad.getEncoding(notepad.getCurrentBufferID())
Npp.BUFFERENCODING.COOKIE
</code></pre>
<p dir="auto">I kinda expected to get <code>BUFFERENCODING.UTF8</code> back instead.<br />
Anyone have ideas of the whys and the hows on this?</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/20142/what-is-bufferencoding-cookie</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Apr 2026 22:25:35 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/20142.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 12 Oct 2020 14:37:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to What is BUFFERENCODING.COOKIE ?? on Tue, 21 Dec 2021 16:05:05 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/58502">What is BUFFERENCODING.COOKIE ??</a>:</p>
<blockquote>
<p dir="auto">How is one to tell the difference, in Pythonscript, if the current file’s encoding is UTF-8 without BOM, or for example, ISO-8859-1 ?</p>
</blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/3841">@peterjones</a> said in <a href="/post/58503">What is BUFFERENCODING.COOKIE ??</a>:</p>
<blockquote>
<p dir="auto">I thought there would be a way to read back the character set, distinct from the GETBUFFERENCODING message… but I cannot find a message that does that.  Barring that, I thought that the scintilla object might have that info somewhere, but I cannot find it there, either. …maybe <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/14479">@Ekopalypse</a> has insight on this one.</p>
</blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/14479">@ekopalypse</a> said in <a href="/post/58504">What is BUFFERENCODING.COOKIE ??</a>:</p>
<blockquote>
<p dir="auto">Sorry, but I have no idea.</p>
</blockquote>
<hr />
<p dir="auto">So…it’s a bit cheesy, but one can read the status bar field that shows the encoding type to get this information (as its text string).</p>
<p dir="auto">We’ve discussed in this forum how to get the status bar data before using a PythonScript, but I’ve revamped my code for doing it so I’ll post the whole thing here.</p>
<p dir="auto">Here’s <code>NotepadGetStatusBar.py</code> with a demo at the end to show the current file’s encoding:</p>
<pre><code class="language-z"># -*- coding: utf-8 -*-
from __future__ import print_function

from Npp import *
import ctypes
from ctypes.wintypes import BOOL, HWND, WPARAM, LPARAM, UINT

class NGSB(object):  # implements a "getStatusBar" function (complement to notepad.setStatusBar())

    def __init__(self):
        self.SendMessageW = ctypes.windll.user32.SendMessageW
        LRESULT = LPARAM
        self.SendMessageW.restype = LRESULT
        self.SendMessageW.argtypes = [ HWND, UINT, WPARAM, LPARAM ]
        self.create_unicode_buffer = ctypes.create_unicode_buffer
        self.curr_class_256 = self.create_unicode_buffer(256)
        self.STATUSBAR_HANDLE = None
        self._determine_statusbar_handle()
        assert self.STATUSBAR_HANDLE

    def get_statusbar_by_section(self, statusbar_item_number):
        # statusbar_item_number can be integer 0 thru 5 or one of:
        #  STATUSBARSECTION.DOCTYPE
        #  STATUSBARSECTION.DOCSIZE
        #  STATUSBARSECTION.CURPOS
        #  STATUSBARSECTION.EOFFORMAT
        #  STATUSBARSECTION.UNICODETYPE
        #  STATUSBARSECTION.TYPINGMODE
        return self._get_statusbar_section(statusbar_item_number)

    def get_statusbar_as_tuple(self):
        section_list = [
            STATUSBARSECTION.DOCTYPE,
            STATUSBARSECTION.DOCSIZE,
            STATUSBARSECTION.CURPOS,
            STATUSBARSECTION.EOFFORMAT,
            STATUSBARSECTION.UNICODETYPE,
            STATUSBARSECTION.TYPINGMODE,
        ]
        return tuple(list(map(lambda x: self._get_statusbar_section(x), section_list)))

    def _determine_statusbar_handle(self):

        WNDENUMPROC = ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM)
        FindWindowW = ctypes.windll.user32.FindWindowW
        FindWindowExW = ctypes.windll.user32.FindWindowExW
        EnumChildWindows = ctypes.windll.user32.EnumChildWindows
        GetClassNameW = ctypes.windll.user32.GetClassNameW

        self.STATUSBAR_HANDLE = None

        def enum_callback_fn(hwnd, lparam):
            GetClassNameW(hwnd, self.curr_class_256, 256)
            if self.curr_class_256.value.lower() == "msctls_statusbar32":
                self.STATUSBAR_HANDLE = hwnd
                return False  # stop the enumeration
            return True  # continue the enumeration

        npp_hwnd = FindWindowW(u"Notepad++", None)
        #print('npp_hwnd:', npp_hwnd)
        EnumChildWindows(npp_hwnd, WNDENUMPROC(enum_callback_fn), 0)
        #print('self.STATUSBAR_HANDLE:', self.STATUSBAR_HANDLE)

    def _get_statusbar_section(self, statusbar_item_number):
        assert statusbar_item_number &lt;= 5
        WM_USER = 0x400
        SB_GETTEXTLENGTHW = WM_USER + 12
        SB_GETTEXTW = WM_USER + 13
        SBT_OWNERDRAW = 0x1000
        retcode = self.SendMessageW(self.STATUSBAR_HANDLE, SB_GETTEXTLENGTHW, statusbar_item_number, 0)
        length = retcode &amp; 0xFFFF
        type = (retcode &gt;&gt; 16) &amp; 0xFFFF
        assert (type != SBT_OWNERDRAW)
        text_buffer = self.create_unicode_buffer(length)
        retcode = self.SendMessageW(self.STATUSBAR_HANDLE, SB_GETTEXTW, statusbar_item_number, ctypes.addressof(text_buffer))
        retval = '{}'.format(text_buffer[:length])
        return retval

if __name__ == '__main__':
    print(NGSB().get_statusbar_by_section(STATUSBARSECTION.UNICODETYPE))
</code></pre>
<p dir="auto">Running the script will print the current file’s encoding (from statusbar information) to the Pythonscript console window.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/72268</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/72268</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Tue, 21 Dec 2021 16:05:05 GMT</pubDate></item><item><title><![CDATA[Reply to What is BUFFERENCODING.COOKIE ?? on Sat, 17 Oct 2020 19:55:40 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> said in <a href="/post/58495">What is BUFFERENCODING.COOKIE ??</a>:</p>
<blockquote>
<p dir="auto">I might have a bug in my Perl library</p>
</blockquote>
<p dir="auto">I did.  It’s <a href="https://community.notepad-plus-plus.org/post/58686">been fixed</a>. :-)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/58687</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58687</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Sat, 17 Oct 2020 19:55:40 GMT</pubDate></item><item><title><![CDATA[Reply to What is BUFFERENCODING.COOKIE ?? on Mon, 12 Oct 2020 19:26:37 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></p>
<p dir="auto">Sorry, but I have no idea.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/58504</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58504</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Mon, 12 Oct 2020 19:26:37 GMT</pubDate></item><item><title><![CDATA[Reply to What is BUFFERENCODING.COOKIE ?? on Mon, 12 Oct 2020 19:16:14 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> ,</p>
<p dir="auto">I thought there would be a way to read back the character set, distinct from the GETBUFFERENCODING message… but I cannot find a message that does that.  Barring that, I thought that the scintilla object might have that info somewhere, but I cannot find it there, either.</p>
<p dir="auto">But I’m often bad at finding the things in PythonScript that others find easily; maybe <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/14479">@Ekopalypse</a> has insight on this one.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/58503</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58503</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Mon, 12 Oct 2020 19:16:14 GMT</pubDate></item><item><title><![CDATA[Reply to What is BUFFERENCODING.COOKIE ?? on Mon, 12 Oct 2020 18:56:13 GMT]]></title><description><![CDATA[<p dir="auto">So I guess it is fine, if a bit strange, that someone wants to call UTF-8 without BOM “cookie” encoding in their software…</p>
<p dir="auto">But, paraphrasing the above table:</p>
<pre><code>Encoding &gt;       | notepad.getEncoding() retval
-----------------+-------------------------------
UTF-8            | Npp.BUFFERENCODING.COOKIE
CharacterSets&gt;*  | Npp.BUFFERENCODING.COOKIE
</code></pre>
<p dir="auto">How is one to tell the difference, in Pythonscript, if the current file’s encoding is UTF-8 without BOM, or for example, ISO-8859-1 ?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/58502</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58502</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 12 Oct 2020 18:56:13 GMT</pubDate></item><item><title><![CDATA[Reply to What is BUFFERENCODING.COOKIE ?? on Mon, 12 Oct 2020 15:32:48 GMT]]></title><description><![CDATA[<p dir="auto">I tried digging into the Github Blames with code history, and as far as I can tell, for <a href="https://github.com/notepad-plus-plus/notepad-plus-plus/blame/bbde64c30845761377d063afa7750ec7ce0659a6/PowerEditor/src/Parameters.h#L90" rel="nofollow ugc">at least the last 12 years</a>, he has mapped <code>uniCookie</code> to <code>IDM_FORMAT_AS_UTF_8</code> (as opposed to <code>uniUTF8</code> =&gt; <code>IDM_FORMAT_UTF_8</code>)</p>
<ul>
<li>
<p dir="auto">current: <a href="https://github.com/notepad-plus-plus/notepad-plus-plus/blob/8426c9ccd98157d2712e1b54d54f498a32e6481f/PowerEditor/src/Notepad_plus.cpp#L4439-L4453" rel="nofollow ugc">https://github.com/notepad-plus-plus/notepad-plus-plus/blob/8426c9ccd98157d2712e1b54d54f498a32e6481f/PowerEditor/src/Notepad_plus.cpp#L4439-L4453</a></p>
</li>
<li>
<p dir="auto">12 years ago: <a href="https://github.com/notepad-plus-plus/notepad-plus-plus/blob/4dd3b257e06c56093d109f055911addfe93770f7/PowerEditor/src/Notepad_plus.cpp#L5484-L5497" rel="nofollow ugc">https://github.com/notepad-plus-plus/notepad-plus-plus/blob/4dd3b257e06c56093d109f055911addfe93770f7/PowerEditor/src/Notepad_plus.cpp#L5484-L5497</a></p>
</li>
</ul>
<p dir="auto">I cannot find a reason that he called one “cookie” in the commit comments…</p>
]]></description><link>https://community.notepad-plus-plus.org/post/58500</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58500</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Mon, 12 Oct 2020 15:32:48 GMT</pubDate></item><item><title><![CDATA[Reply to What is BUFFERENCODING.COOKIE ?? on Mon, 12 Oct 2020 15:31:54 GMT]]></title><description><![CDATA[<p dir="auto"><img src="/assets/uploads/files/1602516710882-a718156b-df1e-47aa-a6c1-d11397249c58-image.png" alt="a718156b-df1e-47aa-a6c1-d11397249c58-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/58499</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58499</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 12 Oct 2020 15:31:54 GMT</pubDate></item><item><title><![CDATA[Reply to What is BUFFERENCODING.COOKIE ?? on Mon, 12 Oct 2020 15:12:29 GMT]]></title><description><![CDATA[<p dir="auto">I ran more experiments</p>
<pre><code>Encoding &gt;       | notepad.getEncoding() retval
-----------------+-------------------------------
ANSI             | Npp.BUFFERENCODING.ENC8BIT
UTF-8            | Npp.BUFFERENCODING.COOKIE
UTF-8-BOM        | Npp.BUFFERENCODING.UTF8
UCS-2 BE BOM     | Npp.BUFFERENCODING.UCS2BE
UCS-2 LE BOM     | Npp.BUFFERENCODING.UCS2LE
CharacterSets&gt;*  | Npp.BUFFERENCODING.COOKIE
</code></pre>
<p dir="auto">I didn’t actually try <em>all</em> the character sets, but I tried a few, and all the ones I tried gave me COOKIE.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/58497</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58497</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Mon, 12 Oct 2020 15:12:29 GMT</pubDate></item><item><title><![CDATA[Reply to What is BUFFERENCODING.COOKIE ?? on Mon, 12 Oct 2020 14:53:26 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> ,</p>
<p dir="auto">I don’t know what it’s meant for – I don’t see it in the list of IDM_FORMAT_xxx contants, which are what I thought that the NPPM_GETBUFFERENCODING message was supposed to return.  Hmm, I might have a bug in my Perl library, because it appears those actually return from the <code>enum UniMode</code>, which is <code>enum UniMode {uni8Bit=0, uniUTF8=1, uni16BE=2, uni16LE=3, uniCookie=4, uni7Bit=5, uni16BE_NoBOM=6, uni16LE_NoBOM=7, uniEnd};</code> according to <a href="https://github.com/notepad-plus-plus/notepad-plus-plus/blob/bbde64c30845761377d063afa7750ec7ce0659a6/PowerEditor/src/Parameters.h#L90" rel="nofollow ugc">the source code</a>.</p>
<p dir="auto">Running a quick experiment, if I set <strong>Encoding &gt; UTF-8</strong>, <code>notepad.getEncoding()</code> shows Npp.BUFFERENCODING.COOKIE, but if I set <strong>Encoding &gt; UTF-8-BOM</strong>, it returns Npp.BUFFERENCODING.UTF8.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/58495</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58495</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Mon, 12 Oct 2020 14:53:26 GMT</pubDate></item></channel></rss>