• Login
Community
  • Login

How detect codepage/encoding of current document?

Scheduled Pinned Locked Moved Notepad++ & Plugin Development
4 Posts 2 Posters 999 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.
  • W
    WinterSilence
    last edited by Jul 13, 2020, 2:33 PM

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

    E 1 Reply Last reply Jul 13, 2020, 8:59 PM Reply Quote 0
    • E
      Ekopalypse @WinterSilence
      last edited by Ekopalypse Jul 13, 2020, 9:00 PM Jul 13, 2020, 8:59 PM

      @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.

      W 1 Reply Last reply Jul 19, 2020, 8:04 AM Reply Quote 3
      • W
        WinterSilence @Ekopalypse
        last edited by Jul 19, 2020, 8:04 AM

        @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.

        E 1 Reply Last reply Jul 19, 2020, 6:14 PM Reply Quote 0
        • E
          Ekopalypse @WinterSilence
          last edited by Jul 19, 2020, 6:14 PM

          @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
          4 out of 4
          • First post
            4/4
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors