Home Download Buy Blog Forum Support

text encoding

text encoding

Postby vim on Mon Nov 03, 2008 9:30 pm

is there a way to set default encoding (windows/unix/etc)? and for a specific language?
vim
 
Posts: 298
Joined: Tue May 27, 2008 6:51 pm

Re: text encoding

Postby vim on Mon Nov 24, 2008 1:06 pm

After digging a bit, i found the relevant sublime command is
'setLineEnding type', where type is 'unix|windows|mac'

Now I need to know if there is a way to set to default for new files, and if it can be done to a specific file type.

Help will be appreciated ;)
vim
 
Posts: 298
Joined: Tue May 27, 2008 6:51 pm

Re: text encoding

Postby vim on Wed Nov 26, 2008 3:30 pm

oh, thanks, great example. i did few changes:
Code: Select all
import sublime, sublimeplugin

LE_DEFAULTS = {u'Packages/Erlang/Erlang.tmLanguage':'unix'}

class DefaultLineEndingCommand(sublimeplugin.Plugin):
    def onPreSave(self, view):
        # get current syntax language
        syntax = view.options().get('syntax')
        # search if current syntax has a default line ending defined
        le = LE_DEFAULTS.get(syntax)
        # set the line ending if found a definition
        if le:
            view.runCommand('setLineEnding', [le])


the problem is, i wanted it to be invoked on new erlang files. the problem is that if i use onNew, the syntax is not yet set. and if i use onPreSave (as above) i can't manually override it, i.e. if i want to change it and set the line ending manually this plugin wil always override it when i save the file. what i really wanted is onSyntaxChange event...
vim
 
Posts: 298
Joined: Tue May 27, 2008 6:51 pm


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 19 guests

cron