Skip to content

Instantly share code, notes, and snippets.

@slimane
Last active December 23, 2015 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slimane/6603995 to your computer and use it in GitHub Desktop.
Save slimane/6603995 to your computer and use it in GitHub Desktop.
scriptencoding=utf-8
function! objects#font#New()
let font = {}
let font.name = ''
let font.encoding = 'DEFAULT'
let font.iconv_to = 'utf-8'
let font.size = 12
let font.options = ''
function! font.setName(name) dict
let self.name = a:name
endfunction
function! font.setEncoding(encoding) dict
let self.encoding = a:encoding
endfunction
function! font.setIconv_to(encoding) dict
let self.iconv_to = a:encoding
endfunction
function! font.setSize(size) dict
let self.size = string(a:size)
endfunction
function! font.setOptions(options) dict
let self.options = a:options
endfunction
function! font.setFont(font) dict
call self.setName(matchstr(a:font, '^\zs.*\ze:h'))
call self.setSize(matchstr(a:font, ':h\zs\d\+\ze'))
call self.setEncoding(matchstr(a:font, ':c\zs\w\+\ze'))
endfunction
function! font.format() dict
return self.name . ':h' . self.size . ':c' . self.encoding
\ . self.options
endfunction
function! font.getFont() dict
return iconv(self.format(), &encoding, self.iconv_to)
endfunction
return font
endfunction
function! objects#font#guiFont()
let guiFont = objects#font#New()
function! guiFont.apply() dict
let &guifont = self.getFont()
endfunction
return guiFont
endfunction
function! objects#font#guiFontWide()
let guiFontWide = objects#font#New()
function! guiFontWide.apply() dict
let &guifontwide = self.getFont()
endfunction
return guiFontWide
endfunction
" 使用例
let s:fontSize = 12
" guifont設定
let g:guifont = objects#font#guiFont()
call g:guifont.setName('uzura_font for Powerline')
call g:guifont.setName('Inconsolata_for_Powerline')
call g:guifont.setName('Source_Code_Pro_for_Powerline')
call g:guifont.setOptions(':b')
call g:guifont.setEncoding('DEFAULT')
call g:guifont.setSize(s:fontSize)
call g:guifont.apply()
" guifontwide設定
let g:guifontwide = objects#font#guiFontWide()
call g:guifontwide.setName('OhisamaFont for Powerline')
call g:guifontwide.setName('uzura_font for Powerline')
call g:guifontwide.setName('VL Gothic')
call g:guifontwide.setName('Osaka-等幅')
call g:guifontwide.setName('OhisamaFont for Powerline')
call g:guifontwide.setSize(s:fontSize)
call g:guifontwide.setOptions(':b')
call g:guifontwide.setIconv_to('cp932')
call g:guifontwide.apply()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment