Bug 187033

Summary: kate encoding modeline ignored
Product: [Applications] kate Reporter: Piotr Keplicz <keplicz>
Component: encodingAssignee: KWrite Developers <kwrite-bugs-null>
Severity: normal CC: balzer, drvladl, toni__arnold
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Ubuntu   
OS: Linux   
Latest Commit: Version Fixed In:

Description Piotr Keplicz 2009-03-13 10:51:19 UTC
Version:            (using KDE 4.2.1)
OS:                Linux
Installed from:    Ubuntu Packages

The default encoding for text files is UTF-8, however I'd like to open legacy PHP files with ISO-8859-2 encoding.

Kate is set to:
Default encoding: UTF-8
Encoding detection: Off or Central European (doesn't matter)

Under "Modes & Filetypes" the following variables are set for "Scripts/PHP (HTML)":

kate: replace-tabs false; tab-width 3; indent-width 3; encoding iso-8859-2;

When I open a PHP file for the first time, it's open readonly as UTF-8 and a message about invalid characters is shown. I need to close the file and open it again for that modeline to take effect.
Comment 1 Vlad Lungeanu 2009-05-14 15:57:31 UTC
Same here (Kate 3.2.3, KDE 4.2.3, Kubuntu 9.04).

I have set up a new filetype (Markup/TTX) for some special UTF-16 XML files (*.TTX, TRADOSTag documents).

The "Variables" field says:
kate: encoding UTF-16;

When I open such a file (by clicking on it in Dolphin, or by drag-and-drop in the Kate window), it always opens first in the default UTF-8 encoding, and I have to reopen or reload it (F5) in order to convince it to open in UTF-16.
Comment 2 Piotr Keplicz 2009-05-26 10:05:44 UTC
I guess Kate needs some sort of automatic encoding choosing when opening a file through the file browser, command line or using a file picker with "Encoding" set to "automatic".

Using this "automatic" setting, Kate could choose the right encoding using the following criteria:
- check the file modeline,
- check the directory .kateconfig,
- check Kate configuration,
- use system-wide encoding through environment variables.
Comment 3 Dominik Haumann 2009-06-04 16:13:39 UTC
Reading the file's modeline before knowing its encoding is actually impossible.
Check .kateconfig and the Mode makes sense.

Via const KateFileType& KateModeManager::fileType(const QString &name) const; we can get the KateFileType and then the value for "encoding" (needs an additional query function). But this still does not check the .kateconfig.

The other way is, as soon as the encoding is known, reload the document again with the right encoding (if it was wrong).
Comment 4 Dominik Haumann 2009-06-04 23:33:34 UTC
*** Bug 135581 has been marked as a duplicate of this bug. ***
Comment 5 Dominik Haumann 2009-06-04 23:34:36 UTC
related bug for .kateconfig file: bug #125974
Comment 6 Dominik Haumann 2009-06-04 23:59:55 UTC
related bug for modes/filetypes: bug #159135
Comment 7 Michael Balzer 2010-03-29 15:18:20 UTC
I had exactly the same behaviour as Piotr in the beginning.

After some experiments I now have a new effect:

- After opening a file, the "Extras" menu now claims the encoding is "Unicode > utf7" (no typo, it's really utf_7_)
- BUT iso umlauts are a) displayed correctly and b) remain correct even after adding new umlauts & saving & reopening the file.

So it seems "katepart" somehow internally is actually now using the correct encoding but "kate" thinks it's utf7. Also no complains about wrong character codes when opening these files.

File type definition variables: "kate: encoding iso-8859-1;"
Other settings: 
- Open/Save common: Encoding "ISO 8859-1", autodetect off.
Comment 8 Michael Balzer 2010-03-29 15:23:48 UTC
(In reply to comment #7)
Kate Version 3.3.5
Unter KDE 4.3.5 (KDE 4.3.5) "release 0"
Kate-Komponente Version 3.3
Unter KDE 4.3.5 (KDE 4.3.5) "release 0"
Comment 9 Christoph Cullmann 2011-06-25 09:44:43 UTC
Git commit bd03d9a8302b9c98a7cf1aa389ea9e55c25d2db3 by Christoph Cullmann.
Committed on 25/06/2011 at 11:43.
Pushed by cullmann into branch 'master'.

no encoding: xxx variable support
it never worked, it cant work given the fact we eval all vars only after load
sorry, but the fixed encoding detection in KDE 4.5/.6 must be enough
BUG: 187033

M  +1    -7    doc/kate/configuring.docbook     
M  +0    -2    part/document/katedocument.cpp