Setting the encoding character set by "User Defined Language"
-
Is it possible to set “Encoding -> Character Set” to “OEM-US” within / by setting in an “User Defined Language”?
Reason: I’m using NPP often for editing Sourcecode for an old PLC. There it must be pure ASCII, except comments. In comments I’m using characters of the OEM-US set, so switching the encoding by a setting in “User Defined Language” is wanted -
In comments I’m using characters of the OEM-US set
Curious why you are doing this, in the comments? Does it add special value to what you’re doing?
-
Is it possible to set “Encoding -> Character Set” to “OEM-US” within / by setting in an “User Defined Language”?
No, the encoding is not stored in or controlled by the User Defined Language (UDL), or by any of the builtin languages, either.
Remember, the “language”, whether UDL or builtin language, is really a syntax highlighter: even if there is a requirement for some language to only use a certain encoding, that would be a requirement separate from its syntax. Syntax has to do with the words, tokens, commands, data, etc; encoding has to do with the mapping between bytes inside the file and the textual characters they represent: syntax is at a “higher level of abstraction” than encoding.
so switching the encoding by a setting in “User Defined Language” is wanted
The syntax parsing system itself (builtin or UDL) is encoding agnostic (cannot know about the encoding), because by the time the syntax parser is running, the bytes from the file have already been read and interpreted as characters by Notepad++ – and thus, it’s beyond the encoding stage. They work with characters, not with file-bytes.
That said, you can automate many things in Notepad++ using plugins. For example, the PythonScript plugin allows you to run Python code which will affect the text and GUI. In this case, you could setup a PythonScript hook that runs during the File > Save event; this code could check to see if the file being saved is a UDL, and if it is then check if it’s your particular UDL, and if it is then it can change the encoding of the file to OEM-US.
Once you install the PythonScript plugin, there are good help files included (Plugins > Python Script > Context-Help) which describe the various commands necessary; since you’re programming PLC, I am going to assume you know something about programming, and thus the simple Python syntax necessary shouldn’t be too difficult for you. If you need help on the Notepad+±related specifics, feel free to reply. But to get you started, look up the sections on “Handling Notifications” for a general overview,
notepad.callback()
for how to register the callback, “Enums > NOTIFICATION”,notepad.setEncoding()
for changing the encoding, andnotepad.getLangType()
/.getLanguageName()
/.getLanguageDesc()
for identifying whether your UDL is active.