Community
    • Login

    How detect codepage/encoding of current document?

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    4 Posts 2 Posters 970 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • WinterSilenceW
      WinterSilence
      last edited by

      Some of the Scintilla messages to use?
      Second question: how bind event changed encoding?

      EkopalypseE 1 Reply Last reply Reply Quote 0
      • EkopalypseE
        Ekopalypse @WinterSilence
        last edited by Ekopalypse

        @WinterSilence said in How detect codepage/encoding of current document?:

        Some of the Scintilla messages to use?

        Either use
        https://npp-user-manual.org/docs/plugin-communication/#nppm-getbufferencoding
        or
        https://www.scintilla.org/ScintillaDoc.html#SCI_GETCODEPAGE

        Second question: how bind event changed encoding?

        there is no notification that the encoding has changed.
        You have to either hook npp’s window message queue or
        use an existing notification like https://www.scintilla.org/ScintillaDoc.html#SCN_UPDATEUI and request the information.

        WinterSilenceW 1 Reply Last reply Reply Quote 3
        • WinterSilenceW
          WinterSilence @Ekopalypse
          last edited by

          @Ekopalypse thanks for help again. do you know about this? it’s work in npp?

          Specific to GTK, Cocoa and Windows only: Access to encoded text

          SCI_TARGETASUTF8(<unused>, char *s) → position
          This method retrieves the value of the target encoded as UTF-8 which is the default encoding of GTK so is useful for retrieving text for use in other parts of the user interface, such as find and replace dialogs. The length of the encoded text in bytes is returned. Cocoa uses UTF-16 which is easily converted from UTF-8 so this method can be used to perform the more complex work of transcoding from the various encodings supported.

          SCI_ENCODEDFROMUTF8(const char *utf8, char *encoded) → position
          SCI_SETLENGTHFORENCODE(position bytes)
          SCI_ENCODEDFROMUTF8 converts a UTF-8 string into the document’s encoding which is useful for taking the results of a find dialog, for example, and receiving a string of bytes that can be searched for in the document. Since the text can contain nul bytes, the SCI_SETLENGTHFORENCODE method can be used to set the length that will be converted. If set to -1, the length is determined by finding a nul byte. The length of the converted string is returned.

          EkopalypseE 1 Reply Last reply Reply Quote 0
          • EkopalypseE
            Ekopalypse @WinterSilence
            last edited by

            @WinterSilence

            I guess so, did a quick test with PythonScript plugin and it seems to do
            what it states it will do.

            4d4b7af0-b13c-472f-b3d7-a13c60c52c2c-image.png

            Do you suspect that this is not so?

            1 Reply Last reply Reply Quote 2
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors