Default encoding in Kate

To my best knowledge, there's no UI in Kate to set the default encoding used with new documents or documents opened by file association (eg. double-click on a text file in Konqueror or starting Kate from the command line). However Kate _has_ a logic for setting the default encoding. Smiling

The logic comes from the constructor of the KLocale class:

"The constructor looks for an entry Locale/Language in the configuration file. If no config file is specified, it will also look for languages using the environment variables (KDE_LANG, LC_MESSAGES, LC_ALL, LANG), as well as the global configuration file. If KLocale is not able to use any of the specified languages, the default language (en_US) will be used."

In the definition of this constructor you can find that it calls the initEncoding procedure, which is the following:
void KLocale::initEncoding(KConfig *)
{
  const int mibDefault = 4; // ISO 8859-1

  // This all made more sense when we still had the EncodingEnum config key.
  setEncoding( QTextCodec::codecForLocale()->mibEnum() );

  if ( !d->codecForEncoding )
    {
      kdWarning(173) << " Defaulting to ISO 8859-1 encoding." << endl;
      setEncoding(mibDefault);
    }

  Q_ASSERT( d->codecForEncoding );
}

My experience shows that the country/region selected in "System Settings" does not affect the default encoding at all. Setting the LANG environment variable does affect the default encoding, but there's an even better way: set the Encoding variable in your $HOME/.kde/share/config/katerc config file in the "[Kate Document Defaults]" section. Eg. setting this variable to ISO 8859-2 (note that there's no hyphen between the "ISO" string and the "8859" number!) or to UTF-8 will set your default encoding appropriately.

Syndicate content