├── LICENSE.txt ├── README.md ├── christmas-tree.txt ├── ftdetect └── christmastree.vim ├── ftplugin └── christmastree.vim ├── plugin └── christmastree.vim └── syntax └── christmastree.vim /LICENSE.txt: -------------------------------------------------------------------------------- 1 | the MIT License 2 | 3 | Copyright (c) 2018 rhysd 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 17 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR 20 | THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is a Vim plugin to show a christmas tree in Vim. 2 | 3 | ``` 4 | :MerryChristmas 5 | ``` 6 | 7 | ![screencast](https://github.com/rhysd/ss/blob/master/vim-syntax-christmas-tree/demo.gif?raw=true) 8 | 9 | The ascii art was prepared based on [Laura T's art](https://www.asciiart.eu/holiday-and-events/christmas/trees). 10 | 11 | This plugin was created for [my Japanese blog post](https://rhysd.hatenablog.com/entry/2018/12/23/235933) for [Vim Advent Calendar 2018](https://qiita.com/advent-calendar/2018/vim). 12 | -------------------------------------------------------------------------------- /christmas-tree.txt: -------------------------------------------------------------------------------- 1 | * ☆ * 2 | * .o * * 3 | * .*.'. 4 | .'.'o'. * 5 | * o'.*.'.o. 6 | * .'.o.'.'.*. * * 7 | * .*.'.o.'.o.'. * 8 | * o'.'.'.'*'.'.'. * 9 | * .'.'*'.'o'.'.'*'o * 10 | * [_____] * 11 | * \___/ * * 12 | 13 | Merry Christmas! 14 | -------------------------------------------------------------------------------- /ftdetect/christmastree.vim: -------------------------------------------------------------------------------- 1 | autocmd BufNewFile,BufReadPost christmas-tree.txt setlocal filetype=christmastree 2 | -------------------------------------------------------------------------------- /ftplugin/christmastree.vim: -------------------------------------------------------------------------------- 1 | if exists("b:did_ftplugin") 2 | finish 3 | endif 4 | let b:did_ftplugin = 1 5 | 6 | let s:seed = float2nr(reltimefloat(reltime())) 7 | function! s:rand() abort 8 | let s:seed = s:seed * 214013 + 2531011 9 | return (s:seed < 0 ? s:seed - 0x80000000 : s:seed) / 0x10000 % 0x8000 10 | endfunction 11 | 12 | let s:colors = [ 13 | \ 'christmastreeYellow', 14 | \ 'christmastreeRed', 15 | \ 'christmastreeOrange', 16 | \ 'christmastreeGold', 17 | \ 'christmastreeWhite', 18 | \ 'christmastreePurple', 19 | \ 'christmastreeSkyblue', 20 | \ 'christmastreePink', 21 | \ 'christmastreeLight', 22 | \ 'Ignore', 23 | \ ] 24 | 25 | function! s:christmas_glitter_tick(timer) abort 26 | if !exists('s:timer_id') 27 | call timer_stop(a:timer) 28 | return 29 | endif 30 | 31 | let small = s:colors[s:rand() % len(s:colors)] 32 | execute 'hi link christmastreeGlitterSmall' small 33 | 34 | let large = s:colors[s:rand() % len(s:colors)] 35 | execute 'hi link christmastreeGlitterLarge' large 36 | endfunction 37 | 38 | function! s:christmas_glitter_start() abort 39 | if exists('s:timer_id') 40 | return 41 | endif 42 | let s:timer_id = timer_start(1000, function('s:christmas_glitter_tick'), {'repeat': -1}) 43 | endfunction 44 | 45 | function! s:christmas_glitter_stop() abort 46 | if !exists('s:timer_id') 47 | return 48 | endif 49 | call timer_stop(s:timer_id) 50 | unlet! s:timer_id 51 | endfunction 52 | 53 | if get(g:, 'christmastree_glitter_update', 1) 54 | augroup ChristmasTreeTimer 55 | autocmd! 56 | autocmd BufWinEnter call christmas_glitter_start() 57 | autocmd BufWinLeave call christmas_glitter_stop() 58 | augroup END 59 | endif 60 | 61 | command! -nargs=0 -bar -buffer ChristmasTreeTurnOn call christmas_glitter_start() 62 | command! -nargs=0 -bar -buffer ChristmasTreeTurnOff call christmas_glitter_stop() 63 | -------------------------------------------------------------------------------- /plugin/christmastree.vim: -------------------------------------------------------------------------------- 1 | if (exists('g:loaded_christmastree') && g:loaded_christmastree) || &cp 2 | finish 3 | endif 4 | 5 | let s:tree_file = fnamemodify(expand(''), ':p:h:h') . '/christmas-tree.txt' 6 | 7 | function! s:open() abort 8 | execute 'botright vertical sview' s:tree_file 9 | setlocal nomodifiable 10 | wincmd p 11 | endfunction 12 | command! -nargs=0 -bar MerryChristmas call open() 13 | 14 | let g:loaded_christmastree = 1 15 | -------------------------------------------------------------------------------- /syntax/christmastree.vim: -------------------------------------------------------------------------------- 1 | if exists("b:current_syntax") 2 | finish 3 | endif 4 | 5 | setlocal background=dark 6 | 7 | syn cluster christmastreeGlitters contains=christmastreeGlitterSmall,christmastreeGlitterLarge 8 | syn match christmastreeStar /☆/ 9 | syn region christmastreeLeaves start=/\s\@<=[o.]/ end=/[o.]\%(\s\|\_$\)\@=/ contains=@christmastreeGlitters oneline keepend 10 | syn match christmastreeGlitterLarge /o/ contained containedin=christmastreeLeaves 11 | syn match christmastreeGlitterSmall /\*/ contained containedin=christmastreeLeaves 12 | syn match christmastreeFlowerpot /\[_\+\]/ 13 | syn match christmastreeFlowerpot /\\_\+\// 14 | syn match christmastreeSnow /\*/ containedin=NONE 15 | 16 | hi def christmastreeYellow term=NONE ctermfg=226 guifg=yellow 17 | hi def christmastreeGreen term=NONE ctermfg=47 guifg=lightgreen 18 | hi def christmastreeRed term=NONE ctermfg=196 guifg=red 19 | hi def christmastreeBrown term=NONE ctermfg=173 guifg=#bf8040 20 | hi def christmastreeGold term=NONE ctermfg=220 guifg=gold 21 | hi def christmastreeWhite term=NONE ctermfg=254 guifg=white 22 | hi def christmastreePurple term=NONE ctermfg=147 guifg=purple 23 | hi def christmastreeSkyblue term=NONE ctermfg=117 guifg=skyblue 24 | hi def christmastreePink term=NONE ctermfg=168 guifg=pink 25 | hi def christmastreeLight term=NONE ctermfg=229 guifg=lightyellow 26 | hi def christmastreeOrange term=NONE ctermfg=208 guifg=orange 27 | 28 | hi def link christmastreeStar christmastreeYellow 29 | hi def link christmastreeLeaves christmastreeGreen 30 | hi def link christmastreeGlitterSmall christmastreeRed 31 | hi def link christmastreeGlitterLarge christmastreeGold 32 | hi def link christmastreeFlowerpot christmastreeBrown 33 | hi def link christmastreeSnow christmastreeWhite 34 | 35 | let b:current_syntax = "christmastree" 36 | --------------------------------------------------------------------------------