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