Home Download Buy Blog Forum Support

Different encodings for different files extensions

Different encodings for different files extensions

Postby demonout on Wed Mar 20, 2013 1:56 pm

Hello!

I have, for example, file 1.p with enconding "KOI8-R". And I have file 2.txt with encoding "Windows 1251".

Is it a way to set for extension ".p" always open with encoding "KOI8-R", and for extension "txt" with "Windows 1251".

Sorry for my english. ))
demonout
 
Posts: 3
Joined: Wed Mar 20, 2013 1:46 pm

Re: Different encodings for different files extensions

Postby demonout on Fri Mar 22, 2013 3:34 pm

No solution for this question?
demonout
 
Posts: 3
Joined: Wed Mar 20, 2013 1:46 pm

Re: Different encodings for different files extensions

Postby skuroda on Fri Mar 22, 2013 7:17 pm

It's not built in, but you can write a simple plugin to do it. I would recommend taking a look at the ApplySyntax plugin as a guide. It does something very similar to what you want. It applies a particular syntax based on a variety of recognition methods. Rather than calling the "set_syntax_file" method, you would want to call the "set_encoding" method.

Hope that helps.
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am

Re: Different encodings for different files extensions

Postby qgates on Fri Mar 22, 2013 7:44 pm

At a guess, here's what you'd need to do:

You''ll need to make a copy of the "Plain Text" syntax type first. You can then make settings for your new syntax type with custom default character encoding, and assign certain file extensions to be opened with the new syntax type...

1. In your sublime profile folder (say c:\users\xxx\AppData\Roaming\Sublime Text 2\Packages) make a copy of the "Text" folder (this is the folder for "Plain Text" syntax type) and rename the folder copy to (say) "P Text".

2. Next open up a .p file and click bottom right to change syntax (where it says "Plain Text"). The big pop-up menu, choose "open all with current extension as...", and choose your new syntax type "P Text"

3. Finally, with a .p file open (and syntax as "P Text"), choose menu "Prefs..Settings more..Syntax specific".

Add the following lines to the empty syntax file and save it:

Code: Select all
{
    "default_encoding": "Cyrillic (KOI8-R)"
}


Give it a try and post back if it works!

S
qgates
 
Posts: 223
Joined: Mon Nov 05, 2012 4:33 pm

Re: Different encodings for different files extensions

Postby demonout on Tue Apr 09, 2013 4:15 pm

Thank qgates very much! It really works!!!
demonout
 
Posts: 3
Joined: Wed Mar 20, 2013 1:46 pm

Re: Different encodings for different files extensions

Postby DeepLifer on Wed Aug 14, 2013 9:05 am

Tnx for great solution, but i need to speak some words.
In my case, it works only with code:
Code: Select all
{
   "fallback_encoding": "Cyrillic (Windows 866)"
}

in syntax-specific file, i mean...
DeepLifer
 
Posts: 1
Joined: Wed Aug 14, 2013 9:00 am


Return to General Discussion

Who is online

Users browsing this forum: BugFix and 28 guests