PCEmacs strips some accents on save [solved]

I’m using: SWI-Prolog version 8.1.17-1 (but it occured on 7.x and perhaps even 6.x).

I want the PCEmacs to: preserve all accents when saving file - containing for example “čČžŽ”

But what I’m getting is: file containing “cCžŽ”

Hope this is fixable, otherwise I’m pretty happy with PCEmacs (because of nice Prolog “integration”).

Are you using an encoding/1 directive at the top of your source file?

No, I’m not.
I’ll try, but what about non-prolog files ?

(prolog files are my main concern, but it would be nice to be able to also edit text / config files with same editor)

If possible, use UTF-8 encoding for all your files and make sure that the default encoding is also set to UTF-8 (check the encoding flag value).

The encoding directive doesn’t affect the editor, just the compiler. It seem to be an OS issue though. This works fine for me on MacOS. Note it may also depend on internationalization settings. On Unix-like systems this typically requires an UTF-8 based locale. So, we need more details.

I’d like to use UTF-8.

When tried, it required creating a file with UTF8 BOM, (and restarting prolog session, as just clicking on reload led to garbled accented chars). PCEmacs on its own will not insert BOM, which leads to warning on compile, but with :-encoding(utf8). it at least saves the file as UTF-8.

“Locale” - no attempt to set anything for prolog (env vars / config files), Win 10 English,

The default encoding is taken from the operating-system locale IIRC. But you can set it from your SWI-Prolog initialization file. A BOM should not be necessary.

A BOM should not be necessary.

Not having BOM leads to (compile-time) warning like: Warning: ‘c:/temp/a.pl’:3:13: Illegal UTF-8 start
But it loaded ok, and accents from “test(“čČžŽ”).” were ok in query “a:test(x)”.

EDIT: The 3:13 position is position of last dot in the test file:

:-encoding(utf8).
:-module(aaa,[]).
test("čČžŽ").

At startup, what you get when you try the query:

?- current_prolog_flag(encoding, Encoding).

?- current_prolog_flag(encoding, Encoding).
Encoding = text.

That’s why the BOM avoids the compilation warning. SWI-Prolog recognizes the BOM and changes the encoding to UTF-8. Without the BOM, there’s no simple way to guess the source file encoding and in that case the default encoding is used, IIRC.

Woot, kick in the right direction,

:- set_prolog_flag(encoding, utf8).

in initfile makes UTF8 work by default. FFFFFUUUUUUUU…, for years i thought it buggy :-((((

Thanks