├── README.md ├── doc └── coffee-script.txt ├── .netrwhist ├── autoload ├── emmet │ ├── lang.vim │ ├── lorem │ │ ├── ja.vim │ │ └── en.vim │ ├── lang │ │ ├── scss.vim │ │ ├── sass.vim │ │ ├── css.vim │ │ ├── slim.vim │ │ └── haml.vim │ └── util.vim ├── project.vim ├── coffee.vim └── ctrlp │ ├── quickfix.vim │ ├── rtscript.vim │ ├── line.vim │ ├── mixed.vim │ ├── changes.vim │ ├── dir.vim │ ├── utils.vim │ ├── tag.vim │ ├── bookmarkdir.vim │ ├── undo.vim │ ├── mrufiles.vim │ └── buffertag.vim ├── compiler ├── cake.vim └── coffee.vim ├── after ├── syntax │ ├── html.vim │ └── haml.vim └── indent │ └── html.vim ├── .vimrc ├── ftdetect └── coffee.vim ├── syntax ├── project.vim ├── nerdtree.vim └── coffee.vim ├── nerdtree_plugin ├── exec_menuitem.vim └── fs_menu.vim ├── plugin ├── ctrlp.vim ├── emmet.vim └── NERD_tree.vim ├── lib └── nerdtree │ ├── menu_item.vim │ ├── key_map.vim │ ├── menu_controller.vim │ ├── opener.vim │ ├── creator.vim │ └── bookmark.vim └── ftplugin └── coffee.vim /README.md: -------------------------------------------------------------------------------- 1 | # instructions 2 | git clone https://github.com/gmx/vplugins.git 3 | mv ./vplugins ~/.vim 4 | cp ./vim/.vimrc ~/.vimrc 5 | -------------------------------------------------------------------------------- /doc/coffee-script.txt: -------------------------------------------------------------------------------- 1 | Please see the project readme for up-to-date docs: 2 | https://github.com/kchmck/vim-coffee-script 3 | 4 | vim:tw=78:ts=8:ft=help:norl: 5 | -------------------------------------------------------------------------------- /.netrwhist: -------------------------------------------------------------------------------- 1 | let g:netrw_dirhistmax =10 2 | let g:netrw_dirhist_cnt =4 3 | let g:netrw_dirhist_1='/home/gmx/Documents' 4 | let g:netrw_dirhist_2='/home/gmx/Projects/RonetzSchool/vendor/bin/app/tests/acceptance' 5 | let g:netrw_dirhist_3='/home/gmx/Desktop/unicef/hr' 6 | let g:netrw_dirhist_4='/home/gmx/Desktop/unicef/hr/villageTracts.csv' 7 | -------------------------------------------------------------------------------- /autoload/emmet/lang.vim: -------------------------------------------------------------------------------- 1 | let s:exists = {} 2 | function! emmet#lang#exists(type) 3 | if len(a:type) == 0 4 | return 0 5 | elseif has_key(s:exists, a:type) 6 | return s:exists[a:type] 7 | endif 8 | let s:exists[a:type] = len(globpath(&rtp, 'autoload/emmet/lang/'.a:type.'.vim')) > 0 9 | return s:exists[a:type] 10 | endfunction 11 | 12 | -------------------------------------------------------------------------------- /compiler/cake.vim: -------------------------------------------------------------------------------- 1 | " Language: CoffeeScript 2 | " Maintainer: Mick Koch 3 | " URL: http://github.com/kchmck/vim-coffee-script 4 | " License: WTFPL 5 | 6 | if exists('current_compiler') 7 | finish 8 | endif 9 | 10 | let current_compiler = 'cake' 11 | call coffee#CoffeeSetUpVariables() 12 | 13 | exec 'CompilerSet makeprg=' . escape(g:coffee_cake . ' ' . 14 | \ g:coffee_cake_options . ' $*', ' ') 15 | call coffee#CoffeeSetUpErrorFormat() 16 | -------------------------------------------------------------------------------- /after/syntax/html.vim: -------------------------------------------------------------------------------- 1 | " Language: CoffeeScript 2 | " Maintainer: Mick Koch 3 | " URL: http://github.com/kchmck/vim-coffee-script 4 | " License: WTFPL 5 | 6 | " Syntax highlighting for text/coffeescript script tags 7 | syn include @htmlCoffeeScript syntax/coffee.vim 8 | syn region coffeeScript start=##me=s-1 keepend 10 | \ contains=@htmlCoffeeScript,htmlScriptTag,@htmlPreproc 11 | \ containedin=htmlHead 12 | -------------------------------------------------------------------------------- /.vimrc: -------------------------------------------------------------------------------- 1 | let g:project_use_nerdtree = 1 2 | 3 | Project '/home/gmx/Desktop/tcAdmin/admin2', 'admin2' 4 | Project '/home/gmx/Desktop/unicef/hr', 'hr' 5 | Project '/home/gmx/Desktop/unicef/api', 'api' 6 | Project '/home/gmx/Desktop/unicef/frontend', 'frontend' 7 | 8 | set number 9 | set guifont=Monaco\ 11 10 | set guioptions-=T 11 | set guioptions-=r 12 | 13 | set smartindent 14 | set shiftwidth=4 15 | set tabstop=4 16 | set tabline=4 17 | 18 | set autoindent 19 | 20 | inoremap jk 21 | let mapleader = "," 22 | 23 | let g:ctrlp_map = '' 24 | let g:ctrlp_cmd = 'CtrlP' 25 | 26 | colorscheme desert 27 | -------------------------------------------------------------------------------- /ftdetect/coffee.vim: -------------------------------------------------------------------------------- 1 | " Language: CoffeeScript 2 | " Maintainer: Mick Koch 3 | " URL: http://github.com/kchmck/vim-coffee-script 4 | " License: WTFPL 5 | 6 | autocmd BufNewFile,BufRead *.coffee set filetype=coffee 7 | autocmd BufNewFile,BufRead *Cakefile set filetype=coffee 8 | autocmd BufNewFile,BufRead *.coffeekup,*.ck set filetype=coffee 9 | autocmd BufNewFile,BufRead *._coffee set filetype=coffee 10 | 11 | function! s:DetectCoffee() 12 | if getline(1) =~ '^#!.*\' 13 | set filetype=coffee 14 | endif 15 | endfunction 16 | 17 | autocmd BufNewFile,BufRead * call s:DetectCoffee() 18 | -------------------------------------------------------------------------------- /after/syntax/haml.vim: -------------------------------------------------------------------------------- 1 | " Language: CoffeeScript 2 | " Maintainer: Sven Felix Oberquelle 3 | " URL: http://github.com/kchmck/vim-coffee-script 4 | " License: WTFPL 5 | 6 | " Inherit coffee from html so coffeeComment isn't redefined and given higher 7 | " priority than hamlInterpolation. 8 | syn cluster hamlCoffeescript contains=@htmlCoffeeScript 9 | syn region hamlCoffeescriptFilter matchgroup=hamlFilter 10 | \ start="^\z(\s*\):coffee\z(script\)\?\s*$" 11 | \ end="^\%(\z1 \| *$\)\@!" 12 | \ contains=@hamlCoffeeScript,hamlInterpolation 13 | \ keepend 14 | -------------------------------------------------------------------------------- /autoload/project.vim: -------------------------------------------------------------------------------- 1 | command! -nargs=+ Project 2 | \ call project#config#project() 3 | 4 | command! -nargs=+ File 5 | \ call project#config#title() 6 | 7 | command! -nargs=+ Callback 8 | \ call project#config#callback() 9 | 10 | command! -complete=file -nargs=+ ProjectPath 11 | \ call project#config#project_path() 12 | 13 | command! -nargs=0 -bar Welcome 14 | \ enew | call project#config#welcome() 15 | 16 | if has("gui_running") 17 | function! TabTitle() 18 | let title = expand("%:p:t") 19 | let t:title = exists("b:title") ? b:title : title 20 | endfunction 21 | 22 | au VimEnter * set guitablabel=%-2.2N%{gettabvar(v:lnum,'title')} 23 | set title 24 | endif 25 | 26 | if get(g:, 'project_enable_welcome', 1) 27 | au VimEnter * 28 | \ if !argc() && (line2byte('$') == -1) && (v:progname =~? '^[gm]\=vim\%[\.exe]$') | 29 | \ call project#config#welcome() | 30 | \ endif 31 | endif 32 | 33 | function! project#rc(...) abort 34 | let g:project_dir = len(a:000) > 0 ? expand(a:1, 1) : expand('$HOME', 1) 35 | endfunction 36 | -------------------------------------------------------------------------------- /syntax/project.vim: -------------------------------------------------------------------------------- 1 | if exists("b:current_syntax") 2 | finish 3 | endif 4 | 5 | let s:sep = project#config#get_sep() 6 | 7 | execute 'syntax match ProjectTitle /\%9c\S\+/' 8 | syntax match ProjectSpecial /\V\|/ 9 | syntax match ProjectBracket /\[\|\]/ 10 | syntax match ProjectNumber /\v\[[eq[:digit:]]+\]/hs=s+1,he=e-1 contains=ProjectBracket 11 | syntax match ProjectFile /.*/ contains=ProjectBracket,ProjectNumber,ProjectTitle,ProjectPath,ProjectSpecial,ProjectUnit 12 | syntax match ProjectUnit /.:/ 13 | 14 | execute 'syntax match ProjectSlash /\'. s:sep .'/' 15 | execute 'syntax match ProjectPath /\'. s:sep . '.*\' . s:sep .'/ contains=ProjectSlash' 16 | 17 | highlight projectPath ctermfg=11 ctermbg=8 guifg=#586e75 18 | highlight link ProjectFile String 19 | highlight link ProjectBracket Normal 20 | highlight link ProjectNumber Directory 21 | highlight link ProjectPath projectPath 22 | highlight link ProjectUnit projectPath 23 | highlight link ProjectTitle Statement 24 | highlight link ProjectSpecial String 25 | 26 | 27 | let b:current_syntax = 'project' 28 | 29 | " vim: et sw=2 sts=2 30 | -------------------------------------------------------------------------------- /autoload/emmet/lorem/ja.vim: -------------------------------------------------------------------------------- 1 | scriptencoding utf-8 2 | 3 | function! emmet#lorem#ja#expand(command) 4 | let wcount = matchstr(a:command, '^\%(lorem\|lipsum\)\(\d*\)}$', '\1', '') 5 | let wcount = wcount > 0 ? wcount : 30 6 | 7 | let url = "http://www.aozora.gr.jp/cards/000081/files/470_15407.html" 8 | let content = emmet#util#cache(url) 9 | if len(content) == 0 10 | let content = emmet#util#getContentFromURL(url) 11 | let content = matchstr(content, ']*>\zs.\{-}') 12 | let content = substitute(content, '[ \r]', '', 'g') 13 | let content = substitute(content, ']*>', "\n", 'g') 14 | let content = substitute(content, '<[^>]\+>', '', 'g') 15 | let content = join(filter(split(content, "\n"), 'len(v:val)>0'), "\n") 16 | call emmet#util#cache(url, content) 17 | endif 18 | 19 | let content = substitute(content, "、\n", "、", "g") 20 | let clines = split(content, '\n') 21 | let lines = filter(clines, 'len(substitute(v:val,".",".","g"))<=wcount') 22 | if len(lines) == 0 23 | let lines = clines 24 | endif 25 | let r = emmet#util#rand() 26 | return lines[r % len(lines)] 27 | endfunction 28 | -------------------------------------------------------------------------------- /after/indent/html.vim: -------------------------------------------------------------------------------- 1 | " Language: CoffeeScript 2 | " Maintainer: Mick Koch 3 | " URL: http://github.com/kchmck/vim-coffee-script 4 | " License: WTFPL 5 | 6 | " Load the coffee and html indent functions. 7 | silent! unlet b:did_indent 8 | runtime indent/coffee.vim 9 | let s:coffeeIndentExpr = &l:indentexpr 10 | 11 | " Load html last so it can overwrite coffee settings. 12 | silent! unlet b:did_indent 13 | runtime indent/html.vim 14 | let s:htmlIndentExpr = &l:indentexpr 15 | 16 | " Inject our wrapper indent function. 17 | setlocal indentexpr=GetCoffeeHtmlIndent(v:lnum) 18 | 19 | function! GetCoffeeHtmlIndent(curlinenum) 20 | " See if we're inside a coffeescript block. 21 | let scriptlnum = searchpair('', 'bWn') 23 | let prevlnum = prevnonblank(a:curlinenum) 24 | 25 | " If we're in the script block and the previous line isn't the script tag 26 | " itself, use coffee indenting. 27 | if scriptlnum && scriptlnum != prevlnum 28 | exec 'return ' s:coffeeIndentExpr 29 | endif 30 | 31 | " Otherwise use html indenting. 32 | exec 'return ' s:htmlIndentExpr 33 | endfunction 34 | -------------------------------------------------------------------------------- /autoload/coffee.vim: -------------------------------------------------------------------------------- 1 | " Language: CoffeeScript 2 | " Maintainer: Mick Koch 3 | " URL: http://github.com/kchmck/vim-coffee-script 4 | " License: WTFPL 5 | 6 | " Set up some common global/buffer variables. 7 | function! coffee#CoffeeSetUpVariables() 8 | " Path to coffee executable 9 | if !exists('g:coffee_compiler') 10 | let g:coffee_compiler = 'coffee' 11 | endif 12 | 13 | " Options passed to coffee with make 14 | if !exists('g:coffee_make_options') 15 | let g:coffee_make_options = '' 16 | endif 17 | 18 | " Path to cake executable 19 | if !exists('g:coffee_cake') 20 | let g:coffee_cake = 'cake' 21 | endif 22 | 23 | " Extra options passed to cake 24 | if !exists('g:coffee_cake_options') 25 | let g:coffee_cake_options = '' 26 | endif 27 | 28 | " Path to coffeelint executable 29 | if !exists('g:coffee_linter') 30 | let g:coffee_linter = 'coffeelint' 31 | endif 32 | 33 | " Options passed to CoffeeLint 34 | if !exists('g:coffee_lint_options') 35 | let g:coffee_lint_options = '' 36 | endif 37 | 38 | " Pass the litcoffee flag to tools in this buffer if a litcoffee file is open. 39 | " Let the variable be overwritten so it can be updated if a different filetype 40 | " is set. 41 | if &filetype == 'litcoffee' 42 | let b:coffee_litcoffee = '--literate' 43 | else 44 | let b:coffee_litcoffee = '' 45 | endif 46 | endfunction 47 | 48 | function! coffee#CoffeeSetUpErrorFormat() 49 | CompilerSet errorformat=Error:\ In\ %f\\,\ %m\ on\ line\ %l, 50 | \Error:\ In\ %f\\,\ Parse\ error\ on\ line\ %l:\ %m, 51 | \SyntaxError:\ In\ %f\\,\ %m, 52 | \%f:%l:%c:\ error:\ %m, 53 | \%-G%.%# 54 | endfunction 55 | -------------------------------------------------------------------------------- /nerdtree_plugin/exec_menuitem.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================ 2 | " File: exec_menuitem.vim 3 | " Description: plugin for NERD Tree that provides an execute file menu item 4 | " Maintainer: Martin Grenfell 5 | " Last Change: 22 July, 2009 6 | " License: This program is free software. It comes without any warranty, 7 | " to the extent permitted by applicable law. You can redistribute 8 | " it and/or modify it under the terms of the Do What The Fuck You 9 | " Want To Public License, Version 2, as published by Sam Hocevar. 10 | " See http://sam.zoy.org/wtfpl/COPYING for more details. 11 | " 12 | " ============================================================================ 13 | if exists("g:loaded_nerdtree_exec_menuitem") 14 | finish 15 | endif 16 | let g:loaded_nerdtree_exec_menuitem = 1 17 | 18 | call NERDTreeAddMenuItem({ 19 | \ 'text': '(!)Execute file', 20 | \ 'shortcut': '!', 21 | \ 'callback': 'NERDTreeExecFile', 22 | \ 'isActiveCallback': 'NERDTreeExecFileActive' }) 23 | 24 | function! NERDTreeExecFileActive() 25 | let node = g:NERDTreeFileNode.GetSelected() 26 | return !node.path.isDirectory && node.path.isExecutable 27 | endfunction 28 | 29 | function! NERDTreeExecFile() 30 | let treenode = g:NERDTreeFileNode.GetSelected() 31 | echo "==========================================================\n" 32 | echo "Complete the command to execute (add arguments etc):\n" 33 | let cmd = treenode.path.str({'escape': 1}) 34 | let cmd = input(':!', cmd . ' ') 35 | 36 | if cmd != '' 37 | exec ':!' . cmd 38 | else 39 | echo "Aborted" 40 | endif 41 | endfunction 42 | -------------------------------------------------------------------------------- /autoload/ctrlp/quickfix.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================= 2 | " File: autoload/ctrlp/quickfix.vim 3 | " Description: Quickfix extension 4 | " Author: Kien Nguyen 5 | " ============================================================================= 6 | 7 | " Init {{{1 8 | if exists('g:loaded_ctrlp_quickfix') && g:loaded_ctrlp_quickfix 9 | fini 10 | en 11 | let g:loaded_ctrlp_quickfix = 1 12 | 13 | cal add(g:ctrlp_ext_vars, { 14 | \ 'init': 'ctrlp#quickfix#init()', 15 | \ 'accept': 'ctrlp#quickfix#accept', 16 | \ 'lname': 'quickfix', 17 | \ 'sname': 'qfx', 18 | \ 'type': 'line', 19 | \ 'sort': 0, 20 | \ 'nolim': 1, 21 | \ }) 22 | 23 | let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) 24 | 25 | fu! s:lineout(dict) 26 | retu printf('%s|%d:%d| %s', bufname(a:dict['bufnr']), a:dict['lnum'], 27 | \ a:dict['col'], matchstr(a:dict['text'], '\s*\zs.*\S')) 28 | endf 29 | " Utilities {{{1 30 | fu! s:syntax() 31 | if !ctrlp#nosy() 32 | cal ctrlp#hicheck('CtrlPqfLineCol', 'Search') 33 | sy match CtrlPqfLineCol '|\zs\d\+:\d\+\ze|' 34 | en 35 | endf 36 | " Public {{{1 37 | fu! ctrlp#quickfix#init() 38 | cal s:syntax() 39 | retu map(getqflist(), 's:lineout(v:val)') 40 | endf 41 | 42 | fu! ctrlp#quickfix#accept(mode, str) 43 | let vals = matchlist(a:str, '^\([^|]\+\ze\)|\(\d\+\):\(\d\+\)|') 44 | if vals == [] || vals[1] == '' | retu | en 45 | cal ctrlp#acceptfile(a:mode, vals[1]) 46 | let cur_pos = getpos('.')[1:2] 47 | if cur_pos != [1, 1] && cur_pos != map(vals[2:3], 'str2nr(v:val)') 48 | mark ' 49 | en 50 | cal cursor(vals[2], vals[3]) 51 | sil! norm! zvzz 52 | endf 53 | 54 | fu! ctrlp#quickfix#id() 55 | retu s:id 56 | endf 57 | "}}} 58 | 59 | " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 60 | -------------------------------------------------------------------------------- /autoload/ctrlp/rtscript.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================= 2 | " File: autoload/ctrlp/rtscript.vim 3 | " Description: Runtime scripts extension 4 | " Author: Kien Nguyen 5 | " ============================================================================= 6 | 7 | " Init {{{1 8 | if exists('g:loaded_ctrlp_rtscript') && g:loaded_ctrlp_rtscript 9 | fini 10 | en 11 | let [g:loaded_ctrlp_rtscript, g:ctrlp_newrts] = [1, 0] 12 | 13 | cal add(g:ctrlp_ext_vars, { 14 | \ 'init': 'ctrlp#rtscript#init(s:caching)', 15 | \ 'accept': 'ctrlp#acceptfile', 16 | \ 'lname': 'runtime scripts', 17 | \ 'sname': 'rts', 18 | \ 'type': 'path', 19 | \ 'opmul': 1, 20 | \ }) 21 | 22 | let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) 23 | 24 | let s:filecounts = {} 25 | " Utilities {{{1 26 | fu! s:nocache() 27 | retu g:ctrlp_newrts || 28 | \ !s:caching || ( s:caching > 1 && get(s:filecounts, s:cwd) < s:caching ) 29 | endf 30 | " Public {{{1 31 | fu! ctrlp#rtscript#init(caching) 32 | let [s:caching, s:cwd] = [a:caching, getcwd()] 33 | if s:nocache() || 34 | \ !( exists('g:ctrlp_rtscache') && g:ctrlp_rtscache[0] == &rtp ) 35 | sil! cal ctrlp#progress('Indexing...') 36 | let entries = split(globpath(ctrlp#utils#fnesc(&rtp, 'g'), '**/*.*'), "\n") 37 | cal filter(entries, 'count(entries, v:val) == 1') 38 | let [entries, echoed] = [ctrlp#dirnfile(entries)[1], 1] 39 | el 40 | let [entries, results] = g:ctrlp_rtscache[2:3] 41 | en 42 | if s:nocache() || 43 | \ !( exists('g:ctrlp_rtscache') && g:ctrlp_rtscache[:1] == [&rtp, s:cwd] ) 44 | if !exists('echoed') 45 | sil! cal ctrlp#progress('Processing...') 46 | en 47 | let results = map(copy(entries), 'fnamemodify(v:val, '':.'')') 48 | en 49 | let [g:ctrlp_rtscache, g:ctrlp_newrts] = [[&rtp, s:cwd, entries, results], 0] 50 | cal extend(s:filecounts, { s:cwd : len(results) }) 51 | retu results 52 | endf 53 | 54 | fu! ctrlp#rtscript#id() 55 | retu s:id 56 | endf 57 | "}}} 58 | 59 | " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 60 | -------------------------------------------------------------------------------- /autoload/ctrlp/line.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================= 2 | " File: autoload/ctrlp/line.vim 3 | " Description: Line extension 4 | " Author: Kien Nguyen 5 | " ============================================================================= 6 | 7 | " Init {{{1 8 | if exists('g:loaded_ctrlp_line') && g:loaded_ctrlp_line 9 | fini 10 | en 11 | let g:loaded_ctrlp_line = 1 12 | 13 | cal add(g:ctrlp_ext_vars, { 14 | \ 'init': 'ctrlp#line#init(s:crbufnr)', 15 | \ 'accept': 'ctrlp#line#accept', 16 | \ 'lname': 'lines', 17 | \ 'sname': 'lns', 18 | \ 'type': 'tabe', 19 | \ }) 20 | 21 | let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) 22 | " Utilities {{{1 23 | fu! s:syntax() 24 | if !ctrlp#nosy() 25 | cal ctrlp#hicheck('CtrlPBufName', 'Directory') 26 | cal ctrlp#hicheck('CtrlPTabExtra', 'Comment') 27 | sy match CtrlPBufName '\t|\zs[^|]\+\ze|\d\+:\d\+|$' 28 | sy match CtrlPTabExtra '\zs\t.*\ze$' contains=CtrlPBufName 29 | en 30 | endf 31 | " Public {{{1 32 | fu! ctrlp#line#init(bufnr) 33 | let [lines, bufnr] = [[], exists('s:bufnr') ? s:bufnr : a:bufnr] 34 | let bufs = exists('s:lnmode') && s:lnmode ? ctrlp#buffers('id') : [bufnr] 35 | for bufnr in bufs 36 | let [lfb, bufn] = [getbufline(bufnr, 1, '$'), bufname(bufnr)] 37 | if lfb == [] && bufn != '' 38 | let lfb = ctrlp#utils#readfile(fnamemodify(bufn, ':p')) 39 | en 40 | cal map(lfb, 'tr(v:val, '' '', '' '')') 41 | let [linenr, len_lfb] = [1, len(lfb)] 42 | let buft = bufn == '' ? '[No Name]' : fnamemodify(bufn, ':t') 43 | wh linenr <= len_lfb 44 | let lfb[linenr - 1] .= ' |'.buft.'|'.bufnr.':'.linenr.'|' 45 | let linenr += 1 46 | endw 47 | cal extend(lines, filter(lfb, 'v:val !~ ''^\s*\t|[^|]\+|\d\+:\d\+|$''')) 48 | endfo 49 | cal s:syntax() 50 | retu lines 51 | endf 52 | 53 | fu! ctrlp#line#accept(mode, str) 54 | let info = matchlist(a:str, '\t|[^|]\+|\(\d\+\):\(\d\+\)|$') 55 | let bufnr = str2nr(get(info, 1)) 56 | if bufnr 57 | cal ctrlp#acceptfile(a:mode, bufnr, get(info, 2)) 58 | en 59 | endf 60 | 61 | fu! ctrlp#line#cmd(mode, ...) 62 | let s:lnmode = a:mode 63 | if a:0 && !empty(a:1) 64 | let s:lnmode = 0 65 | let bname = a:1 =~# '^%$\|^#\d*$' ? expand(a:1) : a:1 66 | let s:bufnr = bufnr('^'.fnamemodify(bname, ':p').'$') 67 | en 68 | retu s:id 69 | endf 70 | "}}} 71 | 72 | " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 73 | -------------------------------------------------------------------------------- /plugin/ctrlp.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================= 2 | " File: plugin/ctrlp.vim 3 | " Description: Fuzzy file, buffer, mru, tag, etc finder. 4 | " Author: Kien Nguyen 5 | " ============================================================================= 6 | " GetLatestVimScripts: 3736 1 :AutoInstall: ctrlp.zip 7 | 8 | if ( exists('g:loaded_ctrlp') && g:loaded_ctrlp ) || v:version < 700 || &cp 9 | fini 10 | en 11 | let g:loaded_ctrlp = 1 12 | 13 | let [g:ctrlp_lines, g:ctrlp_allfiles, g:ctrlp_alltags, g:ctrlp_alldirs, 14 | \ g:ctrlp_allmixes, g:ctrlp_buftags, g:ctrlp_ext_vars, g:ctrlp_builtins] 15 | \ = [[], [], [], [], {}, {}, [], 2] 16 | 17 | if !exists('g:ctrlp_map') | let g:ctrlp_map = '' | en 18 | if !exists('g:ctrlp_cmd') | let g:ctrlp_cmd = 'CtrlP' | en 19 | 20 | com! -n=? -com=dir CtrlP cal ctrlp#init(0, { 'dir': }) 21 | com! -n=? -com=dir CtrlPMRUFiles cal ctrlp#init(2, { 'dir': }) 22 | 23 | com! -bar CtrlPBuffer cal ctrlp#init(1) 24 | com! -n=? CtrlPLastMode cal ctrlp#init(-1, { 'args': }) 25 | 26 | com! -bar CtrlPClearCache cal ctrlp#clr() 27 | com! -bar CtrlPClearAllCaches cal ctrlp#clra() 28 | 29 | com! -bar ClearCtrlPCache cal ctrlp#clr() 30 | com! -bar ClearAllCtrlPCaches cal ctrlp#clra() 31 | 32 | com! -bar CtrlPCurWD cal ctrlp#init(0, { 'mode': '' }) 33 | com! -bar CtrlPCurFile cal ctrlp#init(0, { 'mode': 'c' }) 34 | com! -bar CtrlPRoot cal ctrlp#init(0, { 'mode': 'r' }) 35 | 36 | if g:ctrlp_map != '' && !hasmapto(':'.g:ctrlp_cmd.'', 'n') 37 | exe 'nn ' g:ctrlp_map ':'.g:ctrlp_cmd.'' 38 | en 39 | 40 | cal ctrlp#mrufiles#init() 41 | 42 | com! -bar CtrlPTag cal ctrlp#init(ctrlp#tag#id()) 43 | com! -bar CtrlPQuickfix cal ctrlp#init(ctrlp#quickfix#id()) 44 | 45 | com! -n=? -com=dir CtrlPDir 46 | \ cal ctrlp#init(ctrlp#dir#id(), { 'dir': }) 47 | 48 | com! -n=? -com=buffer CtrlPBufTag 49 | \ cal ctrlp#init(ctrlp#buffertag#cmd(0, )) 50 | 51 | com! -bar CtrlPBufTagAll cal ctrlp#init(ctrlp#buffertag#cmd(1)) 52 | com! -bar CtrlPRTS cal ctrlp#init(ctrlp#rtscript#id()) 53 | com! -bar CtrlPUndo cal ctrlp#init(ctrlp#undo#id()) 54 | 55 | com! -n=? -com=buffer CtrlPLine 56 | \ cal ctrlp#init(ctrlp#line#cmd(1, )) 57 | 58 | com! -n=? -com=buffer CtrlPChange 59 | \ cal ctrlp#init(ctrlp#changes#cmd(0, )) 60 | 61 | com! -bar CtrlPChangeAll cal ctrlp#init(ctrlp#changes#cmd(1)) 62 | com! -bar CtrlPMixed cal ctrlp#init(ctrlp#mixed#id()) 63 | com! -bar CtrlPBookmarkDir cal ctrlp#init(ctrlp#bookmarkdir#id()) 64 | 65 | com! -n=? -com=dir CtrlPBookmarkDirAdd 66 | \ cal ctrlp#call('ctrlp#bookmarkdir#add', ) 67 | 68 | " vim:ts=2:sw=2:sts=2 69 | -------------------------------------------------------------------------------- /compiler/coffee.vim: -------------------------------------------------------------------------------- 1 | " Language: CoffeeScript 2 | " Maintainer: Mick Koch 3 | " URL: http://github.com/kchmck/vim-coffee-script 4 | " License: WTFPL 5 | 6 | " All this is needed to support compiling filenames with spaces, quotes, and 7 | " such. The filename is escaped and embedded into the `makeprg` setting. 8 | " 9 | " Because of this, `makeprg` must be updated on every file rename. And because 10 | " of that, `CompilerSet` can't be used because it doesn't exist when the 11 | " rename autocmd is ran. So, we have to do some checks to see whether `compiler` 12 | " was called locally or globally, and respect that in the rest of the script. 13 | 14 | if exists('current_compiler') 15 | finish 16 | endif 17 | 18 | let current_compiler = 'coffee' 19 | call coffee#CoffeeSetUpVariables() 20 | 21 | " Pattern to check if coffee is the compiler 22 | let s:pat = '^' . current_compiler 23 | 24 | " Get a `makeprg` for the current filename. 25 | function! s:GetMakePrg() 26 | return g:coffee_compiler . 27 | \ ' -c' . 28 | \ ' ' . b:coffee_litcoffee . 29 | \ ' ' . g:coffee_make_options . 30 | \ ' $*' . 31 | \ ' ' . fnameescape(expand('%')) 32 | endfunction 33 | 34 | " Set `makeprg` and return 1 if coffee is still the compiler, else return 0. 35 | function! s:SetMakePrg() 36 | if &l:makeprg =~ s:pat 37 | let &l:makeprg = s:GetMakePrg() 38 | elseif &g:makeprg =~ s:pat 39 | let &g:makeprg = s:GetMakePrg() 40 | else 41 | return 0 42 | endif 43 | 44 | return 1 45 | endfunction 46 | 47 | " Set a dummy compiler so we can check whether to set locally or globally. 48 | exec 'CompilerSet makeprg=' . current_compiler 49 | " Then actually set the compiler. 50 | call s:SetMakePrg() 51 | call coffee#CoffeeSetUpErrorFormat() 52 | 53 | function! s:CoffeeMakeDeprecated(bang, args) 54 | echoerr 'CoffeeMake is deprecated! Please use :make instead, its behavior ' . 55 | \ 'is identical.' 56 | sleep 5 57 | exec 'make' . a:bang a:args 58 | endfunction 59 | 60 | " Compile the current file. 61 | command! -bang -bar -nargs=* CoffeeMake 62 | \ call s:CoffeeMakeDeprecated(, ) 63 | 64 | " Set `makeprg` on rename since we embed the filename in the setting. 65 | augroup CoffeeUpdateMakePrg 66 | autocmd! 67 | 68 | " Update `makeprg` if coffee is still the compiler, else stop running this 69 | " function. 70 | function! s:UpdateMakePrg() 71 | if !s:SetMakePrg() 72 | autocmd! CoffeeUpdateMakePrg 73 | endif 74 | endfunction 75 | 76 | " Set autocmd locally if compiler was set locally. 77 | if &l:makeprg =~ s:pat 78 | autocmd BufWritePre,BufFilePost call s:UpdateMakePrg() 79 | else 80 | autocmd BufWritePre,BufFilePost call s:UpdateMakePrg() 81 | endif 82 | augroup END 83 | -------------------------------------------------------------------------------- /autoload/ctrlp/mixed.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================= 2 | " File: autoload/ctrlp/mixed.vim 3 | " Description: Mixing Files + MRU + Buffers 4 | " Author: Kien Nguyen 5 | " ============================================================================= 6 | 7 | " Init {{{1 8 | if exists('g:loaded_ctrlp_mixed') && g:loaded_ctrlp_mixed 9 | fini 10 | en 11 | let [g:loaded_ctrlp_mixed, g:ctrlp_newmix] = [1, 0] 12 | 13 | cal add(g:ctrlp_ext_vars, { 14 | \ 'init': 'ctrlp#mixed#init(s:compare_lim)', 15 | \ 'accept': 'ctrlp#acceptfile', 16 | \ 'lname': 'fil + mru + buf', 17 | \ 'sname': 'mix', 18 | \ 'type': 'path', 19 | \ 'opmul': 1, 20 | \ 'specinput': 1, 21 | \ }) 22 | 23 | let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) 24 | " Utilities {{{1 25 | fu! s:newcache(cwd) 26 | if g:ctrlp_newmix || !has_key(g:ctrlp_allmixes, 'data') | retu 1 | en 27 | retu g:ctrlp_allmixes['cwd'] != a:cwd 28 | \ || g:ctrlp_allmixes['filtime'] < getftime(ctrlp#utils#cachefile()) 29 | \ || g:ctrlp_allmixes['mrutime'] < getftime(ctrlp#mrufiles#cachefile()) 30 | \ || g:ctrlp_allmixes['bufs'] < len(ctrlp#mrufiles#bufs()) 31 | endf 32 | 33 | fu! s:getnewmix(cwd, clim) 34 | if g:ctrlp_newmix 35 | cal ctrlp#mrufiles#refresh('raw') 36 | let g:ctrlp_newcache = 1 37 | en 38 | let g:ctrlp_lines = copy(ctrlp#files()) 39 | cal ctrlp#progress('Mixing...') 40 | let mrufs = copy(ctrlp#mrufiles#list('raw')) 41 | if exists('+ssl') && &ssl 42 | cal map(mrufs, 'tr(v:val, "\\", "/")') 43 | en 44 | let allbufs = map(ctrlp#buffers(), 'fnamemodify(v:val, ":p")') 45 | let [bufs, ubufs] = [[], []] 46 | for each in allbufs 47 | cal add(filereadable(each) ? bufs : ubufs, each) 48 | endfo 49 | let mrufs = bufs + filter(mrufs, 'index(bufs, v:val) < 0') 50 | if len(mrufs) > len(g:ctrlp_lines) 51 | cal filter(mrufs, 'stridx(v:val, a:cwd)') 52 | el 53 | let cwd_mrufs = filter(copy(mrufs), '!stridx(v:val, a:cwd)') 54 | let cwd_mrufs = ctrlp#rmbasedir(cwd_mrufs) 55 | for each in cwd_mrufs 56 | let id = index(g:ctrlp_lines, each) 57 | if id >= 0 | cal remove(g:ctrlp_lines, id) | en 58 | endfo 59 | en 60 | let mrufs += ubufs 61 | cal map(mrufs, 'fnamemodify(v:val, ":.")') 62 | let g:ctrlp_lines = len(mrufs) > len(g:ctrlp_lines) 63 | \ ? g:ctrlp_lines + mrufs : mrufs + g:ctrlp_lines 64 | if len(g:ctrlp_lines) <= a:clim 65 | cal sort(g:ctrlp_lines, 'ctrlp#complen') 66 | en 67 | let g:ctrlp_allmixes = { 'filtime': getftime(ctrlp#utils#cachefile()), 68 | \ 'mrutime': getftime(ctrlp#mrufiles#cachefile()), 'cwd': a:cwd, 69 | \ 'bufs': len(ctrlp#mrufiles#bufs()), 'data': g:ctrlp_lines } 70 | endf 71 | " Public {{{1 72 | fu! ctrlp#mixed#init(clim) 73 | let cwd = getcwd() 74 | if s:newcache(cwd) 75 | cal s:getnewmix(cwd, a:clim) 76 | el 77 | let g:ctrlp_lines = g:ctrlp_allmixes['data'] 78 | en 79 | let g:ctrlp_newmix = 0 80 | retu g:ctrlp_lines 81 | endf 82 | 83 | fu! ctrlp#mixed#id() 84 | retu s:id 85 | endf 86 | "}}} 87 | 88 | " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 89 | -------------------------------------------------------------------------------- /autoload/ctrlp/changes.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================= 2 | " File: autoload/ctrlp/changes.vim 3 | " Description: Change list extension 4 | " Author: Kien Nguyen 5 | " ============================================================================= 6 | 7 | " Init {{{1 8 | if exists('g:loaded_ctrlp_changes') && g:loaded_ctrlp_changes 9 | fini 10 | en 11 | let g:loaded_ctrlp_changes = 1 12 | 13 | cal add(g:ctrlp_ext_vars, { 14 | \ 'init': 'ctrlp#changes#init(s:bufnr, s:crbufnr)', 15 | \ 'accept': 'ctrlp#changes#accept', 16 | \ 'lname': 'changes', 17 | \ 'sname': 'chs', 18 | \ 'exit': 'ctrlp#changes#exit()', 19 | \ 'type': 'tabe', 20 | \ 'sort': 0, 21 | \ 'nolim': 1, 22 | \ }) 23 | 24 | let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) 25 | " Utilities {{{1 26 | fu! s:changelist(bufnr) 27 | sil! exe 'noa hid b' a:bufnr 28 | redi => result 29 | sil! changes 30 | redi END 31 | retu map(split(result, "\n")[1:], 'tr(v:val, " ", " ")') 32 | endf 33 | 34 | fu! s:process(clines, ...) 35 | let [clines, evas] = [[], []] 36 | for each in a:clines 37 | let parts = matchlist(each, '\v^.\s*\d+\s+(\d+)\s+(\d+)\s(.*)$') 38 | if !empty(parts) 39 | if parts[3] == '' | let parts[3] = ' ' | en 40 | cal add(clines, parts[3].' |'.a:1.':'.a:2.'|'.parts[1].':'.parts[2].'|') 41 | en 42 | endfo 43 | retu reverse(filter(clines, 'count(clines, v:val) == 1')) 44 | endf 45 | 46 | fu! s:syntax() 47 | if !ctrlp#nosy() 48 | cal ctrlp#hicheck('CtrlPBufName', 'Directory') 49 | cal ctrlp#hicheck('CtrlPTabExtra', 'Comment') 50 | sy match CtrlPBufName '\t|\d\+:\zs[^|]\+\ze|\d\+:\d\+|$' 51 | sy match CtrlPTabExtra '\zs\t.*\ze$' contains=CtrlPBufName 52 | en 53 | endf 54 | " Public {{{1 55 | fu! ctrlp#changes#init(original_bufnr, bufnr) 56 | let bufnr = exists('s:bufnr') ? s:bufnr : a:bufnr 57 | let bufs = exists('s:clmode') && s:clmode ? ctrlp#buffers('id') : [bufnr] 58 | cal filter(bufs, 'v:val > 0') 59 | let [swb, &swb] = [&swb, ''] 60 | let lines = [] 61 | for each in bufs 62 | let bname = bufname(each) 63 | let fnamet = fnamemodify(bname == '' ? '[No Name]' : bname, ':t') 64 | cal extend(lines, s:process(s:changelist(each), each, fnamet)) 65 | endfo 66 | sil! exe 'noa hid b' a:original_bufnr 67 | let &swb = swb 68 | cal ctrlp#syntax() 69 | cal s:syntax() 70 | retu lines 71 | endf 72 | 73 | fu! ctrlp#changes#accept(mode, str) 74 | let info = matchlist(a:str, '\t|\(\d\+\):[^|]\+|\(\d\+\):\(\d\+\)|$') 75 | let bufnr = str2nr(get(info, 1)) 76 | if bufnr 77 | cal ctrlp#acceptfile(a:mode, bufnr) 78 | cal cursor(get(info, 2), get(info, 3)) 79 | sil! norm! zvzz 80 | en 81 | endf 82 | 83 | fu! ctrlp#changes#cmd(mode, ...) 84 | let s:clmode = a:mode 85 | if a:0 && !empty(a:1) 86 | let s:clmode = 0 87 | let bname = a:1 =~# '^%$\|^#\d*$' ? expand(a:1) : a:1 88 | let s:bufnr = bufnr('^'.fnamemodify(bname, ':p').'$') 89 | en 90 | retu s:id 91 | endf 92 | 93 | fu! ctrlp#changes#exit() 94 | unl! s:clmode s:bufnr 95 | endf 96 | "}}} 97 | 98 | " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 99 | -------------------------------------------------------------------------------- /autoload/ctrlp/dir.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================= 2 | " File: autoload/ctrlp/dir.vim 3 | " Description: Directory extension 4 | " Author: Kien Nguyen 5 | " ============================================================================= 6 | 7 | " Init {{{1 8 | if exists('g:loaded_ctrlp_dir') && g:loaded_ctrlp_dir 9 | fini 10 | en 11 | let [g:loaded_ctrlp_dir, g:ctrlp_newdir] = [1, 0] 12 | 13 | let s:ars = ['s:maxdepth', 's:maxfiles', 's:compare_lim', 's:glob', 's:caching'] 14 | 15 | cal add(g:ctrlp_ext_vars, { 16 | \ 'init': 'ctrlp#dir#init('.join(s:ars, ', ').')', 17 | \ 'accept': 'ctrlp#dir#accept', 18 | \ 'lname': 'dirs', 19 | \ 'sname': 'dir', 20 | \ 'type': 'path', 21 | \ 'specinput': 1, 22 | \ }) 23 | 24 | let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) 25 | 26 | let s:dircounts = {} 27 | " Utilities {{{1 28 | fu! s:globdirs(dirs, depth) 29 | let entries = split(globpath(a:dirs, s:glob), "\n") 30 | let [dirs, depth] = [ctrlp#dirnfile(entries)[0], a:depth + 1] 31 | cal extend(g:ctrlp_alldirs, dirs) 32 | let nr = len(g:ctrlp_alldirs) 33 | if !empty(dirs) && !s:max(nr, s:maxfiles) && depth <= s:maxdepth 34 | sil! cal ctrlp#progress(nr) 35 | cal map(dirs, 'ctrlp#utils#fnesc(v:val, "g", ",")') 36 | cal s:globdirs(join(dirs, ','), depth) 37 | en 38 | endf 39 | 40 | fu! s:max(len, max) 41 | retu a:max && a:len > a:max 42 | endf 43 | 44 | fu! s:nocache() 45 | retu !s:caching || ( s:caching > 1 && get(s:dircounts, s:cwd) < s:caching ) 46 | endf 47 | " Public {{{1 48 | fu! ctrlp#dir#init(...) 49 | let s:cwd = getcwd() 50 | for each in range(len(s:ars)) 51 | let {s:ars[each]} = a:{each + 1} 52 | endfo 53 | let cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'dir' 54 | let cafile = cadir.ctrlp#utils#lash().ctrlp#utils#cachefile('dir') 55 | if g:ctrlp_newdir || s:nocache() || !filereadable(cafile) 56 | let [s:initcwd, g:ctrlp_alldirs] = [s:cwd, []] 57 | if !ctrlp#igncwd(s:cwd) 58 | cal s:globdirs(ctrlp#utils#fnesc(s:cwd, 'g', ','), 0) 59 | en 60 | cal ctrlp#rmbasedir(g:ctrlp_alldirs) 61 | if len(g:ctrlp_alldirs) <= s:compare_lim 62 | cal sort(g:ctrlp_alldirs, 'ctrlp#complen') 63 | en 64 | cal ctrlp#utils#writecache(g:ctrlp_alldirs, cadir, cafile) 65 | let g:ctrlp_newdir = 0 66 | el 67 | if !( exists('s:initcwd') && s:initcwd == s:cwd ) 68 | let s:initcwd = s:cwd 69 | let g:ctrlp_alldirs = ctrlp#utils#readfile(cafile) 70 | en 71 | en 72 | cal extend(s:dircounts, { s:cwd : len(g:ctrlp_alldirs) }) 73 | retu g:ctrlp_alldirs 74 | endf 75 | 76 | fu! ctrlp#dir#accept(mode, str) 77 | let path = a:mode == 'h' ? getcwd() : s:cwd.ctrlp#call('s:lash', s:cwd).a:str 78 | if a:mode =~ 't\|v\|h' 79 | cal ctrlp#exit() 80 | en 81 | cal ctrlp#setdir(path, a:mode =~ 't\|h' ? 'chd!' : 'lc!') 82 | if a:mode == 'e' 83 | sil! cal ctrlp#statusline() 84 | cal ctrlp#setlines(s:id) 85 | cal ctrlp#recordhist() 86 | cal ctrlp#prtclear() 87 | en 88 | endf 89 | 90 | fu! ctrlp#dir#id() 91 | retu s:id 92 | endf 93 | "}}} 94 | 95 | " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 96 | -------------------------------------------------------------------------------- /autoload/ctrlp/utils.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================= 2 | " File: autoload/ctrlp/utils.vim 3 | " Description: Utilities 4 | " Author: Kien Nguyen 5 | " ============================================================================= 6 | 7 | " Static variables {{{1 8 | fu! ctrlp#utils#lash() 9 | retu &ssl || !exists('+ssl') ? '/' : '\' 10 | endf 11 | 12 | fu! s:lash(...) 13 | retu ( a:0 ? a:1 : getcwd() ) !~ '[\/]$' ? s:lash : '' 14 | endf 15 | 16 | fu! ctrlp#utils#opts() 17 | let s:lash = ctrlp#utils#lash() 18 | let usrhome = $HOME . s:lash( $HOME ) 19 | let cahome = exists('$XDG_CACHE_HOME') ? $XDG_CACHE_HOME : usrhome.'.cache' 20 | let cadir = isdirectory(usrhome.'.ctrlp_cache') 21 | \ ? usrhome.'.ctrlp_cache' : cahome.s:lash(cahome).'ctrlp' 22 | if exists('g:ctrlp_cache_dir') 23 | let cadir = expand(g:ctrlp_cache_dir, 1) 24 | if isdirectory(cadir.s:lash(cadir).'.ctrlp_cache') 25 | let cadir = cadir.s:lash(cadir).'.ctrlp_cache' 26 | en 27 | en 28 | let s:cache_dir = cadir 29 | endf 30 | cal ctrlp#utils#opts() 31 | 32 | let s:wig_cond = v:version > 702 || ( v:version == 702 && has('patch051') ) 33 | " Files and Directories {{{1 34 | fu! ctrlp#utils#cachedir() 35 | retu s:cache_dir 36 | endf 37 | 38 | fu! ctrlp#utils#cachefile(...) 39 | let [tail, dir] = [a:0 == 1 ? '.'.a:1 : '', a:0 == 2 ? a:1 : getcwd()] 40 | let cache_file = substitute(dir, '\([\/]\|^\a\zs:\)', '%', 'g').tail.'.txt' 41 | retu a:0 == 1 ? cache_file : s:cache_dir.s:lash(s:cache_dir).cache_file 42 | endf 43 | 44 | fu! ctrlp#utils#readfile(file) 45 | if filereadable(a:file) 46 | let data = readfile(a:file) 47 | if empty(data) || type(data) != 3 48 | unl data 49 | let data = [] 50 | en 51 | retu data 52 | en 53 | retu [] 54 | endf 55 | 56 | fu! ctrlp#utils#mkdir(dir) 57 | if exists('*mkdir') && !isdirectory(a:dir) 58 | sil! cal mkdir(a:dir, 'p') 59 | en 60 | retu a:dir 61 | endf 62 | 63 | fu! ctrlp#utils#writecache(lines, ...) 64 | if isdirectory(ctrlp#utils#mkdir(a:0 ? a:1 : s:cache_dir)) 65 | sil! cal writefile(a:lines, a:0 >= 2 ? a:2 : ctrlp#utils#cachefile()) 66 | en 67 | endf 68 | 69 | fu! ctrlp#utils#glob(...) 70 | let path = ctrlp#utils#fnesc(a:1, 'g') 71 | retu s:wig_cond ? glob(path, a:2) : glob(path) 72 | endf 73 | 74 | fu! ctrlp#utils#globpath(...) 75 | retu call('globpath', s:wig_cond ? a:000 : a:000[:1]) 76 | endf 77 | 78 | fu! ctrlp#utils#fnesc(path, type, ...) 79 | if exists('*fnameescape') 80 | if exists('+ssl') 81 | if a:type == 'c' 82 | let path = escape(a:path, '%#') 83 | elsei a:type == 'f' 84 | let path = fnameescape(a:path) 85 | elsei a:type == 'g' 86 | let path = escape(a:path, '?*') 87 | en 88 | let path = substitute(path, '[', '[[]', 'g') 89 | el 90 | let path = fnameescape(a:path) 91 | en 92 | el 93 | if exists('+ssl') 94 | if a:type == 'c' 95 | let path = escape(a:path, '%#') 96 | elsei a:type == 'f' 97 | let path = escape(a:path, " \t\n%#*?|<\"") 98 | elsei a:type == 'g' 99 | let path = escape(a:path, '?*') 100 | en 101 | let path = substitute(path, '[', '[[]', 'g') 102 | el 103 | let path = escape(a:path, " \t\n*?[{`$\\%#'\"|!<") 104 | en 105 | en 106 | retu a:0 ? escape(path, a:1) : path 107 | endf 108 | "}}} 109 | 110 | " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 111 | -------------------------------------------------------------------------------- /autoload/emmet/lorem/en.vim: -------------------------------------------------------------------------------- 1 | function! emmet#lorem#en#expand(command) 2 | let wcount = matchstr(a:command, '^\%(lorem\|lipsum\)\(\d*\)}$', '\1', '') 3 | let wcount = wcount > 0 ? wcount : 30 4 | 5 | let common = ['lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipisicing', 'elit'] 6 | let words = ['exercitationem', 'perferendis', 'perspiciatis', 'laborum', 'eveniet', 7 | \ 'sunt', 'iure', 'nam', 'nobis', 'eum', 'cum', 'officiis', 'excepturi', 8 | \ 'odio', 'consectetur', 'quasi', 'aut', 'quisquam', 'vel', 'eligendi', 9 | \ 'itaque', 'non', 'odit', 'tempore', 'quaerat', 'dignissimos', 10 | \ 'facilis', 'neque', 'nihil', 'expedita', 'vitae', 'vero', 'ipsum', 11 | \ 'nisi', 'animi', 'cumque', 'pariatur', 'velit', 'modi', 'natus', 12 | \ 'iusto', 'eaque', 'sequi', 'illo', 'sed', 'ex', 'et', 'voluptatibus', 13 | \ 'tempora', 'veritatis', 'ratione', 'assumenda', 'incidunt', 'nostrum', 14 | \ 'placeat', 'aliquid', 'fuga', 'provident', 'praesentium', 'rem', 15 | \ 'necessitatibus', 'suscipit', 'adipisci', 'quidem', 'possimus', 16 | \ 'voluptas', 'debitis', 'sint', 'accusantium', 'unde', 'sapiente', 17 | \ 'voluptate', 'qui', 'aspernatur', 'laudantium', 'soluta', 'amet', 18 | \ 'quo', 'aliquam', 'saepe', 'culpa', 'libero', 'ipsa', 'dicta', 19 | \ 'reiciendis', 'nesciunt', 'doloribus', 'autem', 'impedit', 'minima', 20 | \ 'maiores', 'repudiandae', 'ipsam', 'obcaecati', 'ullam', 'enim', 21 | \ 'totam', 'delectus', 'ducimus', 'quis', 'voluptates', 'dolores', 22 | \ 'molestiae', 'harum', 'dolorem', 'quia', 'voluptatem', 'molestias', 23 | \ 'magni', 'distinctio', 'omnis', 'illum', 'dolorum', 'voluptatum', 'ea', 24 | \ 'quas', 'quam', 'corporis', 'quae', 'blanditiis', 'atque', 'deserunt', 25 | \ 'laboriosam', 'earum', 'consequuntur', 'hic', 'cupiditate', 26 | \ 'quibusdam', 'accusamus', 'ut', 'rerum', 'error', 'minus', 'eius', 27 | \ 'ab', 'ad', 'nemo', 'fugit', 'officia', 'at', 'in', 'id', 'quos', 28 | \ 'reprehenderit', 'numquam', 'iste', 'fugiat', 'sit', 'inventore', 29 | \ 'beatae', 'repellendus', 'magnam', 'recusandae', 'quod', 'explicabo', 30 | \ 'doloremque', 'aperiam', 'consequatur', 'asperiores', 'commodi', 31 | \ 'optio', 'dolor', 'labore', 'temporibus', 'repellat', 'veniam', 32 | \ 'architecto', 'est', 'esse', 'mollitia', 'nulla', 'a', 'similique', 33 | \ 'eos', 'alias', 'dolore', 'tenetur', 'deleniti', 'porro', 'facere', 34 | \ 'maxime', 'corrupti'] 35 | let ret = [] 36 | let sentence = 0 37 | for i in range(wcount) 38 | let arr = common 39 | if sentence > 0 40 | let arr += words 41 | endif 42 | let r = emmet#util#rand() 43 | let word = arr[r % len(arr)] 44 | if sentence == 0 45 | let word = substitute(word, '^.', '\U&', '') 46 | endif 47 | let sentence += 1 48 | call add(ret, word) 49 | if (sentence > 5 && emmet#util#rand() < 10000) || i == wcount - 1 50 | if i == wcount - 1 51 | let endc = "?!..."[emmet#util#rand() % 5] 52 | call add(ret, endc) 53 | else 54 | let endc = "?!,..."[emmet#util#rand() % 6] 55 | call add(ret, endc . ' ') 56 | endif 57 | if endc != ',' 58 | let sentence = 0 59 | endif 60 | else 61 | call add(ret, ' ') 62 | endif 63 | endfor 64 | return join(ret, '') 65 | endfunction 66 | -------------------------------------------------------------------------------- /autoload/emmet/lang/scss.vim: -------------------------------------------------------------------------------- 1 | function! emmet#lang#scss#findTokens(str) 2 | return emmet#lang#html#findTokens(a:str) 3 | endfunction 4 | 5 | function! emmet#lang#scss#parseIntoTree(abbr, type) 6 | if a:abbr =~ '>' 7 | return emmet#lang#html#parseIntoTree(a:abbr, a:type) 8 | else 9 | return emmet#lang#css#parseIntoTree(a:abbr, a:type) 10 | endif 11 | endfunction 12 | 13 | function! emmet#lang#scss#toString(settings, current, type, inline, filters, itemno, indent) 14 | let settings = a:settings 15 | let current = a:current 16 | let type = a:type 17 | let inline = a:inline 18 | let filters = a:filters 19 | let itemno = a:itemno 20 | let indent = a:indent 21 | let str = "" 22 | 23 | let current_name = substitute(current.name, '\$$', itemno+1, '') 24 | if len(current.name) > 0 25 | let str .= current_name 26 | let tmp = '' 27 | for attr in keys(current.attr) 28 | let val = current.attr[attr] 29 | while val =~ '\$\([^#{]\|$\)' 30 | let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') 31 | endwhile 32 | let attr = substitute(attr, '\$$', itemno+1, '') 33 | if attr == 'id' 34 | let str .= '#' . val 35 | elseif attr == 'class' 36 | let str .= '.' . val 37 | else 38 | let tmp .= attr . ': ' . val . ';' 39 | endif 40 | endfor 41 | if len(tmp) > 0 42 | let str .= " {\n" 43 | for line in split(tmp, "\n") 44 | let str .= indent . line . "\n" 45 | endfor 46 | else 47 | let str .= " {\n" 48 | endif 49 | 50 | let inner = '' 51 | for child in current.child 52 | let inner .= emmet#toString(child, type, inline, filters, itemno) 53 | endfor 54 | let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g') 55 | let inner = substitute(inner, "\n" . escape(indent, '\') . "$", "", 'g') 56 | let str .= indent . inner . "\n}\n" 57 | else 58 | return emmet#lang#css#toString(settings, current, type, inline, filters, itemno, indent) 59 | endif 60 | return str 61 | endfunction 62 | 63 | function! emmet#lang#scss#imageSize() 64 | call emmet#lang#css#imageSize() 65 | endfunction 66 | 67 | function! emmet#lang#scss#encodeImage() 68 | return emmet#lang#css#encodeImage() 69 | endfunction 70 | 71 | function! emmet#lang#scss#parseTag(tag) 72 | return emmet#lang#css#parseTag(a:tag) 73 | endfunction 74 | 75 | function! emmet#lang#scss#toggleComment() 76 | call emmet#lang#css#toggleComment() 77 | endfunction 78 | 79 | function! emmet#lang#scss#balanceTag(flag) range 80 | if a:flag == -2 || a:flag == 2 81 | let curpos = [0, line("'<"), col("'<"), 0] 82 | call setpos('.', curpos) 83 | else 84 | let curpos = getpos('.') 85 | endif 86 | if a:flag < 0 87 | let ret = searchpair('}', '', '.\zs{') 88 | else 89 | let ret = searchpair('{', '', '}', 'bW') 90 | endif 91 | if ret > 0 92 | let pos1 = getpos('.')[1:2] 93 | if a:flag < 0 94 | let pos2 = searchpairpos('{', '', '}') 95 | else 96 | let pos2 = searchpairpos('{', '', '}') 97 | endif 98 | let block = [pos1, pos2] 99 | if emmet#util#regionIsValid(block) 100 | call emmet#util#selectRegion(block) 101 | return 102 | endif 103 | endif 104 | if a:flag == -2 || a:flag == 2 105 | silent! exe "normal! gv" 106 | else 107 | call setpos('.', curpos) 108 | endif 109 | endfunction 110 | 111 | function! emmet#lang#scss#moveNextPrev(flag) 112 | call emmet#lang#css#moveNextPrev(a:flag) 113 | endfunction 114 | 115 | function! emmet#lang#scss#splitJoinTag() 116 | call emmet#lang#css#splitJoinTag() 117 | endfunction 118 | 119 | function! emmet#lang#scss#removeTag() 120 | call emmet#lang#ss#removeTag() 121 | endfunction 122 | -------------------------------------------------------------------------------- /lib/nerdtree/menu_item.vim: -------------------------------------------------------------------------------- 1 | "CLASS: MenuItem 2 | "============================================================ 3 | let s:MenuItem = {} 4 | let g:NERDTreeMenuItem = s:MenuItem 5 | 6 | "FUNCTION: MenuItem.All() {{{1 7 | "get all top level menu items 8 | function! s:MenuItem.All() 9 | if !exists("s:menuItems") 10 | let s:menuItems = [] 11 | endif 12 | return s:menuItems 13 | endfunction 14 | 15 | "FUNCTION: MenuItem.AllEnabled() {{{1 16 | "get all top level menu items that are currently enabled 17 | function! s:MenuItem.AllEnabled() 18 | let toReturn = [] 19 | for i in s:MenuItem.All() 20 | if i.enabled() 21 | call add(toReturn, i) 22 | endif 23 | endfor 24 | return toReturn 25 | endfunction 26 | 27 | "FUNCTION: MenuItem.Create(options) {{{1 28 | "make a new menu item and add it to the global list 29 | function! s:MenuItem.Create(options) 30 | let newMenuItem = copy(self) 31 | 32 | let newMenuItem.text = a:options['text'] 33 | let newMenuItem.shortcut = a:options['shortcut'] 34 | let newMenuItem.children = [] 35 | 36 | let newMenuItem.isActiveCallback = -1 37 | if has_key(a:options, 'isActiveCallback') 38 | let newMenuItem.isActiveCallback = a:options['isActiveCallback'] 39 | endif 40 | 41 | let newMenuItem.callback = -1 42 | if has_key(a:options, 'callback') 43 | let newMenuItem.callback = a:options['callback'] 44 | endif 45 | 46 | if has_key(a:options, 'parent') 47 | call add(a:options['parent'].children, newMenuItem) 48 | else 49 | call add(s:MenuItem.All(), newMenuItem) 50 | endif 51 | 52 | return newMenuItem 53 | endfunction 54 | 55 | "FUNCTION: MenuItem.CreateSeparator(options) {{{1 56 | "make a new separator menu item and add it to the global list 57 | function! s:MenuItem.CreateSeparator(options) 58 | let standard_options = { 'text': '--------------------', 59 | \ 'shortcut': -1, 60 | \ 'callback': -1 } 61 | let options = extend(a:options, standard_options, "force") 62 | 63 | return s:MenuItem.Create(options) 64 | endfunction 65 | 66 | "FUNCTION: MenuItem.CreateSubmenu(options) {{{1 67 | "make a new submenu and add it to global list 68 | function! s:MenuItem.CreateSubmenu(options) 69 | let standard_options = { 'callback': -1 } 70 | let options = extend(a:options, standard_options, "force") 71 | 72 | return s:MenuItem.Create(options) 73 | endfunction 74 | 75 | "FUNCTION: MenuItem.enabled() {{{1 76 | "return 1 if this menu item should be displayed 77 | " 78 | "delegates off to the isActiveCallback, and defaults to 1 if no callback was 79 | "specified 80 | function! s:MenuItem.enabled() 81 | if self.isActiveCallback != -1 82 | return {self.isActiveCallback}() 83 | endif 84 | return 1 85 | endfunction 86 | 87 | "FUNCTION: MenuItem.execute() {{{1 88 | "perform the action behind this menu item, if this menuitem has children then 89 | "display a new menu for them, otherwise deletegate off to the menuitem's 90 | "callback 91 | function! s:MenuItem.execute() 92 | if len(self.children) 93 | let mc = s:MenuController.New(self.children) 94 | call mc.showMenu() 95 | else 96 | if self.callback != -1 97 | call {self.callback}() 98 | endif 99 | endif 100 | endfunction 101 | 102 | "FUNCTION: MenuItem.isSeparator() {{{1 103 | "return 1 if this menuitem is a separator 104 | function! s:MenuItem.isSeparator() 105 | return self.callback == -1 && self.children == [] 106 | endfunction 107 | 108 | "FUNCTION: MenuItem.isSubmenu() {{{1 109 | "return 1 if this menuitem is a submenu 110 | function! s:MenuItem.isSubmenu() 111 | return self.callback == -1 && !empty(self.children) 112 | endfunction 113 | 114 | " vim: set sw=4 sts=4 et fdm=marker: 115 | -------------------------------------------------------------------------------- /syntax/nerdtree.vim: -------------------------------------------------------------------------------- 1 | let s:tree_up_dir_line = '.. (up a dir)' 2 | "NERDTreeFlags are syntax items that should be invisible, but give clues as to 3 | "how things should be highlighted 4 | syn match NERDTreeFlag #\~# 5 | syn match NERDTreeFlag #\[RO\]# 6 | 7 | "highlighting for the .. (up dir) line at the top of the tree 8 | execute "syn match NERDTreeUp #\\V". s:tree_up_dir_line ."#" 9 | 10 | "highlighting for the ~/+ symbols for the directory nodes 11 | syn match NERDTreeClosable #\~\<# 12 | syn match NERDTreeClosable #\~\.# 13 | syn match NERDTreeOpenable #+\<# 14 | syn match NERDTreeOpenable #+\.#he=e-1 15 | 16 | "highlighting for the tree structural parts 17 | syn match NERDTreePart #|# 18 | syn match NERDTreePart #`# 19 | syn match NERDTreePartFile #[|`]-#hs=s+1 contains=NERDTreePart 20 | 21 | "quickhelp syntax elements 22 | syn match NERDTreeHelpKey #" \{1,2\}[^ ]*:#hs=s+2,he=e-1 23 | syn match NERDTreeHelpKey #" \{1,2\}[^ ]*,#hs=s+2,he=e-1 24 | syn match NERDTreeHelpTitle #" .*\~#hs=s+2,he=e-1 contains=NERDTreeFlag 25 | syn match NERDTreeToggleOn #".*(on)#hs=e-2,he=e-1 contains=NERDTreeHelpKey 26 | syn match NERDTreeToggleOff #".*(off)#hs=e-3,he=e-1 contains=NERDTreeHelpKey 27 | syn match NERDTreeHelpCommand #" :.\{-}\>#hs=s+3 28 | syn match NERDTreeHelp #^".*# contains=NERDTreeHelpKey,NERDTreeHelpTitle,NERDTreeFlag,NERDTreeToggleOff,NERDTreeToggleOn,NERDTreeHelpCommand 29 | 30 | "highlighting for readonly files 31 | syn match NERDTreeRO #.*\[RO\]#hs=s+2 contains=NERDTreeFlag,NERDTreeBookmark,NERDTreePart,NERDTreePartFile 32 | 33 | "highlighting for sym links 34 | syn match NERDTreeLink #[^-| `].* -> # contains=NERDTreeBookmark,NERDTreeOpenable,NERDTreeClosable,NERDTreeDirSlash 35 | 36 | "highlighing for directory nodes and file nodes 37 | syn match NERDTreeDirSlash #/# 38 | syn match NERDTreeDir #[^-| `].*/# contains=NERDTreeLink,NERDTreeDirSlash,NERDTreeOpenable,NERDTreeClosable 39 | syn match NERDTreeExecFile #[|` ].*\*\($\| \)# contains=NERDTreeLink,NERDTreePart,NERDTreeRO,NERDTreePartFile,NERDTreeBookmark 40 | syn match NERDTreeFile #|-.*# contains=NERDTreeLink,NERDTreePart,NERDTreeRO,NERDTreePartFile,NERDTreeBookmark,NERDTreeExecFile 41 | syn match NERDTreeFile #`-.*# contains=NERDTreeLink,NERDTreePart,NERDTreeRO,NERDTreePartFile,NERDTreeBookmark,NERDTreeExecFile 42 | syn match NERDTreeCWD #^[# 49 | syn match NERDTreeBookmarksHeader #^>-\+Bookmarks-\+$# contains=NERDTreeBookmarksLeader 50 | syn match NERDTreeBookmarkName #^>.\{-} #he=e-1 contains=NERDTreeBookmarksLeader 51 | syn match NERDTreeBookmark #^>.*$# contains=NERDTreeBookmarksLeader,NERDTreeBookmarkName,NERDTreeBookmarksHeader 52 | 53 | if exists("g:NERDChristmasTree") && g:NERDChristmasTree 54 | hi def link NERDTreePart Special 55 | hi def link NERDTreePartFile Type 56 | hi def link NERDTreeFile Normal 57 | hi def link NERDTreeExecFile Title 58 | hi def link NERDTreeDirSlash Identifier 59 | hi def link NERDTreeClosable Type 60 | else 61 | hi def link NERDTreePart Normal 62 | hi def link NERDTreePartFile Normal 63 | hi def link NERDTreeFile Normal 64 | hi def link NERDTreeClosable Title 65 | endif 66 | 67 | hi def link NERDTreeBookmarksHeader statement 68 | hi def link NERDTreeBookmarksLeader ignore 69 | hi def link NERDTreeBookmarkName Identifier 70 | hi def link NERDTreeBookmark normal 71 | 72 | hi def link NERDTreeHelp String 73 | hi def link NERDTreeHelpKey Identifier 74 | hi def link NERDTreeHelpCommand Identifier 75 | hi def link NERDTreeHelpTitle Macro 76 | hi def link NERDTreeToggleOn Question 77 | hi def link NERDTreeToggleOff WarningMsg 78 | 79 | hi def link NERDTreeDir Directory 80 | hi def link NERDTreeUp Directory 81 | hi def link NERDTreeCWD Statement 82 | hi def link NERDTreeLink Macro 83 | hi def link NERDTreeOpenable Title 84 | hi def link NERDTreeFlag ignore 85 | hi def link NERDTreeRO WarningMsg 86 | hi def link NERDTreeBookmark Statement 87 | 88 | hi def link NERDTreeCurrentNode Search 89 | -------------------------------------------------------------------------------- /autoload/ctrlp/tag.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================= 2 | " File: autoload/ctrlp/tag.vim 3 | " Description: Tag file extension 4 | " Author: Kien Nguyen 5 | " ============================================================================= 6 | 7 | " Init {{{1 8 | if exists('g:loaded_ctrlp_tag') && g:loaded_ctrlp_tag 9 | fini 10 | en 11 | let g:loaded_ctrlp_tag = 1 12 | 13 | cal add(g:ctrlp_ext_vars, { 14 | \ 'init': 'ctrlp#tag#init()', 15 | \ 'accept': 'ctrlp#tag#accept', 16 | \ 'lname': 'tags', 17 | \ 'sname': 'tag', 18 | \ 'enter': 'ctrlp#tag#enter()', 19 | \ 'type': 'tabs', 20 | \ }) 21 | 22 | let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) 23 | " Utilities {{{1 24 | fu! s:findcount(str) 25 | let [tg, ofname] = split(a:str, '\t\+\ze[^\t]\+$') 26 | let tgs = taglist('^'.tg.'$') 27 | if len(tgs) < 2 28 | retu [0, 0, 0, 0] 29 | en 30 | let bname = fnamemodify(bufname('%'), ':p') 31 | let fname = expand(fnamemodify(simplify(ofname), ':s?^[.\/]\+??:p:.'), 1) 32 | let [fnd, cnt, pos, ctgs, otgs] = [0, 0, 0, [], []] 33 | for tgi in tgs 34 | let lst = bname == fnamemodify(tgi["filename"], ':p') ? 'ctgs' : 'otgs' 35 | cal call('add', [{lst}, tgi]) 36 | endfo 37 | let ntgs = ctgs + otgs 38 | for tgi in ntgs 39 | let cnt += 1 40 | let fulname = fnamemodify(tgi["filename"], ':p') 41 | if stridx(fulname, fname) >= 0 42 | \ && strlen(fname) + stridx(fulname, fname) == strlen(fulname) 43 | let fnd += 1 44 | let pos = cnt 45 | en 46 | endfo 47 | let cnt = 0 48 | for tgi in ntgs 49 | let cnt += 1 50 | if tgi["filename"] == ofname 51 | let [fnd, pos] = [0, cnt] 52 | en 53 | endfo 54 | retu [1, fnd, pos, len(ctgs)] 55 | endf 56 | 57 | fu! s:filter(tags) 58 | let nr = 0 59 | wh 0 < 1 60 | if a:tags == [] | brea | en 61 | if a:tags[nr] =~ '^!' && a:tags[nr] !~# '^!_TAG_' 62 | let nr += 1 63 | con 64 | en 65 | if a:tags[nr] =~# '^!_TAG_' && len(a:tags) > nr 66 | cal remove(a:tags, nr) 67 | el 68 | brea 69 | en 70 | endw 71 | retu a:tags 72 | endf 73 | 74 | fu! s:syntax() 75 | if !ctrlp#nosy() 76 | cal ctrlp#hicheck('CtrlPTabExtra', 'Comment') 77 | sy match CtrlPTabExtra '\zs\t.*\ze$' 78 | en 79 | endf 80 | " Public {{{1 81 | fu! ctrlp#tag#init() 82 | if empty(s:tagfiles) | retu [] | en 83 | let g:ctrlp_alltags = [] 84 | let tagfiles = sort(filter(s:tagfiles, 'count(s:tagfiles, v:val) == 1')) 85 | for each in tagfiles 86 | let alltags = s:filter(ctrlp#utils#readfile(each)) 87 | cal extend(g:ctrlp_alltags, alltags) 88 | endfo 89 | cal s:syntax() 90 | retu g:ctrlp_alltags 91 | endf 92 | 93 | fu! ctrlp#tag#accept(mode, str) 94 | cal ctrlp#exit() 95 | let str = matchstr(a:str, '^[^\t]\+\t\+[^\t]\+\ze\t') 96 | let [tg, fdcnt] = [split(str, '^[^\t]\+\zs\t')[0], s:findcount(str)] 97 | let cmds = { 98 | \ 't': ['tab sp', 'tab stj'], 99 | \ 'h': ['sp', 'stj'], 100 | \ 'v': ['vs', 'vert stj'], 101 | \ 'e': ['', 'tj'], 102 | \ } 103 | let utg = fdcnt[3] < 2 && fdcnt[0] == 1 && fdcnt[1] == 1 104 | let cmd = !fdcnt[0] || utg ? cmds[a:mode][0] : cmds[a:mode][1] 105 | let cmd = a:mode == 'e' && ctrlp#modfilecond(!&aw) 106 | \ ? ( cmd == 'tj' ? 'stj' : 'sp' ) : cmd 107 | let cmd = a:mode == 't' ? ctrlp#tabcount().cmd : cmd 108 | if !fdcnt[0] || utg 109 | if cmd != '' 110 | exe cmd 111 | en 112 | let save_cst = &cst 113 | set cst& 114 | cal feedkeys(":".( utg ? fdcnt[2] : "" )."ta ".tg."\r", 'nt') 115 | let &cst = save_cst 116 | el 117 | let ext = "" 118 | if fdcnt[1] < 2 && fdcnt[2] 119 | let [sav_more, &more] = [&more, 0] 120 | let ext = fdcnt[2]."\r".":let &more = ".sav_more."\r" 121 | en 122 | cal feedkeys(":".cmd." ".tg."\r".ext, 'nt') 123 | en 124 | cal ctrlp#setlcdir() 125 | endf 126 | 127 | fu! ctrlp#tag#id() 128 | retu s:id 129 | endf 130 | 131 | fu! ctrlp#tag#enter() 132 | let tfs = tagfiles() 133 | let s:tagfiles = tfs != [] ? filter(map(tfs, 'fnamemodify(v:val, ":p")'), 134 | \ 'filereadable(v:val)') : [] 135 | endf 136 | "}}} 137 | 138 | " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 139 | -------------------------------------------------------------------------------- /autoload/ctrlp/bookmarkdir.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================= 2 | " File: autoload/ctrlp/bookmarkdir.vim 3 | " Description: Bookmarked directories extension 4 | " Author: Kien Nguyen 5 | " ============================================================================= 6 | 7 | " Init {{{1 8 | if exists('g:loaded_ctrlp_bookmarkdir') && g:loaded_ctrlp_bookmarkdir 9 | fini 10 | en 11 | let g:loaded_ctrlp_bookmarkdir = 1 12 | 13 | cal add(g:ctrlp_ext_vars, { 14 | \ 'init': 'ctrlp#bookmarkdir#init()', 15 | \ 'accept': 'ctrlp#bookmarkdir#accept', 16 | \ 'lname': 'bookmarked dirs', 17 | \ 'sname': 'bkd', 18 | \ 'type': 'tabs', 19 | \ 'opmul': 1, 20 | \ 'nolim': 1, 21 | \ 'wipe': 'ctrlp#bookmarkdir#remove', 22 | \ }) 23 | 24 | let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) 25 | " Utilities {{{1 26 | fu! s:getinput(str, ...) 27 | echoh Identifier 28 | cal inputsave() 29 | let input = call('input', a:0 ? [a:str] + a:000 : [a:str]) 30 | cal inputrestore() 31 | echoh None 32 | retu input 33 | endf 34 | 35 | fu! s:cachefile() 36 | if !exists('s:cadir') || !exists('s:cafile') 37 | let s:cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'bkd' 38 | let s:cafile = s:cadir.ctrlp#utils#lash().'cache.txt' 39 | en 40 | retu s:cafile 41 | endf 42 | 43 | fu! s:writecache(lines) 44 | cal ctrlp#utils#writecache(a:lines, s:cadir, s:cafile) 45 | endf 46 | 47 | fu! s:getbookmarks() 48 | retu ctrlp#utils#readfile(s:cachefile()) 49 | endf 50 | 51 | fu! s:savebookmark(name, cwd) 52 | let cwds = exists('+ssl') ? [tr(a:cwd, '\', '/'), tr(a:cwd, '/', '\')] : [a:cwd] 53 | let entries = filter(s:getbookmarks(), 'index(cwds, s:parts(v:val)[1]) < 0') 54 | cal s:writecache(insert(entries, a:name.' '.a:cwd)) 55 | endf 56 | 57 | fu! s:setentries() 58 | let time = getftime(s:cachefile()) 59 | if !( exists('s:bookmarks') && time == s:bookmarks[0] ) 60 | let s:bookmarks = [time, s:getbookmarks()] 61 | en 62 | endf 63 | 64 | fu! s:parts(str) 65 | let mlist = matchlist(a:str, '\v([^\t]+)\t(.*)$') 66 | retu mlist != [] ? mlist[1:2] : ['', ''] 67 | endf 68 | 69 | fu! s:process(entries, type) 70 | retu map(a:entries, 's:modify(v:val, a:type)') 71 | endf 72 | 73 | fu! s:modify(entry, type) 74 | let [name, dir] = s:parts(a:entry) 75 | let dir = fnamemodify(dir, a:type) 76 | retu name.' '.( dir == '' ? '.' : dir ) 77 | endf 78 | 79 | fu! s:msg(name, cwd) 80 | redr 81 | echoh Identifier | echon 'Bookmarked ' | echoh Constant 82 | echon a:name.' ' | echoh Directory | echon a:cwd 83 | echoh None 84 | endf 85 | 86 | fu! s:syntax() 87 | if !ctrlp#nosy() 88 | cal ctrlp#hicheck('CtrlPBookmark', 'Identifier') 89 | cal ctrlp#hicheck('CtrlPTabExtra', 'Comment') 90 | sy match CtrlPBookmark '^> [^\t]\+' contains=CtrlPLinePre 91 | sy match CtrlPTabExtra '\zs\t.*\ze$' 92 | en 93 | endf 94 | " Public {{{1 95 | fu! ctrlp#bookmarkdir#init() 96 | cal s:setentries() 97 | cal s:syntax() 98 | retu s:process(copy(s:bookmarks[1]), ':.') 99 | endf 100 | 101 | fu! ctrlp#bookmarkdir#accept(mode, str) 102 | let parts = s:parts(s:modify(a:str, ':p')) 103 | cal call('s:savebookmark', parts) 104 | if a:mode =~ 't\|v\|h' 105 | cal ctrlp#exit() 106 | en 107 | cal ctrlp#setdir(parts[1], a:mode =~ 't\|h' ? 'chd!' : 'lc!') 108 | if a:mode == 'e' 109 | cal ctrlp#switchtype(0) 110 | cal ctrlp#recordhist() 111 | cal ctrlp#prtclear() 112 | en 113 | endf 114 | 115 | fu! ctrlp#bookmarkdir#add(dir, ...) 116 | let str = 'Directory to bookmark: ' 117 | let cwd = a:dir != '' ? a:dir : s:getinput(str, getcwd(), 'dir') 118 | if cwd == '' | retu | en 119 | let cwd = fnamemodify(cwd, ':p') 120 | let name = a:0 && a:1 != '' ? a:1 : s:getinput('Bookmark as: ', cwd) 121 | if name == '' | retu | en 122 | let name = tr(name, ' ', ' ') 123 | cal s:savebookmark(name, cwd) 124 | cal s:msg(name, cwd) 125 | endf 126 | 127 | fu! ctrlp#bookmarkdir#remove(entries) 128 | cal s:process(a:entries, ':p') 129 | cal s:writecache(a:entries == [] ? [] : 130 | \ filter(s:getbookmarks(), 'index(a:entries, v:val) < 0')) 131 | cal s:setentries() 132 | retu s:process(copy(s:bookmarks[1]), ':.') 133 | endf 134 | 135 | fu! ctrlp#bookmarkdir#id() 136 | retu s:id 137 | endf 138 | "}}} 139 | 140 | " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 141 | -------------------------------------------------------------------------------- /autoload/ctrlp/undo.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================= 2 | " File: autoload/ctrlp/undo.vim 3 | " Description: Undo extension 4 | " Author: Kien Nguyen 5 | " ============================================================================= 6 | 7 | " Init {{{1 8 | if ( exists('g:loaded_ctrlp_undo') && g:loaded_ctrlp_undo ) 9 | fini 10 | en 11 | let g:loaded_ctrlp_undo = 1 12 | 13 | cal add(g:ctrlp_ext_vars, { 14 | \ 'init': 'ctrlp#undo#init()', 15 | \ 'accept': 'ctrlp#undo#accept', 16 | \ 'lname': 'undo', 17 | \ 'sname': 'udo', 18 | \ 'enter': 'ctrlp#undo#enter()', 19 | \ 'exit': 'ctrlp#undo#exit()', 20 | \ 'type': 'line', 21 | \ 'sort': 0, 22 | \ 'nolim': 1, 23 | \ }) 24 | 25 | let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) 26 | 27 | let s:text = map(['second', 'seconds', 'minutes', 'hours', 'days', 'weeks', 28 | \ 'months', 'years'], '" ".v:val." ago"') 29 | " Utilities {{{1 30 | fu! s:getundo() 31 | if exists('*undotree') 32 | \ && ( v:version > 703 || ( v:version == 703 && has('patch005') ) ) 33 | retu [1, undotree()] 34 | el 35 | redi => result 36 | sil! undol 37 | redi END 38 | retu [0, split(result, "\n")[1:]] 39 | en 40 | endf 41 | 42 | fu! s:flatten(tree, cur) 43 | let flatdict = {} 44 | for each in a:tree 45 | let saved = has_key(each, 'save') ? 'saved' : '' 46 | let current = each['seq'] == a:cur ? 'current' : '' 47 | cal extend(flatdict, { each['seq'] : [each['time'], saved, current] }) 48 | if has_key(each, 'alt') 49 | cal extend(flatdict, s:flatten(each['alt'], a:cur)) 50 | en 51 | endfo 52 | retu flatdict 53 | endf 54 | 55 | fu! s:elapsed(nr) 56 | let [text, time] = [s:text, localtime() - a:nr] 57 | let mins = time / 60 58 | let hrs = time / 3600 59 | let days = time / 86400 60 | let wks = time / 604800 61 | let mons = time / 2592000 62 | let yrs = time / 31536000 63 | if yrs > 1 64 | retu yrs.text[7] 65 | elsei mons > 1 66 | retu mons.text[6] 67 | elsei wks > 1 68 | retu wks.text[5] 69 | elsei days > 1 70 | retu days.text[4] 71 | elsei hrs > 1 72 | retu hrs.text[3] 73 | elsei mins > 1 74 | retu mins.text[2] 75 | elsei time == 1 76 | retu time.text[0] 77 | elsei time < 120 78 | retu time.text[1] 79 | en 80 | endf 81 | 82 | fu! s:syntax() 83 | if ctrlp#nosy() | retu | en 84 | for [ke, va] in items({'T': 'Directory', 'Br': 'Comment', 'Nr': 'String', 85 | \ 'Sv': 'Comment', 'Po': 'Title'}) 86 | cal ctrlp#hicheck('CtrlPUndo'.ke, va) 87 | endfo 88 | sy match CtrlPUndoT '\v\d+ \zs[^ ]+\ze|\d+:\d+:\d+' 89 | sy match CtrlPUndoBr '\[\|\]' 90 | sy match CtrlPUndoNr '\[\d\+\]' contains=CtrlPUndoBr 91 | sy match CtrlPUndoSv 'saved' 92 | sy match CtrlPUndoPo 'current' 93 | endf 94 | 95 | fu! s:dict2list(dict) 96 | for ke in keys(a:dict) 97 | let a:dict[ke][0] = s:elapsed(a:dict[ke][0]) 98 | endfo 99 | retu map(keys(a:dict), 'eval(''[v:val, a:dict[v:val]]'')') 100 | endf 101 | 102 | fu! s:compval(...) 103 | retu a:2[0] - a:1[0] 104 | endf 105 | 106 | fu! s:format(...) 107 | let saved = !empty(a:1[1][1]) ? ' '.a:1[1][1] : '' 108 | let current = !empty(a:1[1][2]) ? ' '.a:1[1][2] : '' 109 | retu a:1[1][0].' ['.a:1[0].']'.saved.current 110 | endf 111 | 112 | fu! s:formatul(...) 113 | let parts = matchlist(a:1, 114 | \ '\v^\s+(\d+)\s+\d+\s+([^ ]+\s?[^ ]+|\d+\s\w+\s\w+)(\s*\d*)$') 115 | retu parts == [] ? '----' 116 | \ : parts[2].' ['.parts[1].']'.( parts[3] != '' ? ' saved' : '' ) 117 | endf 118 | " Public {{{1 119 | fu! ctrlp#undo#init() 120 | let entries = s:undos[0] ? s:undos[1]['entries'] : s:undos[1] 121 | if empty(entries) | retu [] | en 122 | if !exists('s:lines') 123 | if s:undos[0] 124 | let entries = s:dict2list(s:flatten(entries, s:undos[1]['seq_cur'])) 125 | let s:lines = map(sort(entries, 's:compval'), 's:format(v:val)') 126 | el 127 | let s:lines = map(reverse(entries), 's:formatul(v:val)') 128 | en 129 | en 130 | cal s:syntax() 131 | retu s:lines 132 | endf 133 | 134 | fu! ctrlp#undo#accept(mode, str) 135 | let undon = matchstr(a:str, '\[\zs\d\+\ze\]') 136 | if empty(undon) | retu | en 137 | cal ctrlp#exit() 138 | exe 'u' undon 139 | endf 140 | 141 | fu! ctrlp#undo#id() 142 | retu s:id 143 | endf 144 | 145 | fu! ctrlp#undo#enter() 146 | let s:undos = s:getundo() 147 | endf 148 | 149 | fu! ctrlp#undo#exit() 150 | unl! s:lines 151 | endf 152 | "}}} 153 | 154 | " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 155 | -------------------------------------------------------------------------------- /autoload/emmet/lang/sass.vim: -------------------------------------------------------------------------------- 1 | function! emmet#lang#sass#findTokens(str) 2 | return emmet#lang#html#findTokens(a:str) 3 | endfunction 4 | 5 | function! emmet#lang#sass#parseIntoTree(abbr, type) 6 | if a:abbr =~ '>' 7 | return emmet#lang#html#parseIntoTree(a:abbr, a:type) 8 | else 9 | return emmet#lang#css#parseIntoTree(a:abbr, a:type) 10 | endif 11 | endfunction 12 | 13 | function! emmet#lang#sass#toString(settings, current, type, inline, filters, itemno, indent) 14 | let settings = a:settings 15 | let current = a:current 16 | let type = a:type 17 | let inline = a:inline 18 | let filters = a:filters 19 | let itemno = a:itemno 20 | let indent = a:indent 21 | let str = "" 22 | 23 | let current_name = current.name 24 | let current_name = substitute(current.name, '\$$', itemno+1, '') 25 | if len(current.name) > 0 26 | let str .= current_name 27 | let tmp = '' 28 | for attr in keys(current.attr) 29 | let val = current.attr[attr] 30 | while val =~ '\$\([^#{]\|$\)' 31 | let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') 32 | endwhile 33 | let attr = substitute(attr, '\$$', itemno+1, '') 34 | if attr == 'id' 35 | let str .= '#' . val 36 | elseif attr == 'class' 37 | let str .= '.' . val 38 | else 39 | let tmp .= attr . ': ' . val 40 | endif 41 | endfor 42 | if len(tmp) > 0 43 | let str .= "\n" 44 | for line in split(tmp, "\n") 45 | let str .= indent . line . "\n" 46 | endfor 47 | else 48 | let str .= "\n" 49 | endif 50 | 51 | let inner = '' 52 | for child in current.child 53 | let inner .= emmet#toString(child, type, inline, filters, itemno, indent) 54 | endfor 55 | let inner = substitute(inner, "\n", "\n" . indent, 'g') 56 | let str .= indent . inner 57 | else 58 | let text = emmet#lang#css#toString(settings, current, type, inline, filters, itemno, indent) 59 | let text = substitute(text, '\s*;\ze\(\${[^}]\+}\)\?\(\n\|$\)', '', 'g') 60 | return text 61 | endif 62 | return str 63 | endfunction 64 | 65 | function! emmet#lang#sass#imageSize() 66 | endfunction 67 | 68 | function! emmet#lang#sass#encodeImage() 69 | endfunction 70 | 71 | function! emmet#lang#sass#parseTag(tag) 72 | endfunction 73 | 74 | function! emmet#lang#sass#toggleComment() 75 | endfunction 76 | 77 | function! emmet#lang#sass#balanceTag(flag) range 78 | let block = emmet#util#getVisualBlock() 79 | if a:flag == -2 || a:flag == 2 80 | let curpos = [0, line("'<"), col("'<"), 0] 81 | else 82 | let curpos = getpos('.') 83 | endif 84 | let n = curpos[1] 85 | let ml = len(matchstr(getline(n), '^\s*')) 86 | 87 | if a:flag > 0 88 | if a:flag == 1 || !emmet#util#regionIsValid(block) 89 | let n = line('.') 90 | else 91 | while n > 0 92 | let l = len(matchstr(getline(n), '^\s*\ze[a-z]')) 93 | if l > 0 && l < ml 94 | let ml = l 95 | break 96 | endif 97 | let n -= 1 98 | endwhile 99 | endif 100 | let sn = n 101 | if n == 0 102 | let ml = 0 103 | endif 104 | while n < line('$') 105 | let l = len(matchstr(getline(n), '^\s*[a-z]')) 106 | if l > 0 && l <= ml 107 | let n -= 1 108 | break 109 | endif 110 | let n += 1 111 | endwhile 112 | call setpos('.', [0, n, 1, 0]) 113 | normal! V 114 | call setpos('.', [0, sn, 1, 0]) 115 | else 116 | while n > 0 117 | let l = len(matchstr(getline(n), '^\s*\ze[a-z]')) 118 | if l > 0 && l > ml 119 | let ml = l 120 | break 121 | endif 122 | let n += 1 123 | endwhile 124 | let sn = n 125 | if n == 0 126 | let ml = 0 127 | endif 128 | while n < line('$') 129 | let l = len(matchstr(getline(n), '^\s*[a-z]')) 130 | if l > 0 && l <= ml 131 | let n -= 1 132 | break 133 | endif 134 | let n += 1 135 | endwhile 136 | call setpos('.', [0, n, 1, 0]) 137 | normal! V 138 | call setpos('.', [0, sn, 1, 0]) 139 | endif 140 | endfunction 141 | 142 | function! emmet#lang#sass#moveNextPrev(flag) 143 | let pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp') 144 | if pos == 2 145 | startinsert! 146 | elseif pos != 0 147 | silent! normal! l 148 | startinsert 149 | endif 150 | endfunction 151 | 152 | function! emmet#lang#sass#splitJoinTag() 153 | endfunction 154 | 155 | function! emmet#lang#sass#removeTag() 156 | endfunction 157 | -------------------------------------------------------------------------------- /lib/nerdtree/key_map.vim: -------------------------------------------------------------------------------- 1 | "CLASS: KeyMap 2 | "============================================================ 3 | let s:KeyMap = {} 4 | let g:NERDTreeKeyMap = s:KeyMap 5 | 6 | "FUNCTION: KeyMap.All() {{{1 7 | function! s:KeyMap.All() 8 | if !exists("s:keyMaps") 9 | let s:keyMaps = [] 10 | endif 11 | return s:keyMaps 12 | endfunction 13 | 14 | "FUNCTION: KeyMap.FindFor(key, scope) {{{1 15 | function! s:KeyMap.FindFor(key, scope) 16 | for i in s:KeyMap.All() 17 | if i.key ==# a:key && i.scope ==# a:scope 18 | return i 19 | endif 20 | endfor 21 | return {} 22 | endfunction 23 | 24 | "FUNCTION: KeyMap.BindAll() {{{1 25 | function! s:KeyMap.BindAll() 26 | for i in s:KeyMap.All() 27 | call i.bind() 28 | endfor 29 | endfunction 30 | 31 | "FUNCTION: KeyMap.bind() {{{1 32 | function! s:KeyMap.bind() 33 | " If the key sequence we're trying to map contains any '<>' notation, we 34 | " must replace each of the '<' characters with '' to ensure the string 35 | " is not translated into its corresponding keycode during the later part 36 | " of the map command below 37 | " :he <> 38 | let specialNotationRegex = '\m<\([[:alnum:]_-]\+>\)' 39 | if self.key =~# specialNotationRegex 40 | let keymapInvokeString = substitute(self.key, specialNotationRegex, '\1', 'g') 41 | else 42 | let keymapInvokeString = self.key 43 | endif 44 | 45 | let premap = self.key == "" ? " " : " " 46 | 47 | exec 'nnoremap '. self.key . premap . ':call nerdtree#invokeKeyMap("'. keymapInvokeString .'")' 48 | endfunction 49 | 50 | "FUNCTION: KeyMap.Remove(key, scope) {{{1 51 | function! s:KeyMap.Remove(key, scope) 52 | let maps = s:KeyMap.All() 53 | for i in range(len(maps)) 54 | if maps[i].key ==# a:key && maps[i].scope ==# a:scope 55 | return remove(maps, i) 56 | endif 57 | endfor 58 | endfunction 59 | 60 | "FUNCTION: KeyMap.invoke() {{{1 61 | "Call the KeyMaps callback function 62 | function! s:KeyMap.invoke(...) 63 | let Callback = function(self.callback) 64 | if a:0 65 | call Callback(a:1) 66 | else 67 | call Callback() 68 | endif 69 | endfunction 70 | 71 | "FUNCTION: KeyMap.Invoke() {{{1 72 | "Find a keymapping for a:key and the current scope invoke it. 73 | " 74 | "Scope is determined as follows: 75 | " * if the cursor is on a dir node then "DirNode" 76 | " * if the cursor is on a file node then "FileNode" 77 | " * if the cursor is on a bookmark then "Bookmark" 78 | " 79 | "If a keymap has the scope of "all" then it will be called if no other keymap 80 | "is found for a:key and the scope. 81 | function! s:KeyMap.Invoke(key) 82 | let node = g:NERDTreeFileNode.GetSelected() 83 | if !empty(node) 84 | 85 | "try file node 86 | if !node.path.isDirectory 87 | let km = s:KeyMap.FindFor(a:key, "FileNode") 88 | if !empty(km) 89 | return km.invoke(node) 90 | endif 91 | endif 92 | 93 | "try dir node 94 | if node.path.isDirectory 95 | let km = s:KeyMap.FindFor(a:key, "DirNode") 96 | if !empty(km) 97 | return km.invoke(node) 98 | endif 99 | endif 100 | 101 | "try generic node 102 | let km = s:KeyMap.FindFor(a:key, "Node") 103 | if !empty(km) 104 | return km.invoke(node) 105 | endif 106 | 107 | endif 108 | 109 | "try bookmark 110 | let bm = g:NERDTreeBookmark.GetSelected() 111 | if !empty(bm) 112 | let km = s:KeyMap.FindFor(a:key, "Bookmark") 113 | if !empty(km) 114 | return km.invoke(bm) 115 | endif 116 | endif 117 | 118 | "try all 119 | let km = s:KeyMap.FindFor(a:key, "all") 120 | if !empty(km) 121 | return km.invoke() 122 | endif 123 | endfunction 124 | 125 | "FUNCTION: KeyMap.Create(options) {{{1 126 | function! s:KeyMap.Create(options) 127 | let newKeyMap = copy(self) 128 | let opts = extend({'scope': 'all', 'quickhelpText': ''}, copy(a:options)) 129 | let newKeyMap.key = opts['key'] 130 | let newKeyMap.quickhelpText = opts['quickhelpText'] 131 | let newKeyMap.callback = opts['callback'] 132 | let newKeyMap.scope = opts['scope'] 133 | 134 | call s:KeyMap.Add(newKeyMap) 135 | endfunction 136 | 137 | "FUNCTION: KeyMap.Add(keymap) {{{1 138 | function! s:KeyMap.Add(keymap) 139 | call s:KeyMap.Remove(a:keymap.key, a:keymap.scope) 140 | call add(s:KeyMap.All(), a:keymap) 141 | endfunction 142 | 143 | " vim: set sw=4 sts=4 et fdm=marker: 144 | -------------------------------------------------------------------------------- /autoload/ctrlp/mrufiles.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================= 2 | " File: autoload/ctrlp/mrufiles.vim 3 | " Description: Most Recently Used Files extension 4 | " Author: Kien Nguyen 5 | " ============================================================================= 6 | 7 | " Static variables {{{1 8 | let [s:mrbs, s:mrufs] = [[], []] 9 | 10 | fu! ctrlp#mrufiles#opts() 11 | let [pref, opts] = ['g:ctrlp_mruf_', { 12 | \ 'max': ['s:max', 250], 13 | \ 'include': ['s:in', ''], 14 | \ 'exclude': ['s:ex', ''], 15 | \ 'case_sensitive': ['s:cseno', 1], 16 | \ 'relative': ['s:re', 0], 17 | \ 'save_on_update': ['s:soup', 1], 18 | \ }] 19 | for [ke, va] in items(opts) 20 | let [{va[0]}, {pref.ke}] = [pref.ke, exists(pref.ke) ? {pref.ke} : va[1]] 21 | endfo 22 | endf 23 | cal ctrlp#mrufiles#opts() 24 | " Utilities {{{1 25 | fu! s:excl(fn) 26 | retu !empty({s:ex}) && a:fn =~# {s:ex} 27 | endf 28 | 29 | fu! s:mergelists() 30 | let diskmrufs = ctrlp#utils#readfile(ctrlp#mrufiles#cachefile()) 31 | cal filter(diskmrufs, 'index(s:mrufs, v:val) < 0') 32 | let mrufs = s:mrufs + diskmrufs 33 | retu s:chop(mrufs) 34 | endf 35 | 36 | fu! s:chop(mrufs) 37 | if len(a:mrufs) > {s:max} | cal remove(a:mrufs, {s:max}, -1) | en 38 | retu a:mrufs 39 | endf 40 | 41 | fu! s:reformat(mrufs, ...) 42 | let cwd = getcwd() 43 | let cwd .= cwd !~ '[\/]$' ? ctrlp#utils#lash() : '' 44 | if {s:re} 45 | let cwd = exists('+ssl') ? tr(cwd, '/', '\') : cwd 46 | cal filter(a:mrufs, '!stridx(v:val, cwd)') 47 | en 48 | if a:0 && a:1 == 'raw' | retu a:mrufs | en 49 | let idx = strlen(cwd) 50 | if exists('+ssl') && &ssl 51 | let cwd = tr(cwd, '\', '/') 52 | cal map(a:mrufs, 'tr(v:val, "\\", "/")') 53 | en 54 | retu map(a:mrufs, '!stridx(v:val, cwd) ? strpart(v:val, idx) : v:val') 55 | endf 56 | 57 | fu! s:record(bufnr) 58 | if s:locked | retu | en 59 | let bufnr = a:bufnr + 0 60 | let bufname = bufname(bufnr) 61 | if bufnr > 0 && !empty(bufname) 62 | cal filter(s:mrbs, 'v:val != bufnr') 63 | cal insert(s:mrbs, bufnr) 64 | cal s:addtomrufs(bufname) 65 | en 66 | endf 67 | 68 | fu! s:addtomrufs(fname) 69 | let fn = fnamemodify(a:fname, ':p') 70 | let fn = exists('+ssl') ? tr(fn, '/', '\') : fn 71 | if ( !empty({s:in}) && fn !~# {s:in} ) || ( !empty({s:ex}) && fn =~# {s:ex} ) 72 | \ || !empty(getbufvar('^'.fn.'$', '&bt')) || !filereadable(fn) | retu 73 | en 74 | let idx = index(s:mrufs, fn, 0, !{s:cseno}) 75 | if idx 76 | cal filter(s:mrufs, 'v:val !='.( {s:cseno} ? '#' : '?' ).' fn') 77 | cal insert(s:mrufs, fn) 78 | if {s:soup} && idx < 0 79 | cal s:savetofile(s:mergelists()) 80 | en 81 | en 82 | endf 83 | 84 | fu! s:savetofile(mrufs) 85 | cal ctrlp#utils#writecache(a:mrufs, s:cadir, s:cafile) 86 | endf 87 | " Public {{{1 88 | fu! ctrlp#mrufiles#refresh(...) 89 | let mrufs = s:mergelists() 90 | cal filter(mrufs, '!empty(ctrlp#utils#glob(v:val, 1)) && !s:excl(v:val)') 91 | if exists('+ssl') 92 | cal map(mrufs, 'tr(v:val, "/", "\\")') 93 | cal map(s:mrufs, 'tr(v:val, "/", "\\")') 94 | let cond = 'count(mrufs, v:val, !{s:cseno}) == 1' 95 | cal filter(mrufs, cond) 96 | cal filter(s:mrufs, cond) 97 | en 98 | cal s:savetofile(mrufs) 99 | retu a:0 && a:1 == 'raw' ? [] : s:reformat(mrufs) 100 | endf 101 | 102 | fu! ctrlp#mrufiles#remove(files) 103 | let mrufs = [] 104 | if a:files != [] 105 | let mrufs = s:mergelists() 106 | let cond = 'index(a:files, v:val, 0, !{s:cseno}) < 0' 107 | cal filter(mrufs, cond) 108 | cal filter(s:mrufs, cond) 109 | en 110 | cal s:savetofile(mrufs) 111 | retu s:reformat(mrufs) 112 | endf 113 | 114 | fu! ctrlp#mrufiles#add(fn) 115 | if !empty(a:fn) 116 | cal s:addtomrufs(a:fn) 117 | en 118 | endf 119 | 120 | fu! ctrlp#mrufiles#list(...) 121 | retu a:0 ? a:1 == 'raw' ? s:reformat(s:mergelists(), a:1) : 0 122 | \ : s:reformat(s:mergelists()) 123 | endf 124 | 125 | fu! ctrlp#mrufiles#bufs() 126 | retu s:mrbs 127 | endf 128 | 129 | fu! ctrlp#mrufiles#tgrel() 130 | let {s:re} = !{s:re} 131 | endf 132 | 133 | fu! ctrlp#mrufiles#cachefile() 134 | if !exists('s:cadir') || !exists('s:cafile') 135 | let s:cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'mru' 136 | let s:cafile = s:cadir.ctrlp#utils#lash().'cache.txt' 137 | en 138 | retu s:cafile 139 | endf 140 | 141 | fu! ctrlp#mrufiles#init() 142 | if !has('autocmd') | retu | en 143 | let s:locked = 0 144 | aug CtrlPMRUF 145 | au! 146 | au BufAdd,BufEnter,BufLeave,BufWritePost * cal s:record(expand('', 1)) 147 | au QuickFixCmdPre *vimgrep* let s:locked = 1 148 | au QuickFixCmdPost *vimgrep* let s:locked = 0 149 | au VimLeavePre * cal s:savetofile(s:mergelists()) 150 | aug END 151 | endf 152 | "}}} 153 | 154 | " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 155 | -------------------------------------------------------------------------------- /lib/nerdtree/menu_controller.vim: -------------------------------------------------------------------------------- 1 | "CLASS: MenuController 2 | "============================================================ 3 | let s:MenuController = {} 4 | let g:NERDTreeMenuController = s:MenuController 5 | 6 | "FUNCTION: MenuController.New(menuItems) {{{1 7 | "create a new menu controller that operates on the given menu items 8 | function! s:MenuController.New(menuItems) 9 | let newMenuController = copy(self) 10 | if a:menuItems[0].isSeparator() 11 | let newMenuController.menuItems = a:menuItems[1:-1] 12 | else 13 | let newMenuController.menuItems = a:menuItems 14 | endif 15 | return newMenuController 16 | endfunction 17 | 18 | "FUNCTION: MenuController.showMenu() {{{1 19 | "start the main loop of the menu and get the user to choose/execute a menu 20 | "item 21 | function! s:MenuController.showMenu() 22 | call self._saveOptions() 23 | 24 | try 25 | let self.selection = 0 26 | 27 | let done = 0 28 | while !done 29 | redraw! 30 | call self._echoPrompt() 31 | let key = nr2char(getchar()) 32 | let done = self._handleKeypress(key) 33 | endwhile 34 | finally 35 | call self._restoreOptions() 36 | endtry 37 | 38 | if self.selection != -1 39 | let m = self._current() 40 | call m.execute() 41 | endif 42 | endfunction 43 | 44 | "FUNCTION: MenuController._echoPrompt() {{{1 45 | function! s:MenuController._echoPrompt() 46 | echo "NERDTree Menu. Use j/k/enter and the shortcuts indicated" 47 | echo "==========================================================" 48 | 49 | for i in range(0, len(self.menuItems)-1) 50 | if self.selection == i 51 | echo "> " . self.menuItems[i].text 52 | else 53 | echo " " . self.menuItems[i].text 54 | endif 55 | endfor 56 | endfunction 57 | 58 | "FUNCTION: MenuController._current(key) {{{1 59 | "get the MenuItem that is currently selected 60 | function! s:MenuController._current() 61 | return self.menuItems[self.selection] 62 | endfunction 63 | 64 | "FUNCTION: MenuController._handleKeypress(key) {{{1 65 | "change the selection (if appropriate) and return 1 if the user has made 66 | "their choice, 0 otherwise 67 | function! s:MenuController._handleKeypress(key) 68 | if a:key == 'j' 69 | call self._cursorDown() 70 | elseif a:key == 'k' 71 | call self._cursorUp() 72 | elseif a:key == nr2char(27) "escape 73 | let self.selection = -1 74 | return 1 75 | elseif a:key == "\r" || a:key == "\n" "enter and ctrl-j 76 | return 1 77 | else 78 | let index = self._nextIndexFor(a:key) 79 | if index != -1 80 | let self.selection = index 81 | if len(self._allIndexesFor(a:key)) == 1 82 | return 1 83 | endif 84 | endif 85 | endif 86 | 87 | return 0 88 | endfunction 89 | 90 | "FUNCTION: MenuController._allIndexesFor(shortcut) {{{1 91 | "get indexes to all menu items with the given shortcut 92 | function! s:MenuController._allIndexesFor(shortcut) 93 | let toReturn = [] 94 | 95 | for i in range(0, len(self.menuItems)-1) 96 | if self.menuItems[i].shortcut == a:shortcut 97 | call add(toReturn, i) 98 | endif 99 | endfor 100 | 101 | return toReturn 102 | endfunction 103 | 104 | "FUNCTION: MenuController._nextIndexFor(shortcut) {{{1 105 | "get the index to the next menu item with the given shortcut, starts from the 106 | "current cursor location and wraps around to the top again if need be 107 | function! s:MenuController._nextIndexFor(shortcut) 108 | for i in range(self.selection+1, len(self.menuItems)-1) 109 | if self.menuItems[i].shortcut == a:shortcut 110 | return i 111 | endif 112 | endfor 113 | 114 | for i in range(0, self.selection) 115 | if self.menuItems[i].shortcut == a:shortcut 116 | return i 117 | endif 118 | endfor 119 | 120 | return -1 121 | endfunction 122 | 123 | "FUNCTION: MenuController._setCmdheight() {{{1 124 | "sets &cmdheight to whatever is needed to display the menu 125 | function! s:MenuController._setCmdheight() 126 | let &cmdheight = len(self.menuItems) + 3 127 | endfunction 128 | 129 | "FUNCTION: MenuController._saveOptions() {{{1 130 | "set any vim options that are required to make the menu work (saving their old 131 | "values) 132 | function! s:MenuController._saveOptions() 133 | let self._oldLazyredraw = &lazyredraw 134 | let self._oldCmdheight = &cmdheight 135 | set nolazyredraw 136 | call self._setCmdheight() 137 | endfunction 138 | 139 | "FUNCTION: MenuController._restoreOptions() {{{1 140 | "restore the options we saved in _saveOptions() 141 | function! s:MenuController._restoreOptions() 142 | let &cmdheight = self._oldCmdheight 143 | let &lazyredraw = self._oldLazyredraw 144 | endfunction 145 | 146 | "FUNCTION: MenuController._cursorDown() {{{1 147 | "move the cursor to the next menu item, skipping separators 148 | function! s:MenuController._cursorDown() 149 | let done = 0 150 | while !done 151 | if self.selection < len(self.menuItems)-1 152 | let self.selection += 1 153 | else 154 | let self.selection = 0 155 | endif 156 | 157 | if !self._current().isSeparator() 158 | let done = 1 159 | endif 160 | endwhile 161 | endfunction 162 | 163 | "FUNCTION: MenuController._cursorUp() {{{1 164 | "move the cursor to the previous menu item, skipping separators 165 | function! s:MenuController._cursorUp() 166 | let done = 0 167 | while !done 168 | if self.selection > 0 169 | let self.selection -= 1 170 | else 171 | let self.selection = len(self.menuItems)-1 172 | endif 173 | 174 | if !self._current().isSeparator() 175 | let done = 1 176 | endif 177 | endwhile 178 | endfunction 179 | 180 | " vim: set sw=4 sts=4 et fdm=marker: 181 | -------------------------------------------------------------------------------- /plugin/emmet.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File: emmet.vim 3 | " Author: Yasuhiro Matsumoto 4 | " Last Change: 13-Aug-2013. 5 | " Version: 0.82 6 | " WebPage: http://github.com/mattn/emmet-vim 7 | " Description: vim plugins for HTML and CSS hi-speed coding. 8 | " SeeAlso: http://emmet.io/ 9 | " Usage: 10 | " 11 | " This is vim script support expanding abbreviation like emmet. 12 | " ref: http://emmet.io/ 13 | " 14 | " Type abbreviation 15 | " +------------------------------------- 16 | " | html:5_ 17 | " +------------------------------------- 18 | " "_" is a cursor position. and type "," (Ctrl+y and Comma) 19 | " NOTE: Don't worry about key map. you can change it easily. 20 | " +------------------------------------- 21 | " | 22 | " | 23 | " | 24 | " | 25 | " | 26 | " | 27 | " | 28 | " | _ 29 | " | 30 | " | 31 | " +------------------------------------- 32 | " Type following 33 | " +------------------------------------- 34 | " | div#foo$*2>div.bar 35 | " +------------------------------------- 36 | " And type "," 37 | " +------------------------------------- 38 | " |
39 | " |
_
40 | " |
41 | " |
42 | " |
43 | " |
44 | " +------------------------------------- 45 | " 46 | " Tips: 47 | " 48 | " You can customize behavior of expanding with overriding config. 49 | " This configuration will be marged at loading plugin. 50 | " 51 | " let g:user_emmet_settings = { 52 | " \ 'indentation' : ' ', 53 | " \ 'perl' : { 54 | " \ 'aliases' : { 55 | " \ 'req' : 'require ' 56 | " \ }, 57 | " \ 'snippets' : { 58 | " \ 'use' : "use strict\nuse warnings\n\n", 59 | " \ 'warn' : "warn \"|\";", 60 | " \ } 61 | " \ } 62 | " \} 63 | " 64 | " You can set language attribute in html using 'emmet_settings.lang'. 65 | " 66 | " GetLatestVimScripts: 2981 1 :AutoInstall: emmet.vim 67 | " script type: plugin 68 | 69 | if &cp || v:version < 702 || (exists('g:loaded_emmet_vim') && g:loaded_emmet_vim) 70 | finish 71 | endif 72 | let g:loaded_emmet_vim = 1 73 | 74 | let s:save_cpo = &cpo 75 | set cpo&vim 76 | 77 | if !exists('g:emmet_debug') 78 | let g:emmet_debug = 0 79 | endif 80 | 81 | if !exists('g:emmet_curl_command') 82 | let g:emmet_curl_command = 'curl -s -L -A Mozilla/5.0' 83 | endif 84 | 85 | if exists('g:use_emmet_complete_tag') && g:use_emmet_complete_tag 86 | setlocal omnifunc=emmet#CompleteTag 87 | endif 88 | 89 | if !exists('g:user_emmet_leader_key') 90 | let g:user_emmet_leader_key = '' 91 | endif 92 | 93 | function! s:install_plugin(mode) 94 | for item in [ 95 | \ {'mode': 'i', 'var': 'user_emmet_expandabbr_key', 'key': ',', 'plug': 'EmmetExpandAbbr', 'func': 'u:call emmet#expandAbbr(0,"")a'}, 96 | \ {'mode': 'n', 'var': 'user_emmet_expandabbr_key', 'key': ',', 'plug': 'EmmetExpandAbbr', 'func': ':call emmet#expandAbbr(3,"")'}, 97 | \ {'mode': 'v', 'var': 'user_emmet_expandabbr_key', 'key': ',', 'plug': 'EmmetExpandAbbr', 'func': ':call emmet#expandAbbr(2,"")'}, 98 | \ {'mode': 'i', 'var': 'user_emmet_expandword_key', 'key': ';', 'plug': 'EmmetExpandWord', 'func': 'u:call emmet#expandAbbr(1,"")a'}, 99 | \ {'mode': 'n', 'var': 'user_emmet_expandword_key', 'key': ';', 'plug': 'EmmetExpandWord', 'func': ':call emmet#expandAbbr(1,"")'}, 100 | \ {'mode': 'i', 'var': 'user_emmet_balancetaginward_key', 'key': 'd', 'plug': 'EmmetBalanceTagInward', 'func': ':call emmet#balanceTag(1)'}, 101 | \ {'mode': 'n', 'var': 'user_emmet_balancetaginward_key', 'key': 'd', 'plug': 'EmmetBalanceTagInward', 'func': ':call emmet#balanceTag(1)'}, 102 | \ {'mode': 'v', 'var': 'user_emmet_balancetaginward_key', 'key': 'd', 'plug': 'EmmetBalanceTagInward', 'func': ':call emmet#balanceTag(2)'}, 103 | \ {'mode': 'i', 'var': 'user_emmet_balancetagoutward_key', 'key': 'D', 'plug': 'EmmetBalanceTagOutward', 'func': ':call emmet#balanceTag(-1)'}, 104 | \ {'mode': 'n', 'var': 'user_emmet_balancetagoutward_key', 'key': 'D', 'plug': 'EmmetBalanceTagOutward', 'func': ':call emmet#balanceTag(-1)'}, 105 | \ {'mode': 'v', 'var': 'user_emmet_balancetagoutward_key', 'key': 'D', 'plug': 'EmmetBalanceTagOutward', 'func': ':call emmet#balanceTag(-2)'}, 106 | \ {'mode': 'i', 'var': 'user_emmet_next_key', 'key': 'n', 'plug': 'EmmetMoveNext', 'func': ':call emmet#moveNextPrev(0)'}, 107 | \ {'mode': 'n', 'var': 'user_emmet_next_key', 'key': 'n', 'plug': 'EmmetMoveNext', 'func': ':call emmet#moveNextPrev(0)'}, 108 | \ {'mode': 'i', 'var': 'user_emmet_prev_key', 'key': 'N', 'plug': 'EmmetMovePrev', 'func': ':call emmet#moveNextPrev(1)'}, 109 | \ {'mode': 'n', 'var': 'user_emmet_prev_key', 'key': 'N', 'plug': 'EmmetMovePrev', 'func': ':call emmet#moveNextPrev(1)'}, 110 | \ {'mode': 'i', 'var': 'user_emmet_imagesize_key', 'key': 'i', 'plug': 'EmmetImageSize', 'func': ':call emmet#imageSize()a'}, 111 | \ {'mode': 'n', 'var': 'user_emmet_imagesize_key', 'key': 'i', 'plug': 'EmmetImageSize', 'func': ':call emmet#imageSize()'}, 112 | \ {'mode': 'i', 'var': 'user_emmet_togglecomment_key', 'key': '/', 'plug': 'EmmetToggleComment', 'func': ':call emmet#toggleComment()a'}, 113 | \ {'mode': 'n', 'var': 'user_emmet_togglecomment_key', 'key': '/', 'plug': 'EmmetToggleComment', 'func': ':call emmet#toggleComment()'}, 114 | \ {'mode': 'i', 'var': 'user_emmet_splitjointag_key', 'key': 'j', 'plug': 'EmmetSplitJoinTag', 'func': ':call emmet#splitJoinTag()'}, 115 | \ {'mode': 'n', 'var': 'user_emmet_splitjointag_key', 'key': 'j', 'plug': 'EmmetSplitJoinTag', 'func': ':call emmet#splitJoinTag()'}, 116 | \ {'mode': 'i', 'var': 'user_emmet_removetag_key', 'key': 'k', 'plug': 'EmmetRemoveTag', 'func': ':call emmet#removeTag()a'}, 117 | \ {'mode': 'n', 'var': 'user_emmet_removetag_key', 'key': 'k', 'plug': 'EmmetRemoveTag', 'func': ':call emmet#removeTag()'}, 118 | \ {'mode': 'i', 'var': 'user_emmet_anchorizeurl_key', 'key': 'a', 'plug': 'EmmetAnchorizeURL', 'func': ':call emmet#anchorizeURL(0)a'}, 119 | \ {'mode': 'n', 'var': 'user_emmet_anchorizeurl_key', 'key': 'a', 'plug': 'EmmetAnchorizeURL', 'func': ':call emmet#anchorizeURL(0)'}, 120 | \ {'mode': 'i', 'var': 'user_emmet_anchorizesummary_key', 'key': 'A', 'plug': 'EmmetAnchorizeSummary', 'func': ':call emmet#anchorizeURL(1)a'}, 121 | \ {'mode': 'n', 'var': 'user_emmet_anchorizesummary_key', 'key': 'A', 'plug': 'EmmetAnchorizeSummary', 'func': ':call emmet#anchorizeURL(1)'}, 122 | \ {'mode': 'v', 'var': 'user_emmet_mergelines_key', 'key': 'm', 'plug': 'EmmetMergeLines', 'func': ':call emmet#mergeLines()'}, 123 | \ {'mode': 'v', 'var': 'user_emmet_codepretty_key', 'key': 'c', 'plug': 'EmmetCodePretty', 'func': ':call emmet#codePretty()'}, 124 | \] 125 | 126 | if a:mode != 'a' && stridx(a:mode, item.mode) == -1 127 | continue 128 | endif 129 | if !hasmapto('(' . item.plug . ')', item.mode) 130 | exe item.mode . 'noremap (' . item.plug . ') ' . item.func 131 | endif 132 | if exists('g:' . item.var) 133 | let key = eval('g:' . item.var) 134 | else 135 | let key = g:user_emmet_leader_key . item.key 136 | endif 137 | if len(maparg(key, item.mode)) == 0 138 | exe item.mode . 'map ' . key . ' (' . item.plug . ')' 139 | endif 140 | endfor 141 | endfunction 142 | 143 | if exists('g:user_emmet_mode') 144 | call s:install_plugin(g:user_emmet_mode) 145 | else 146 | call s:install_plugin('a') 147 | endif 148 | 149 | delfunction s:install_plugin 150 | 151 | command! -nargs=1 Emmet call emmet#expandAbbr(4, ) 152 | 153 | let &cpo = s:save_cpo 154 | unlet s:save_cpo 155 | 156 | " vim:set et: 157 | -------------------------------------------------------------------------------- /autoload/emmet/lang/css.vim: -------------------------------------------------------------------------------- 1 | function! emmet#lang#css#findTokens(str) 2 | return substitute(a:str, '^.*[;{]\s*', '', '') 3 | endfunction 4 | 5 | function! emmet#lang#css#parseIntoTree(abbr, type) 6 | let abbr = a:abbr 7 | let type = a:type 8 | let prefix = 0 9 | let value = '' 10 | 11 | let settings = emmet#getSettings() 12 | let indent = emmet#getIndentation(type) 13 | let aliases = emmet#getResource(type, 'aliases', {}) 14 | let snippets = emmet#getResource(type, 'snippets', {}) 15 | let use_pipe_for_cursor = emmet#getResource(type, 'use_pipe_for_cursor', 1) 16 | 17 | let root = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': 0 } 18 | 19 | " emmet 20 | let tokens = split(abbr, '+\ze[^+)!]') 21 | for n in range(len(tokens)) 22 | let token = tokens[n] 23 | let prop = matchlist(token, '^\(-\{0,1}[a-zA-Z]\+\|[a-zA-Z0-9]\++\{0,1}\|([a-zA-Z0-9]\++\{0,1})\)\(\%([0-9.-]\+[pe]\{0,1}-\{0,1}\|-auto\)*\)$') 24 | if len(prop) 25 | let token = substitute(prop[1], '^(\(.*\))', '\1', '') 26 | if token =~ '^-' 27 | let prefix = 1 28 | let token = token[1:] 29 | endif 30 | let value = '' 31 | for v in split(prop[2], '\d\zs-') 32 | if len(value) > 0 33 | let value .= ' ' 34 | endif 35 | if token =~ '^[z]' 36 | " TODO 37 | let value .= substitute(v, '[^0-9.]*$', '', '') 38 | elseif v =~ 'p$' 39 | let value .= substitute(v, 'p$', '%', '') 40 | elseif v =~ 'e$' 41 | let value .= substitute(v, 'e$', 'em', '') 42 | elseif v =~ '\.' 43 | let value .= v . 'em' 44 | elseif v == 'auto' 45 | let value .= v 46 | elseif v == '0' 47 | let value .= '0' 48 | else 49 | let value .= v . 'px' 50 | endif 51 | endfor 52 | endif 53 | 54 | let tag_name = token 55 | if tag_name =~ '.!$' 56 | let tag_name = tag_name[:-2] 57 | let important = 1 58 | else 59 | let important = 0 60 | endif 61 | " make default node 62 | let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': important } 63 | let current.name = tag_name 64 | 65 | " aliases 66 | if has_key(aliases, tag_name) 67 | let current.name = aliases[tag_name] 68 | endif 69 | 70 | " snippets 71 | if !empty(snippets) && has_key(snippets, tag_name) 72 | let snippet = snippets[tag_name] 73 | if use_pipe_for_cursor 74 | let snippet = substitute(snippet, '|', '${cursor}', 'g') 75 | endif 76 | let lines = split(snippet, "\n") 77 | call map(lines, 'substitute(v:val, "\\( \\|\\t\\)", escape(indent, "\\\\"), "g")') 78 | let current.snippet = join(lines, "\n") 79 | let current.name = '' 80 | let current.snippet = substitute(current.snippet, ';', value . ';', '') 81 | if use_pipe_for_cursor && len(value) > 0 82 | let current.snippet = substitute(current.snippet, '\${cursor}', '', 'g') 83 | endif 84 | if n < len(tokens) - 1 85 | let current.snippet .= "\n" 86 | endif 87 | endif 88 | 89 | let current.pos = 0 90 | let lg = matchlist(token, '^\%(linear-gradient\|lg\)(\s*\(\w\+\)\s*,\s*\([^,]\+\)\s*,\s*\([^)]\+\)\s*)$') 91 | if len(lg) 92 | let current.name = '' 93 | let current.snippet = printf("background-image:-webkit-gradient(%s, 0 0, 0 100%, from(%s), to(%s));\n", lg[1], lg[2], lg[3]) 94 | call add(root.child, deepcopy(current)) 95 | let current.snippet = printf("background-image:-webkit-linear-gradient(%s, %s);\n", lg[2], lg[3]) 96 | call add(root.child, deepcopy(current)) 97 | let current.snippet = printf("background-image:-moz-linear-gradient(%s, %s);\n", lg[2], lg[3]) 98 | call add(root.child, deepcopy(current)) 99 | let current.snippet = printf("background-image:-o-linear-gradient(%s, %s);\n", lg[2], lg[3]) 100 | call add(root.child, deepcopy(current)) 101 | let current.snippet = printf("background-image:linear-gradient(%s, %s);\n", lg[2], lg[3]) 102 | call add(root.child, deepcopy(current)) 103 | elseif prefix 104 | let snippet = current.snippet 105 | let current.snippet = '-webkit-' . snippet . "\n" 106 | call add(root.child, deepcopy(current)) 107 | let current.snippet = '-moz-' . snippet . "\n" 108 | call add(root.child, deepcopy(current)) 109 | let current.snippet = snippet 110 | call add(root.child, current) 111 | else 112 | call add(root.child, current) 113 | endif 114 | endfor 115 | return root 116 | endfunction 117 | 118 | function! emmet#lang#css#toString(settings, current, type, inline, filters, itemno, indent) 119 | let current = a:current 120 | let value = current.value[1:-2] 121 | if emmet#useFilter(a:filters, 'fc') 122 | let value = substitute(value, '\([^:]\+\):\([^;]*;\)', '\1: \2', 'g') 123 | else 124 | let value = substitute(value, '\([^:]\+\):\([^;]*;\)', '\1:\2', 'g') 125 | endif 126 | if current.important 127 | let value = substitute(value, ';', ' !important;', '') 128 | endif 129 | return value 130 | endfunction 131 | 132 | function! emmet#lang#css#imageSize() 133 | endfunction 134 | 135 | function! emmet#lang#css#encodeImage() 136 | endfunction 137 | 138 | function! emmet#lang#css#parseTag(tag) 139 | return {} 140 | endfunction 141 | 142 | function! emmet#lang#css#toggleComment() 143 | let line = getline('.') 144 | let mx = '^\(\s*\)/\*\s*\(.*\)\s*\*/\s*$' 145 | if line =~ '{\s*$' 146 | let block = emmet#util#searchRegion('/\*', '\*/\zs') 147 | if emmet#util#regionIsValid(block) 148 | let content = emmet#util#getContent(block) 149 | let content = substitute(content, '/\*\s\(.*\)\s\*/', '\1', '') 150 | call emmet#util#setContent(block, content) 151 | else 152 | let node = expand('') 153 | if len(node) 154 | exe "normal ciw\='/* '.node.' */'\" 155 | endif 156 | endif 157 | else 158 | if line =~ mx 159 | let space = substitute(matchstr(line, mx), mx, '\1', '') 160 | let line = substitute(matchstr(line, mx), mx, '\2', '') 161 | let line = space . substitute(line, '^\s*\|\s*$', '\1', 'g') 162 | else 163 | let mx = '^\(\s*\)\(.*\)\s*$' 164 | let line = substitute(line, mx, '\1/* \2 */', '') 165 | endif 166 | call setline('.', line) 167 | endif 168 | endfunction 169 | 170 | function! emmet#lang#css#balanceTag(flag) range 171 | if a:flag == -2 || a:flag == 2 172 | let curpos = [0, line("'<"), col("'<"), 0] 173 | else 174 | let curpos = getpos('.') 175 | endif 176 | let block = emmet#util#getVisualBlock() 177 | if !emmet#util#regionIsValid(block) 178 | if a:flag > 0 179 | let block = emmet#util#searchRegion('^', ';') 180 | if emmet#util#regionIsValid(block) 181 | call emmet#util#selectRegion(block) 182 | return 183 | endif 184 | endif 185 | else 186 | if a:flag > 0 187 | let content = emmet#util#getContent(block) 188 | if content !~ '^{.*}$' 189 | let block = emmet#util#searchRegion('{', '}') 190 | if emmet#util#regionIsValid(block) 191 | call emmet#util#selectRegion(block) 192 | return 193 | endif 194 | endif 195 | else 196 | let pos = searchpos('.*;', 'nW') 197 | if pos[0] != 0 198 | call setpos('.', [0, pos[0], pos[1], 0]) 199 | let block = emmet#util#searchRegion('^', ';') 200 | if emmet#util#regionIsValid(block) 201 | call emmet#util#selectRegion(block) 202 | return 203 | endif 204 | endif 205 | endif 206 | endif 207 | if a:flag == -2 || a:flag == 2 208 | silent! exe "normal! gv" 209 | else 210 | call setpos('.', curpos) 211 | endif 212 | endfunction 213 | 214 | function! emmet#lang#css#moveNextPrev(flag) 215 | let pos = search('""\|()\|\(:\s*\zs$\)', a:flag ? 'Wbp' : 'Wp') 216 | if pos == 2 217 | startinsert! 218 | else 219 | silent! normal! l 220 | startinsert 221 | endif 222 | endfunction 223 | 224 | function! emmet#lang#css#splitJoinTag() 225 | " nothing to do 226 | endfunction 227 | 228 | function! emmet#lang#css#removeTag() 229 | " nothing to do 230 | endfunction 231 | -------------------------------------------------------------------------------- /autoload/ctrlp/buffertag.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================= 2 | " File: autoload/ctrlp/buffertag.vim 3 | " Description: Buffer Tag extension 4 | " Maintainer: Kien Nguyen 5 | " Credits: Much of the code was taken from tagbar.vim by Jan Larres, plus 6 | " a few lines from taglist.vim by Yegappan Lakshmanan and from 7 | " buffertag.vim by Takeshi Nishida. 8 | " ============================================================================= 9 | 10 | " Init {{{1 11 | if exists('g:loaded_ctrlp_buftag') && g:loaded_ctrlp_buftag 12 | fini 13 | en 14 | let g:loaded_ctrlp_buftag = 1 15 | 16 | cal add(g:ctrlp_ext_vars, { 17 | \ 'init': 'ctrlp#buffertag#init(s:crfile)', 18 | \ 'accept': 'ctrlp#buffertag#accept', 19 | \ 'lname': 'buffer tags', 20 | \ 'sname': 'bft', 21 | \ 'exit': 'ctrlp#buffertag#exit()', 22 | \ 'type': 'tabs', 23 | \ 'opts': 'ctrlp#buffertag#opts()', 24 | \ }) 25 | 26 | let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) 27 | 28 | let [s:pref, s:opts] = ['g:ctrlp_buftag_', { 29 | \ 'systemenc': ['s:enc', &enc], 30 | \ 'ctags_bin': ['s:bin', ''], 31 | \ 'types': ['s:usr_types', {}], 32 | \ }] 33 | 34 | let s:bins = [ 35 | \ 'ctags-exuberant', 36 | \ 'exuberant-ctags', 37 | \ 'exctags', 38 | \ '/usr/local/bin/ctags', 39 | \ '/opt/local/bin/ctags', 40 | \ 'ctags', 41 | \ 'ctags.exe', 42 | \ 'tags', 43 | \ ] 44 | 45 | let s:types = { 46 | \ 'asm' : '%sasm%sasm%sdlmt', 47 | \ 'aspperl': '%sasp%sasp%sfsv', 48 | \ 'aspvbs' : '%sasp%sasp%sfsv', 49 | \ 'awk' : '%sawk%sawk%sf', 50 | \ 'beta' : '%sbeta%sbeta%sfsv', 51 | \ 'c' : '%sc%sc%sdgsutvf', 52 | \ 'cpp' : '%sc++%sc++%snvdtcgsuf', 53 | \ 'cs' : '%sc#%sc#%sdtncEgsipm', 54 | \ 'cobol' : '%scobol%scobol%sdfgpPs', 55 | \ 'eiffel' : '%seiffel%seiffel%scf', 56 | \ 'erlang' : '%serlang%serlang%sdrmf', 57 | \ 'expect' : '%stcl%stcl%scfp', 58 | \ 'fortran': '%sfortran%sfortran%spbceiklmntvfs', 59 | \ 'html' : '%shtml%shtml%saf', 60 | \ 'java' : '%sjava%sjava%spcifm', 61 | \ 'javascript': '%sjavascript%sjavascript%sf', 62 | \ 'lisp' : '%slisp%slisp%sf', 63 | \ 'lua' : '%slua%slua%sf', 64 | \ 'make' : '%smake%smake%sm', 65 | \ 'ocaml' : '%socaml%socaml%scmMvtfCre', 66 | \ 'pascal' : '%spascal%spascal%sfp', 67 | \ 'perl' : '%sperl%sperl%sclps', 68 | \ 'php' : '%sphp%sphp%scdvf', 69 | \ 'python' : '%spython%spython%scmf', 70 | \ 'rexx' : '%srexx%srexx%ss', 71 | \ 'ruby' : '%sruby%sruby%scfFm', 72 | \ 'scheme' : '%sscheme%sscheme%ssf', 73 | \ 'sh' : '%ssh%ssh%sf', 74 | \ 'csh' : '%ssh%ssh%sf', 75 | \ 'zsh' : '%ssh%ssh%sf', 76 | \ 'slang' : '%sslang%sslang%snf', 77 | \ 'sml' : '%ssml%ssml%secsrtvf', 78 | \ 'sql' : '%ssql%ssql%scFPrstTvfp', 79 | \ 'tcl' : '%stcl%stcl%scfmp', 80 | \ 'vera' : '%svera%svera%scdefgmpPtTvx', 81 | \ 'verilog': '%sverilog%sverilog%smcPertwpvf', 82 | \ 'vim' : '%svim%svim%savf', 83 | \ 'yacc' : '%syacc%syacc%sl', 84 | \ } 85 | 86 | cal map(s:types, 'printf(v:val, "--language-force=", " --", "-types=")') 87 | 88 | if executable('jsctags') 89 | cal extend(s:types, { 'javascript': { 'args': '-f -', 'bin': 'jsctags' } }) 90 | en 91 | 92 | fu! ctrlp#buffertag#opts() 93 | for [ke, va] in items(s:opts) 94 | let {va[0]} = exists(s:pref.ke) ? {s:pref.ke} : va[1] 95 | endfo 96 | " Ctags bin 97 | if empty(s:bin) 98 | for bin in s:bins | if executable(bin) 99 | let s:bin = bin 100 | brea 101 | en | endfo 102 | el 103 | let s:bin = expand(s:bin, 1) 104 | en 105 | " Types 106 | cal extend(s:types, s:usr_types) 107 | endf 108 | " Utilities {{{1 109 | fu! s:validfile(fname, ftype) 110 | if ( !empty(a:fname) || !empty(a:ftype) ) && filereadable(a:fname) 111 | \ && index(keys(s:types), a:ftype) >= 0 | retu 1 | en 112 | retu 0 113 | endf 114 | 115 | fu! s:exectags(cmd) 116 | if exists('+ssl') 117 | let [ssl, &ssl] = [&ssl, 0] 118 | en 119 | if &sh =~ 'cmd\.exe' 120 | let [sxq, &sxq, shcf, &shcf] = [&sxq, '"', &shcf, '/s /c'] 121 | en 122 | let output = system(a:cmd) 123 | if &sh =~ 'cmd\.exe' 124 | let [&sxq, &shcf] = [sxq, shcf] 125 | en 126 | if exists('+ssl') 127 | let &ssl = ssl 128 | en 129 | retu output 130 | endf 131 | 132 | fu! s:exectagsonfile(fname, ftype) 133 | let [ags, ft] = ['-f - --sort=no --excmd=pattern --fields=nKs ', a:ftype] 134 | if type(s:types[ft]) == 1 135 | let ags .= s:types[ft] 136 | let bin = s:bin 137 | elsei type(s:types[ft]) == 4 138 | let ags = s:types[ft]['args'] 139 | let bin = expand(s:types[ft]['bin'], 1) 140 | en 141 | if empty(bin) | retu '' | en 142 | let cmd = s:esctagscmd(bin, ags, a:fname) 143 | if empty(cmd) | retu '' | en 144 | let output = s:exectags(cmd) 145 | if v:shell_error || output =~ 'Warning: cannot open' | retu '' | en 146 | retu output 147 | endf 148 | 149 | fu! s:esctagscmd(bin, args, ...) 150 | if exists('+ssl') 151 | let [ssl, &ssl] = [&ssl, 0] 152 | en 153 | let fname = a:0 ? shellescape(a:1) : '' 154 | let cmd = shellescape(a:bin).' '.a:args.' '.fname 155 | if &sh =~ 'cmd\.exe' 156 | let cmd = substitute(cmd, '[&()@^<>|]', '^\0', 'g') 157 | en 158 | if exists('+ssl') 159 | let &ssl = ssl 160 | en 161 | if has('iconv') 162 | let last = s:enc != &enc ? s:enc : !empty( $LANG ) ? $LANG : &enc 163 | let cmd = iconv(cmd, &enc, last) 164 | en 165 | retu cmd 166 | endf 167 | 168 | fu! s:process(fname, ftype) 169 | if !s:validfile(a:fname, a:ftype) | retu [] | endif 170 | let ftime = getftime(a:fname) 171 | if has_key(g:ctrlp_buftags, a:fname) 172 | \ && g:ctrlp_buftags[a:fname]['time'] >= ftime 173 | let lines = g:ctrlp_buftags[a:fname]['lines'] 174 | el 175 | let data = s:exectagsonfile(a:fname, a:ftype) 176 | let [raw, lines] = [split(data, '\n\+'), []] 177 | for line in raw 178 | if line !~# '^!_TAG_' && len(split(line, ';"')) == 2 179 | let parsed_line = s:parseline(line) 180 | if parsed_line != '' 181 | cal add(lines, parsed_line) 182 | en 183 | en 184 | endfo 185 | let cache = { a:fname : { 'time': ftime, 'lines': lines } } 186 | cal extend(g:ctrlp_buftags, cache) 187 | en 188 | retu lines 189 | endf 190 | 191 | fu! s:parseline(line) 192 | let vals = matchlist(a:line, 193 | \ '\v^([^\t]+)\t(.+)\t[?/]\^?(.{-1,})\$?[?/]\;\"\t(.+)\tline(no)?\:(\d+)') 194 | if vals == [] | retu '' | en 195 | let [bufnr, bufname] = [bufnr('^'.vals[2].'$'), fnamemodify(vals[2], ':p:t')] 196 | retu vals[1].' '.vals[4].'|'.bufnr.':'.bufname.'|'.vals[6].'| '.vals[3] 197 | endf 198 | 199 | fu! s:syntax() 200 | if !ctrlp#nosy() 201 | cal ctrlp#hicheck('CtrlPTagKind', 'Title') 202 | cal ctrlp#hicheck('CtrlPBufName', 'Directory') 203 | cal ctrlp#hicheck('CtrlPTabExtra', 'Comment') 204 | sy match CtrlPTagKind '\zs[^\t|]\+\ze|\d\+:[^|]\+|\d\+|' 205 | sy match CtrlPBufName '|\d\+:\zs[^|]\+\ze|\d\+|' 206 | sy match CtrlPTabExtra '\zs\t.*\ze$' contains=CtrlPBufName,CtrlPTagKind 207 | en 208 | endf 209 | 210 | fu! s:chknearby(pat) 211 | if match(getline('.'), a:pat) < 0 212 | let [int, forw, maxl] = [1, 1, line('$')] 213 | wh !search(a:pat, 'W'.( forw ? '' : 'b' )) 214 | if !forw 215 | if int > maxl | brea | en 216 | let int += int 217 | en 218 | let forw = !forw 219 | endw 220 | en 221 | endf 222 | " Public {{{1 223 | fu! ctrlp#buffertag#init(fname) 224 | let bufs = exists('s:btmode') && s:btmode 225 | \ ? filter(ctrlp#buffers(), 'filereadable(v:val)') 226 | \ : [exists('s:bufname') ? s:bufname : a:fname] 227 | let lines = [] 228 | for each in bufs 229 | let bname = fnamemodify(each, ':p') 230 | let tftype = get(split(getbufvar('^'.bname.'$', '&ft'), '\.'), 0, '') 231 | cal extend(lines, s:process(bname, tftype)) 232 | endfo 233 | cal s:syntax() 234 | retu lines 235 | endf 236 | 237 | fu! ctrlp#buffertag#accept(mode, str) 238 | let vals = matchlist(a:str, 239 | \ '\v^[^\t]+\t+[^\t|]+\|(\d+)\:[^\t|]+\|(\d+)\|\s(.+)$') 240 | let bufnr = str2nr(get(vals, 1)) 241 | if bufnr 242 | cal ctrlp#acceptfile(a:mode, bufnr) 243 | exe 'norm!' str2nr(get(vals, 2, line('.'))).'G' 244 | cal s:chknearby('\V\C'.get(vals, 3, '')) 245 | sil! norm! zvzz 246 | en 247 | endf 248 | 249 | fu! ctrlp#buffertag#cmd(mode, ...) 250 | let s:btmode = a:mode 251 | if a:0 && !empty(a:1) 252 | let s:btmode = 0 253 | let bname = a:1 =~# '^%$\|^#\d*$' ? expand(a:1) : a:1 254 | let s:bufname = fnamemodify(bname, ':p') 255 | en 256 | retu s:id 257 | endf 258 | 259 | fu! ctrlp#buffertag#exit() 260 | unl! s:btmode s:bufname 261 | endf 262 | "}}} 263 | 264 | " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 265 | -------------------------------------------------------------------------------- /lib/nerdtree/opener.vim: -------------------------------------------------------------------------------- 1 | "CLASS: Opener 2 | "============================================================ 3 | let s:Opener = {} 4 | let g:NERDTreeOpener = s:Opener 5 | 6 | "FUNCTION: Opener._checkToCloseTree(newtab) {{{1 7 | "Check the class options and global options (i.e. NERDTreeQuitOnOpen) to see 8 | "if the tree should be closed now. 9 | " 10 | "Args: 11 | "a:newtab - boolean. If set, only close the tree now if we are opening the 12 | "target in a new tab. This is needed because we have to close tree before we 13 | "leave the tab 14 | function! s:Opener._checkToCloseTree(newtab) 15 | if self._keepopen 16 | return 17 | endif 18 | 19 | if (a:newtab && self._where == 't') || !a:newtab 20 | call nerdtree#closeTreeIfQuitOnOpen() 21 | endif 22 | endfunction 23 | 24 | "FUNCTION: Opener._gotoTargetWin() {{{1 25 | function! s:Opener._gotoTargetWin() 26 | if b:NERDTreeType ==# "secondary" 27 | if self._where == 'v' 28 | vsplit 29 | elseif self._where == 'h' 30 | split 31 | elseif self._where == 't' 32 | tabnew 33 | endif 34 | else 35 | call self._checkToCloseTree(1) 36 | 37 | if self._where == 'v' 38 | call self._newVSplit() 39 | elseif self._where == 'h' 40 | call self._newSplit() 41 | elseif self._where == 't' 42 | tabnew 43 | elseif self._where == 'p' 44 | call self._previousWindow() 45 | endif 46 | 47 | call self._checkToCloseTree(0) 48 | endif 49 | endfunction 50 | 51 | "FUNCTION: Opener.New(path, opts) {{{1 52 | "Args: 53 | " 54 | "a:path: The path object that is to be opened. 55 | " 56 | "a:opts: 57 | " 58 | "A dictionary containing the following keys (all optional): 59 | " 'where': Specifies whether the node should be opened in new split/tab or in 60 | " the previous window. Can be either 'v' or 'h' or 't' (for open in 61 | " new tab) 62 | " 'reuse': if a window is displaying the file then jump the cursor there 63 | " 'keepopen': dont close the tree window 64 | " 'stay': open the file, but keep the cursor in the tree win 65 | function! s:Opener.New(path, opts) 66 | let newObj = copy(self) 67 | 68 | let newObj._path = a:path 69 | let newObj._stay = nerdtree#has_opt(a:opts, 'stay') 70 | let newObj._reuse = nerdtree#has_opt(a:opts, 'reuse') 71 | let newObj._keepopen = nerdtree#has_opt(a:opts, 'keepopen') 72 | let newObj._where = has_key(a:opts, 'where') ? a:opts['where'] : '' 73 | let newObj._treetype = b:NERDTreeType 74 | call newObj._saveCursorPos() 75 | 76 | return newObj 77 | endfunction 78 | 79 | "FUNCTION: Opener._newSplit() {{{1 80 | function! s:Opener._newSplit() 81 | " Save the user's settings for splitbelow and splitright 82 | let savesplitbelow=&splitbelow 83 | let savesplitright=&splitright 84 | 85 | " 'there' will be set to a command to move from the split window 86 | " back to the explorer window 87 | " 88 | " 'back' will be set to a command to move from the explorer window 89 | " back to the newly split window 90 | " 91 | " 'right' and 'below' will be set to the settings needed for 92 | " splitbelow and splitright IF the explorer is the only window. 93 | " 94 | let there= g:NERDTreeWinPos ==# "left" ? "wincmd h" : "wincmd l" 95 | let back = g:NERDTreeWinPos ==# "left" ? "wincmd l" : "wincmd h" 96 | let right= g:NERDTreeWinPos ==# "left" 97 | let below=0 98 | 99 | " Attempt to go to adjacent window 100 | call nerdtree#exec(back) 101 | 102 | let onlyOneWin = (winnr("$") ==# 1) 103 | 104 | " If no adjacent window, set splitright and splitbelow appropriately 105 | if onlyOneWin 106 | let &splitright=right 107 | let &splitbelow=below 108 | else 109 | " found adjacent window - invert split direction 110 | let &splitright=!right 111 | let &splitbelow=!below 112 | endif 113 | 114 | let splitMode = onlyOneWin ? "vertical" : "" 115 | 116 | " Open the new window 117 | try 118 | exec(splitMode." sp ") 119 | catch /^Vim\%((\a\+)\)\=:E37/ 120 | call nerdtree#putCursorInTreeWin() 121 | throw "NERDTree.FileAlreadyOpenAndModifiedError: ". self._path.str() ." is already open and modified." 122 | catch /^Vim\%((\a\+)\)\=:/ 123 | "do nothing 124 | endtry 125 | 126 | "resize the tree window if no other window was open before 127 | if onlyOneWin 128 | let size = exists("b:NERDTreeOldWindowSize") ? b:NERDTreeOldWindowSize : g:NERDTreeWinSize 129 | call nerdtree#exec(there) 130 | exec("silent ". splitMode ." resize ". size) 131 | call nerdtree#exec('wincmd p') 132 | endif 133 | 134 | " Restore splitmode settings 135 | let &splitbelow=savesplitbelow 136 | let &splitright=savesplitright 137 | endfunction 138 | 139 | "FUNCTION: Opener._newVSplit() {{{1 140 | function! s:Opener._newVSplit() 141 | let winwidth = winwidth(".") 142 | if winnr("$")==#1 143 | let winwidth = g:NERDTreeWinSize 144 | endif 145 | 146 | call nerdtree#exec("wincmd p") 147 | vnew 148 | 149 | "resize the nerd tree back to the original size 150 | call nerdtree#putCursorInTreeWin() 151 | exec("silent vertical resize ". winwidth) 152 | call nerdtree#exec('wincmd p') 153 | endfunction 154 | 155 | "FUNCTION: Opener.open(target) {{{1 156 | function! s:Opener.open(target) 157 | if self._path.isDirectory 158 | call self._openDirectory(a:target) 159 | else 160 | call self._openFile() 161 | endif 162 | endfunction 163 | 164 | "FUNCTION: Opener._openFile() {{{1 165 | function! s:Opener._openFile() 166 | if self._reuse && self._reuseWindow() 167 | return 168 | endif 169 | 170 | call self._gotoTargetWin() 171 | 172 | if self._treetype ==# "secondary" 173 | call self._path.edit() 174 | else 175 | call self._path.edit() 176 | 177 | 178 | if self._stay 179 | call self._restoreCursorPos() 180 | endif 181 | endif 182 | endfunction 183 | 184 | "FUNCTION: Opener._openDirectory(node) {{{1 185 | function! s:Opener._openDirectory(node) 186 | if self._treetype ==# "secondary" 187 | call self._gotoTargetWin() 188 | call g:NERDTreeCreator.CreateSecondary(a:node.path.str()) 189 | else 190 | call self._gotoTargetWin() 191 | if empty(self._where) 192 | call a:node.makeRoot() 193 | call nerdtree#renderView() 194 | call a:node.putCursorHere(0, 0) 195 | elseif self._where == 't' 196 | call g:NERDTreeCreator.CreatePrimary(a:node.path.str()) 197 | else 198 | call g:NERDTreeCreator.CreateSecondary(a:node.path.str()) 199 | endif 200 | endif 201 | 202 | if self._stay 203 | call self._restoreCursorPos() 204 | endif 205 | endfunction 206 | 207 | "FUNCTION: Opener._previousWindow() {{{1 208 | function! s:Opener._previousWindow() 209 | if !nerdtree#isWindowUsable(winnr("#")) && nerdtree#firstUsableWindow() ==# -1 210 | call self._newSplit() 211 | else 212 | try 213 | if !nerdtree#isWindowUsable(winnr("#")) 214 | call nerdtree#exec(nerdtree#firstUsableWindow() . "wincmd w") 215 | else 216 | call nerdtree#exec('wincmd p') 217 | endif 218 | catch /^Vim\%((\a\+)\)\=:E37/ 219 | call nerdtree#putCursorInTreeWin() 220 | throw "NERDTree.FileAlreadyOpenAndModifiedError: ". self._path.str() ." is already open and modified." 221 | catch /^Vim\%((\a\+)\)\=:/ 222 | echo v:exception 223 | endtry 224 | endif 225 | endfunction 226 | 227 | "FUNCTION: Opener._restoreCursorPos(){{{1 228 | function! s:Opener._restoreCursorPos() 229 | call nerdtree#exec('normal ' . self._tabnr . 'gt') 230 | call nerdtree#exec(bufwinnr(self._bufnr) . 'wincmd w') 231 | endfunction 232 | 233 | "FUNCTION: Opener._reuseWindow(){{{1 234 | "put the cursor in the first window we find for this file 235 | " 236 | "return 1 if we were successful 237 | function! s:Opener._reuseWindow() 238 | "check the current tab for the window 239 | let winnr = bufwinnr('^' . self._path.str() . '$') 240 | if winnr != -1 241 | call nerdtree#exec(winnr . "wincmd w") 242 | call self._checkToCloseTree(0) 243 | return 1 244 | else 245 | "check other tabs 246 | let tabnr = self._path.tabnr() 247 | if tabnr 248 | call self._checkToCloseTree(1) 249 | call nerdtree#exec('normal! ' . tabnr . 'gt') 250 | let winnr = bufwinnr('^' . self._path.str() . '$') 251 | call nerdtree#exec(winnr . "wincmd w") 252 | return 1 253 | endif 254 | endif 255 | return 0 256 | endfunction 257 | 258 | "FUNCTION: Opener._saveCursorPos(){{{1 259 | function! s:Opener._saveCursorPos() 260 | let self._bufnr = bufnr("") 261 | let self._tabnr = tabpagenr() 262 | endfunction 263 | 264 | " vim: set sw=4 sts=4 et fdm=marker: 265 | -------------------------------------------------------------------------------- /plugin/NERD_tree.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================ 2 | " File: NERD_tree.vim 3 | " Description: vim global plugin that provides a nice tree explorer 4 | " Maintainer: Martin Grenfell 5 | " Last Change: 28 December, 2011 6 | " License: This program is free software. It comes without any warranty, 7 | " to the extent permitted by applicable law. You can redistribute 8 | " it and/or modify it under the terms of the Do What The Fuck You 9 | " Want To Public License, Version 2, as published by Sam Hocevar. 10 | " See http://sam.zoy.org/wtfpl/COPYING for more details. 11 | " 12 | " ============================================================================ 13 | " 14 | " SECTION: Script init stuff {{{1 15 | "============================================================ 16 | if exists("loaded_nerd_tree") 17 | finish 18 | endif 19 | if v:version < 700 20 | echoerr "NERDTree: this plugin requires vim >= 7. DOWNLOAD IT! You'll thank me later!" 21 | finish 22 | endif 23 | let loaded_nerd_tree = 1 24 | 25 | "for line continuation - i.e dont want C in &cpo 26 | let s:old_cpo = &cpo 27 | set cpo&vim 28 | 29 | "Function: s:initVariable() function {{{2 30 | "This function is used to initialise a given variable to a given value. The 31 | "variable is only initialised if it does not exist prior 32 | " 33 | "Args: 34 | "var: the name of the var to be initialised 35 | "value: the value to initialise var to 36 | " 37 | "Returns: 38 | "1 if the var is set, 0 otherwise 39 | function! s:initVariable(var, value) 40 | if !exists(a:var) 41 | exec 'let ' . a:var . ' = ' . "'" . substitute(a:value, "'", "''", "g") . "'" 42 | return 1 43 | endif 44 | return 0 45 | endfunction 46 | 47 | "SECTION: Init variable calls and other random constants {{{2 48 | call s:initVariable("g:NERDChristmasTree", 1) 49 | call s:initVariable("g:NERDTreeAutoCenter", 1) 50 | call s:initVariable("g:NERDTreeAutoCenterThreshold", 3) 51 | call s:initVariable("g:NERDTreeCaseSensitiveSort", 0) 52 | call s:initVariable("g:NERDTreeChDirMode", 0) 53 | call s:initVariable("g:NERDTreeMinimalUI", 0) 54 | if !exists("g:NERDTreeIgnore") 55 | let g:NERDTreeIgnore = ['\~$'] 56 | endif 57 | call s:initVariable("g:NERDTreeBookmarksFile", expand('$HOME') . '/.NERDTreeBookmarks') 58 | call s:initVariable("g:NERDTreeHighlightCursorline", 1) 59 | call s:initVariable("g:NERDTreeHijackNetrw", 1) 60 | call s:initVariable("g:NERDTreeMouseMode", 1) 61 | call s:initVariable("g:NERDTreeNotificationThreshold", 100) 62 | call s:initVariable("g:NERDTreeQuitOnOpen", 0) 63 | call s:initVariable("g:NERDTreeShowBookmarks", 0) 64 | call s:initVariable("g:NERDTreeShowFiles", 1) 65 | call s:initVariable("g:NERDTreeShowHidden", 0) 66 | call s:initVariable("g:NERDTreeShowLineNumbers", 0) 67 | call s:initVariable("g:NERDTreeSortDirs", 1) 68 | call s:initVariable("g:NERDTreeDirArrows", !nerdtree#runningWindows()) 69 | call s:initVariable("g:NERDTreeCasadeOpenSingleChildDir", 1) 70 | 71 | if !exists("g:NERDTreeSortOrder") 72 | let g:NERDTreeSortOrder = ['\/$', '*', '\.swp$', '\.bak$', '\~$'] 73 | else 74 | "if there isnt a * in the sort sequence then add one 75 | if count(g:NERDTreeSortOrder, '*') < 1 76 | call add(g:NERDTreeSortOrder, '*') 77 | endif 78 | endif 79 | 80 | if !exists('g:NERDTreeStatusline') 81 | 82 | "the exists() crap here is a hack to stop vim spazzing out when 83 | "loading a session that was created with an open nerd tree. It spazzes 84 | "because it doesnt store b:NERDTreeRoot (its a b: var, and its a hash) 85 | let g:NERDTreeStatusline = "%{exists('b:NERDTreeRoot')?b:NERDTreeRoot.path.str():''}" 86 | 87 | endif 88 | call s:initVariable("g:NERDTreeWinPos", "left") 89 | call s:initVariable("g:NERDTreeWinSize", 31) 90 | 91 | "init the shell commands that will be used to copy nodes, and remove dir trees 92 | " 93 | "Note: the space after the command is important 94 | if nerdtree#runningWindows() 95 | call s:initVariable("g:NERDTreeRemoveDirCmd", 'rmdir /s /q ') 96 | else 97 | call s:initVariable("g:NERDTreeRemoveDirCmd", 'rm -rf ') 98 | call s:initVariable("g:NERDTreeCopyCmd", 'cp -r ') 99 | endif 100 | 101 | 102 | "SECTION: Init variable calls for key mappings {{{2 103 | call s:initVariable("g:NERDTreeMapActivateNode", "o") 104 | call s:initVariable("g:NERDTreeMapChangeRoot", "C") 105 | call s:initVariable("g:NERDTreeMapChdir", "cd") 106 | call s:initVariable("g:NERDTreeMapCloseChildren", "X") 107 | call s:initVariable("g:NERDTreeMapCloseDir", "x") 108 | call s:initVariable("g:NERDTreeMapDeleteBookmark", "D") 109 | call s:initVariable("g:NERDTreeMapMenu", "m") 110 | call s:initVariable("g:NERDTreeMapHelp", "?") 111 | call s:initVariable("g:NERDTreeMapJumpFirstChild", "K") 112 | call s:initVariable("g:NERDTreeMapJumpLastChild", "J") 113 | call s:initVariable("g:NERDTreeMapJumpNextSibling", "") 114 | call s:initVariable("g:NERDTreeMapJumpParent", "p") 115 | call s:initVariable("g:NERDTreeMapJumpPrevSibling", "") 116 | call s:initVariable("g:NERDTreeMapJumpRoot", "P") 117 | call s:initVariable("g:NERDTreeMapOpenExpl", "e") 118 | call s:initVariable("g:NERDTreeMapOpenInTab", "t") 119 | call s:initVariable("g:NERDTreeMapOpenInTabSilent", "T") 120 | call s:initVariable("g:NERDTreeMapOpenRecursively", "O") 121 | call s:initVariable("g:NERDTreeMapOpenSplit", "i") 122 | call s:initVariable("g:NERDTreeMapOpenVSplit", "s") 123 | call s:initVariable("g:NERDTreeMapPreview", "g" . NERDTreeMapActivateNode) 124 | call s:initVariable("g:NERDTreeMapPreviewSplit", "g" . NERDTreeMapOpenSplit) 125 | call s:initVariable("g:NERDTreeMapPreviewVSplit", "g" . NERDTreeMapOpenVSplit) 126 | call s:initVariable("g:NERDTreeMapQuit", "q") 127 | call s:initVariable("g:NERDTreeMapRefresh", "r") 128 | call s:initVariable("g:NERDTreeMapRefreshRoot", "R") 129 | call s:initVariable("g:NERDTreeMapToggleBookmarks", "B") 130 | call s:initVariable("g:NERDTreeMapToggleFiles", "F") 131 | call s:initVariable("g:NERDTreeMapToggleFilters", "f") 132 | call s:initVariable("g:NERDTreeMapToggleHidden", "I") 133 | call s:initVariable("g:NERDTreeMapToggleZoom", "A") 134 | call s:initVariable("g:NERDTreeMapUpdir", "u") 135 | call s:initVariable("g:NERDTreeMapUpdirKeepOpen", "U") 136 | call s:initVariable("g:NERDTreeMapCWD", "CD") 137 | 138 | "SECTION: Load class files{{{2 139 | call nerdtree#loadClassFiles() 140 | 141 | " SECTION: Commands {{{1 142 | "============================================================ 143 | "init the command that users start the nerd tree with 144 | command! -n=? -complete=dir -bar NERDTree :call g:NERDTreeCreator.CreatePrimary('') 145 | command! -n=? -complete=dir -bar NERDTreeToggle :call g:NERDTreeCreator.TogglePrimary('') 146 | command! -n=0 -bar NERDTreeClose :call nerdtree#closeTreeIfOpen() 147 | command! -n=1 -complete=customlist,nerdtree#completeBookmarks -bar NERDTreeFromBookmark call g:NERDTreeCreator.CreatePrimary('') 148 | command! -n=0 -bar NERDTreeMirror call g:NERDTreeCreator.CreateMirror() 149 | command! -n=0 -bar NERDTreeFind call nerdtree#findAndRevealPath() 150 | command! -n=0 -bar NERDTreeFocus call NERDTreeFocus() 151 | command! -n=0 -bar NERDTreeCWD call NERDTreeCWD() 152 | " SECTION: Auto commands {{{1 153 | "============================================================ 154 | augroup NERDTree 155 | "Save the cursor position whenever we close the nerd tree 156 | exec "autocmd BufWinLeave ". g:NERDTreeCreator.BufNamePrefix() ."* call nerdtree#saveScreenState()" 157 | 158 | "disallow insert mode in the NERDTree 159 | exec "autocmd BufEnter ". g:NERDTreeCreator.BufNamePrefix() ."* stopinsert" 160 | augroup END 161 | 162 | if g:NERDTreeHijackNetrw 163 | augroup NERDTreeHijackNetrw 164 | autocmd VimEnter * silent! autocmd! FileExplorer 165 | au BufEnter,VimEnter * call nerdtree#checkForBrowse(expand("")) 166 | augroup END 167 | endif 168 | 169 | " SECTION: Public API {{{1 170 | "============================================================ 171 | function! NERDTreeAddMenuItem(options) 172 | call g:NERDTreeMenuItem.Create(a:options) 173 | endfunction 174 | 175 | function! NERDTreeAddMenuSeparator(...) 176 | let opts = a:0 ? a:1 : {} 177 | call g:NERDTreeMenuItem.CreateSeparator(opts) 178 | endfunction 179 | 180 | function! NERDTreeAddSubmenu(options) 181 | return g:NERDTreeMenuItem.Create(a:options) 182 | endfunction 183 | 184 | function! NERDTreeAddKeyMap(options) 185 | call g:NERDTreeKeyMap.Create(a:options) 186 | endfunction 187 | 188 | function! NERDTreeRender() 189 | call nerdtree#renderView() 190 | endfunction 191 | 192 | function! NERDTreeFocus() 193 | if nerdtree#isTreeOpen() 194 | call nerdtree#putCursorInTreeWin() 195 | else 196 | call g:NERDTreeCreator.TogglePrimary("") 197 | endif 198 | endfunction 199 | 200 | function! NERDTreeCWD() 201 | call NERDTreeFocus() 202 | call nerdtree#chRootCwd() 203 | endfunction 204 | " SECTION: Post Source Actions {{{1 205 | call nerdtree#postSourceActions() 206 | 207 | "reset &cpo back to users setting 208 | let &cpo = s:old_cpo 209 | 210 | " vim: set sw=4 sts=4 et fdm=marker: 211 | -------------------------------------------------------------------------------- /autoload/emmet/lang/slim.vim: -------------------------------------------------------------------------------- 1 | function! emmet#lang#slim#findTokens(str) 2 | return emmet#lang#html#findTokens(a:str) 3 | endfunction 4 | 5 | function! emmet#lang#slim#parseIntoTree(abbr, type) 6 | return emmet#lang#html#parseIntoTree(a:abbr, a:type) 7 | endfunction 8 | 9 | function! emmet#lang#slim#toString(settings, current, type, inline, filters, itemno, indent) 10 | let settings = a:settings 11 | let current = a:current 12 | let type = a:type 13 | let inline = a:inline 14 | let filters = a:filters 15 | let itemno = a:itemno 16 | let indent = emmet#getIndentation(type) 17 | let dollar_expr = emmet#getResource(type, 'dollar_expr', 1) 18 | let str = "" 19 | 20 | let comment_indent = '' 21 | let comment = '' 22 | let current_name = current.name 23 | if dollar_expr 24 | let current_name = substitute(current.name, '\$$', itemno+1, '') 25 | endif 26 | if len(current.name) > 0 27 | let str .= current_name 28 | for attr in emmet#util#unique(current.attrs_order + keys(current.attr)) 29 | if !has_key(current.attr, attr) 30 | continue 31 | endif 32 | let val = current.attr[attr] 33 | if dollar_expr 34 | while val =~ '\$\([^#{]\|$\)' 35 | let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') 36 | endwhile 37 | endif 38 | let attr = substitute(attr, '\$$', itemno+1, '') 39 | let str .= ' ' . attr . '="' . val . '"' 40 | endfor 41 | 42 | let inner = '' 43 | if len(current.value) > 0 44 | let str .= "\n" 45 | let text = current.value[1:-2] 46 | if dollar_expr 47 | let text = substitute(text, '\%(\\\)\@\ 0 70 | for child in current.child 71 | let inner .= emmet#toString(child, type, inline, filters, itemno, indent) 72 | endfor 73 | let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g') 74 | let inner = substitute(inner, "\n" . escape(indent, '\') . "$", "", 'g') 75 | let str .= "\n" . indent . inner 76 | endif 77 | else 78 | let str = current.value[1:-2] 79 | if dollar_expr 80 | let str = substitute(str, '\%(\\\)\@\ 0 130 | let match = matchstr(attrs, mx) 131 | if len(match) == 0 132 | break 133 | endif 134 | let attr_match = matchlist(match, mx) 135 | let name = attr_match[1] 136 | let value = len(attr_match[2]) ? attr_match[2] : attr_match[3] 137 | let current.attr[name] = value 138 | let current.attrs_order += [name] 139 | let attrs = attrs[stridx(attrs, match) + len(match):] 140 | endwhile 141 | return current 142 | endfunction 143 | 144 | function! emmet#lang#slim#toggleComment() 145 | let line = getline('.') 146 | let space = matchstr(line, '^\s*') 147 | if line =~ '^\s*/' 148 | call setline('.', space . line[len(space)+1:]) 149 | elseif line =~ '^\s*[a-z]' 150 | call setline('.', space . '/' . line[len(space):]) 151 | endif 152 | endfunction 153 | 154 | function! emmet#lang#slim#balanceTag(flag) range 155 | let block = emmet#util#getVisualBlock() 156 | if a:flag == -2 || a:flag == 2 157 | let curpos = [0, line("'<"), col("'<"), 0] 158 | else 159 | let curpos = getpos('.') 160 | endif 161 | let n = curpos[1] 162 | let ml = len(matchstr(getline(n), '^\s*')) 163 | 164 | if a:flag > 0 165 | if a:flag == 1 || !emmet#util#regionIsValid(block) 166 | let n = line('.') 167 | else 168 | while n > 0 169 | let l = len(matchstr(getline(n), '^\s*\ze[a-z]')) 170 | if l > 0 && l < ml 171 | let ml = l 172 | break 173 | endif 174 | let n -= 1 175 | endwhile 176 | endif 177 | let sn = n 178 | if n == 0 179 | let ml = 0 180 | endif 181 | while n < line('$') 182 | let l = len(matchstr(getline(n), '^\s*[a-z]')) 183 | if l > 0 && l <= ml 184 | let n -= 1 185 | break 186 | endif 187 | let n += 1 188 | endwhile 189 | call setpos('.', [0, n, 1, 0]) 190 | normal! V 191 | call setpos('.', [0, sn, 1, 0]) 192 | else 193 | while n > 0 194 | let l = len(matchstr(getline(n), '^\s*\ze[a-z]')) 195 | if l > 0 && l > ml 196 | let ml = l 197 | break 198 | endif 199 | let n += 1 200 | endwhile 201 | let sn = n 202 | if n == 0 203 | let ml = 0 204 | endif 205 | while n < line('$') 206 | let l = len(matchstr(getline(n), '^\s*[a-z]')) 207 | if l > 0 && l <= ml 208 | let n -= 1 209 | break 210 | endif 211 | let n += 1 212 | endwhile 213 | call setpos('.', [0, n, 1, 0]) 214 | normal! V 215 | call setpos('.', [0, sn, 1, 0]) 216 | endif 217 | endfunction 218 | 219 | function! emmet#lang#slim#moveNextPrev(flag) 220 | let pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp') 221 | if pos == 2 222 | startinsert! 223 | elseif pos != 0 224 | silent! normal! l 225 | startinsert 226 | endif 227 | endfunction 228 | 229 | function! emmet#lang#slim#splitJoinTag() 230 | let n = line('.') 231 | while n > 0 232 | if getline(n) =~ '^\s*\ze[a-z]' 233 | let sn = n 234 | let n += 1 235 | if getline(n) =~ '^\s*|' 236 | while n <= line('$') 237 | if getline(n) !~ '^\s*|' 238 | break 239 | endif 240 | exe n "delete" 241 | endwhile 242 | call setpos('.', [0, sn, 1, 0]) 243 | else 244 | let spaces = matchstr(getline(sn), '^\s*') 245 | call append(sn, spaces . ' | ') 246 | call setpos('.', [0, sn+1, 1, 0]) 247 | startinsert! 248 | endif 249 | break 250 | endif 251 | let n -= 1 252 | endwhile 253 | endfunction 254 | 255 | function! emmet#lang#slim#removeTag() 256 | let n = line('.') 257 | let ml = 0 258 | while n > 0 259 | if getline(n) =~ '^\s*\ze[a-z]' 260 | let ml = len(matchstr(getline(n), '^\s*[a-z]')) 261 | break 262 | endif 263 | let n -= 1 264 | endwhile 265 | let sn = n 266 | while n < line('$') 267 | let l = len(matchstr(getline(n), '^\s*[a-z]')) 268 | if l > 0 && l <= ml 269 | let n -= 1 270 | break 271 | endif 272 | let n += 1 273 | endwhile 274 | if sn == n 275 | exe "delete" 276 | else 277 | exe sn "," (n-1) "delete" 278 | endif 279 | endfunction 280 | -------------------------------------------------------------------------------- /syntax/coffee.vim: -------------------------------------------------------------------------------- 1 | " Language: CoffeeScript 2 | " Maintainer: Mick Koch 3 | " URL: http://github.com/kchmck/vim-coffee-script 4 | " License: WTFPL 5 | 6 | " Bail if our syntax is already loaded. 7 | if exists('b:current_syntax') && b:current_syntax == 'coffee' 8 | finish 9 | endif 10 | 11 | " Include JavaScript for coffeeEmbed. 12 | syn include @coffeeJS syntax/javascript.vim 13 | silent! unlet b:current_syntax 14 | 15 | " Highlight long strings. 16 | syntax sync fromstart 17 | 18 | " These are `matches` instead of `keywords` because vim's highlighting 19 | " priority for keywords is higher than matches. This causes keywords to be 20 | " highlighted inside matches, even if a match says it shouldn't contain them -- 21 | " like with coffeeAssign and coffeeDot. 22 | syn match coffeeStatement /\<\%(return\|break\|continue\|throw\)\>/ display 23 | hi def link coffeeStatement Statement 24 | 25 | syn match coffeeRepeat /\<\%(for\|while\|until\|loop\)\>/ display 26 | hi def link coffeeRepeat Repeat 27 | 28 | syn match coffeeConditional /\<\%(if\|else\|unless\|switch\|when\|then\)\>/ 29 | \ display 30 | hi def link coffeeConditional Conditional 31 | 32 | syn match coffeeException /\<\%(try\|catch\|finally\)\>/ display 33 | hi def link coffeeException Exception 34 | 35 | syn match coffeeKeyword /\<\%(new\|in\|of\|by\|and\|or\|not\|is\|isnt\|class\|extends\|super\|do\)\>/ 36 | \ display 37 | " The `own` keyword is only a keyword after `for`. 38 | syn match coffeeKeyword /\/ contained containedin=coffeeRepeat 39 | \ display 40 | hi def link coffeeKeyword Keyword 41 | 42 | syn match coffeeOperator /\<\%(instanceof\|typeof\|delete\)\>/ display 43 | hi def link coffeeOperator Operator 44 | 45 | " The first case matches symbol operators only if they have an operand before. 46 | syn match coffeeExtendedOp /\%(\S\s*\)\@<=[+\-*/%&|\^=!<>?.]\{-1,}\|[-=]>\|--\|++\|:/ 47 | \ display 48 | syn match coffeeExtendedOp /\<\%(and\|or\)=/ display 49 | hi def link coffeeExtendedOp coffeeOperator 50 | 51 | " This is separate from `coffeeExtendedOp` to help differentiate commas from 52 | " dots. 53 | syn match coffeeSpecialOp /[,;]/ display 54 | hi def link coffeeSpecialOp SpecialChar 55 | 56 | syn match coffeeBoolean /\<\%(true\|on\|yes\|false\|off\|no\)\>/ display 57 | hi def link coffeeBoolean Boolean 58 | 59 | syn match coffeeGlobal /\<\%(null\|undefined\)\>/ display 60 | hi def link coffeeGlobal Type 61 | 62 | " A special variable 63 | syn match coffeeSpecialVar /\<\%(this\|prototype\|arguments\)\>/ display 64 | hi def link coffeeSpecialVar Special 65 | 66 | " An @-variable 67 | syn match coffeeSpecialIdent /@\%(\%(\I\|\$\)\%(\i\|\$\)*\)\?/ display 68 | hi def link coffeeSpecialIdent Identifier 69 | 70 | " A class-like name that starts with a capital letter 71 | syn match coffeeObject /\<\u\w*\>/ display 72 | hi def link coffeeObject Structure 73 | 74 | " A constant-like name in SCREAMING_CAPS 75 | syn match coffeeConstant /\<\u[A-Z0-9_]\+\>/ display 76 | hi def link coffeeConstant Constant 77 | 78 | " A variable name 79 | syn cluster coffeeIdentifier contains=coffeeSpecialVar,coffeeSpecialIdent, 80 | \ coffeeObject,coffeeConstant 81 | 82 | " A non-interpolated string 83 | syn cluster coffeeBasicString contains=@Spell,coffeeEscape 84 | " An interpolated string 85 | syn cluster coffeeInterpString contains=@coffeeBasicString,coffeeInterp 86 | 87 | " Regular strings 88 | syn region coffeeString start=/"/ skip=/\\\\\|\\"/ end=/"/ 89 | \ contains=@coffeeInterpString 90 | syn region coffeeString start=/'/ skip=/\\\\\|\\'/ end=/'/ 91 | \ contains=@coffeeBasicString 92 | hi def link coffeeString String 93 | 94 | " A integer, including a leading plus or minus 95 | syn match coffeeNumber /\%(\i\|\$\)\@/ display 98 | syn match coffeeNumber /\<0[bB][01]\+\>/ display 99 | syn match coffeeNumber /\<0[oO][0-7]\+\>/ display 100 | syn match coffeeNumber /\<\%(Infinity\|NaN\)\>/ display 101 | hi def link coffeeNumber Number 102 | 103 | " A floating-point number, including a leading plus or minus 104 | syn match coffeeFloat /\%(\i\|\$\)\@/ 111 | \ display 112 | hi def link coffeeReservedError Error 113 | 114 | " A normal object assignment 115 | syn match coffeeObjAssign /@\?\%(\I\|\$\)\%(\i\|\$\)*\s*\ze::\@!/ contains=@coffeeIdentifier display 116 | hi def link coffeeObjAssign Identifier 117 | 118 | syn keyword coffeeTodo TODO FIXME XXX contained 119 | hi def link coffeeTodo Todo 120 | 121 | syn match coffeeComment /#.*/ contains=@Spell,coffeeTodo 122 | hi def link coffeeComment Comment 123 | 124 | syn region coffeeBlockComment start=/####\@!/ end=/###/ 125 | \ contains=@Spell,coffeeTodo 126 | hi def link coffeeBlockComment coffeeComment 127 | 128 | " A comment in a heregex 129 | syn region coffeeHeregexComment start=/#/ end=/\ze\/\/\/\|$/ contained 130 | \ contains=@Spell,coffeeTodo 131 | hi def link coffeeHeregexComment coffeeComment 132 | 133 | " Embedded JavaScript 134 | syn region coffeeEmbed matchgroup=coffeeEmbedDelim 135 | \ start=/`/ skip=/\\\\\|\\`/ end=/`/ keepend 136 | \ contains=@coffeeJS 137 | hi def link coffeeEmbedDelim Delimiter 138 | 139 | syn region coffeeInterp matchgroup=coffeeInterpDelim start=/#{/ end=/}/ contained 140 | \ contains=@coffeeAll 141 | hi def link coffeeInterpDelim PreProc 142 | 143 | " A string escape sequence 144 | syn match coffeeEscape /\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\./ contained display 145 | hi def link coffeeEscape SpecialChar 146 | 147 | " A regex -- must not follow a parenthesis, number, or identifier, and must not 148 | " be followed by a number 149 | syn region coffeeRegex start=#\%(\%()\|\%(\i\|\$\)\@ 0 27 | let str .= '%' . current_name 28 | let tmp = '' 29 | for attr in emmet#util#unique(current.attrs_order + keys(current.attr)) 30 | if !has_key(current.attr, attr) 31 | continue 32 | endif 33 | let val = current.attr[attr] 34 | if dollar_expr 35 | while val =~ '\$\([^#{]\|$\)' 36 | let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') 37 | endwhile 38 | let attr = substitute(attr, '\$$', itemno+1, '') 39 | endif 40 | let valtmp = substitute(val, '\${cursor}', '', '') 41 | if attr == 'id' && len(valtmp) > 0 42 | let str .= '#' . val 43 | elseif attr == 'class' && len(valtmp) > 0 44 | let str .= '.' . substitute(val, ' ', '.', 'g') 45 | else 46 | if len(tmp) > 0 | let tmp .= ',' | endif 47 | let val = substitute(val, '\${cursor}', '', '') 48 | let tmp .= ' :' . attr . ' => "' . val . '"' 49 | endif 50 | endfor 51 | if len(tmp) 52 | let str .= '{' . tmp . ' }' 53 | endif 54 | if stridx(','.settings.html.empty_elements.',', ','.current_name.',') != -1 && len(current.value) == 0 55 | let str .= "/" 56 | endif 57 | 58 | let inner = '' 59 | if len(current.value) > 0 60 | let text = current.value[1:-2] 61 | if dollar_expr 62 | let text = substitute(text, '\%(\\\)\@\ 0 94 | for child in current.child 95 | let inner .= emmet#toString(child, type, inline, filters, itemno, indent) 96 | endfor 97 | let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g') 98 | let inner = substitute(inner, "\n" . escape(indent, '\') . "$", "", 'g') 99 | let str .= "\n" . indent . inner 100 | endif 101 | else 102 | let str = current.value[1:-2] 103 | if dollar_expr 104 | let str = substitute(str, '\%(\\\)\@\\s*\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)' 151 | while len(attrs) > 0 152 | let match = matchstr(attrs, mx) 153 | if len(match) == 0 154 | break 155 | endif 156 | let attr_match = matchlist(match, mx) 157 | let name = attr_match[1] 158 | let value = len(attr_match[2]) ? attr_match[2] : attr_match[3] 159 | let current.attr[name] = value 160 | let current.attrs_order += [name] 161 | let attrs = attrs[stridx(attrs, match) + len(match):] 162 | endwhile 163 | return current 164 | endfunction 165 | 166 | function! emmet#lang#haml#toggleComment() 167 | let line = getline('.') 168 | let space = matchstr(line, '^\s*') 169 | if line =~ '^\s*-#' 170 | call setline('.', space . matchstr(line[len(space)+2:], '^\s*\zs.*')) 171 | elseif line =~ '^\s*%[a-z]' 172 | call setline('.', space . '-# ' . line[len(space):]) 173 | endif 174 | endfunction 175 | 176 | function! emmet#lang#haml#balanceTag(flag) range 177 | let block = emmet#util#getVisualBlock() 178 | if a:flag == -2 || a:flag == 2 179 | let curpos = [0, line("'<"), col("'<"), 0] 180 | else 181 | let curpos = getpos('.') 182 | endif 183 | let n = curpos[1] 184 | let ml = len(matchstr(getline(n), '^\s*')) 185 | 186 | if a:flag > 0 187 | if a:flag == 1 || !emmet#util#regionIsValid(block) 188 | let n = line('.') 189 | else 190 | while n > 0 191 | let l = len(matchstr(getline(n), '^\s*\ze%[a-z]')) 192 | if l > 0 && l < ml 193 | let ml = l 194 | break 195 | endif 196 | let n -= 1 197 | endwhile 198 | endif 199 | let sn = n 200 | if n == 0 201 | let ml = 0 202 | endif 203 | while n < line('$') 204 | let l = len(matchstr(getline(n), '^\s*%[a-z]')) 205 | if l > 0 && l <= ml 206 | let n -= 1 207 | break 208 | endif 209 | let n += 1 210 | endwhile 211 | call setpos('.', [0, n, 1, 0]) 212 | normal! V 213 | call setpos('.', [0, sn, 1, 0]) 214 | else 215 | while n > 0 216 | let l = len(matchstr(getline(n), '^\s*\ze[a-z]')) 217 | if l > 0 && l > ml 218 | let ml = l 219 | break 220 | endif 221 | let n += 1 222 | endwhile 223 | let sn = n 224 | if n == 0 225 | let ml = 0 226 | endif 227 | while n < line('$') 228 | let l = len(matchstr(getline(n), '^\s*%[a-z]')) 229 | if l > 0 && l <= ml 230 | let n -= 1 231 | break 232 | endif 233 | let n += 1 234 | endwhile 235 | call setpos('.', [0, n, 1, 0]) 236 | normal! V 237 | call setpos('.', [0, sn, 1, 0]) 238 | endif 239 | endfunction 240 | 241 | function! emmet#lang#haml#moveNextPrev(flag) 242 | let pos = search('""', a:flag ? 'Wb' : 'W') 243 | if pos != 0 244 | silent! normal! l 245 | startinsert 246 | endif 247 | endfunction 248 | 249 | function! emmet#lang#haml#splitJoinTag() 250 | let n = line('.') 251 | let sml = len(matchstr(getline(n), '^\s*%[a-z]')) 252 | while n > 0 253 | if getline(n) =~ '^\s*\ze%[a-z]' 254 | if len(matchstr(getline(n), '^\s*%[a-z]')) < sml 255 | break 256 | endif 257 | let line = getline(n) 258 | call setline(n, substitute(line, '^\s*%\w\+\%(\s*{[^}]*}\|\s\)\zs.*', '', '')) 259 | let sn = n 260 | let n += 1 261 | let ml = len(matchstr(getline(n), '^\s*%[a-z]')) 262 | if len(matchstr(getline(n), '^\s*')) > ml 263 | while n <= line('$') 264 | let l = len(matchstr(getline(n), '^\s*')) 265 | if l <= ml 266 | break 267 | endif 268 | exe n "delete" 269 | endwhile 270 | call setpos('.', [0, sn, 1, 0]) 271 | else 272 | let tag = matchstr(getline(sn), '^\s*%\zs\(\w\+\)') 273 | let spaces = matchstr(getline(sn), '^\s*') 274 | let settings = emmet#getSettings() 275 | if stridx(','.settings.html.inline_elements.',', ','.tag.',') == -1 276 | call append(sn, spaces . ' ') 277 | call setpos('.', [0, sn+1, 1, 0]) 278 | else 279 | call setpos('.', [0, sn, 1, 0]) 280 | endif 281 | startinsert! 282 | endif 283 | break 284 | endif 285 | let n -= 1 286 | endwhile 287 | endfunction 288 | 289 | function! emmet#lang#haml#removeTag() 290 | let n = line('.') 291 | let ml = 0 292 | while n > 0 293 | if getline(n) =~ '^\s*\ze[a-z]' 294 | let ml = len(matchstr(getline(n), '^\s*%[a-z]')) 295 | break 296 | endif 297 | let n -= 1 298 | endwhile 299 | let sn = n 300 | while n < line('$') 301 | let l = len(matchstr(getline(n), '^\s*%[a-z]')) 302 | if l > 0 && l <= ml 303 | let n -= 1 304 | break 305 | endif 306 | let n += 1 307 | endwhile 308 | if sn == n 309 | exe "delete" 310 | else 311 | exe sn "," (n-1) "delete" 312 | endif 313 | endfunction 314 | -------------------------------------------------------------------------------- /autoload/emmet/util.vim: -------------------------------------------------------------------------------- 1 | "============================================================================== 2 | " region utils 3 | "============================================================================== 4 | " deleteContent : delete content in region 5 | " if region make from between '' and '' 6 | " -------------------- 7 | " begin: 8 | " :end 9 | " -------------------- 10 | " this function make the content as following 11 | " -------------------- 12 | " begin::end 13 | " -------------------- 14 | function! emmet#util#deleteContent(region) 15 | let lines = getline(a:region[0][0], a:region[1][0]) 16 | call setpos('.', [0, a:region[0][0], a:region[0][1], 0]) 17 | silent! exe "delete ".(a:region[1][0] - a:region[0][0]) 18 | call setline(line('.'), lines[0][:a:region[0][1]-2] . lines[-1][a:region[1][1]]) 19 | endfunction 20 | 21 | " change_content : change content in region 22 | " if region make from between '' and '' 23 | " -------------------- 24 | " begin: 25 | " :end 26 | " -------------------- 27 | " and content is 28 | " -------------------- 29 | " foo 30 | " bar 31 | " baz 32 | " -------------------- 33 | " this function make the content as following 34 | " -------------------- 35 | " begin:foo 36 | " bar 37 | " baz:end 38 | " -------------------- 39 | function! emmet#util#setContent(region, content) 40 | let newlines = split(a:content, '\n', 1) 41 | let oldlines = getline(a:region[0][0], a:region[1][0]) 42 | call setpos('.', [0, a:region[0][0], a:region[0][1], 0]) 43 | silent! exe "delete ".(a:region[1][0] - a:region[0][0]) 44 | if len(newlines) == 0 45 | let tmp = '' 46 | if a:region[0][1] > 1 47 | let tmp = oldlines[0][:a:region[0][1]-2] 48 | endif 49 | if a:region[1][1] >= 1 50 | let tmp .= oldlines[-1][a:region[1][1]:] 51 | endif 52 | call setline(line('.'), tmp) 53 | elseif len(newlines) == 1 54 | if a:region[0][1] > 1 55 | let newlines[0] = oldlines[0][:a:region[0][1]-2] . newlines[0] 56 | endif 57 | if a:region[1][1] >= 1 58 | let newlines[0] .= oldlines[-1][a:region[1][1]:] 59 | endif 60 | call setline(line('.'), newlines[0]) 61 | else 62 | if a:region[0][1] > 1 63 | let newlines[0] = oldlines[0][:a:region[0][1]-2] . newlines[0] 64 | endif 65 | if a:region[1][1] >= 1 66 | let newlines[-1] .= oldlines[-1][a:region[1][1]:] 67 | endif 68 | call setline(line('.'), newlines[0]) 69 | call append(line('.'), newlines[1:]) 70 | endif 71 | endfunction 72 | 73 | " select_region : select region 74 | " this function make a selection of region 75 | function! emmet#util#selectRegion(region) 76 | call setpos('.', [0, a:region[1][0], a:region[1][1], 0]) 77 | normal! v 78 | call setpos('.', [0, a:region[0][0], a:region[0][1], 0]) 79 | endfunction 80 | 81 | " point_in_region : check point is in the region 82 | " this function return 0 or 1 83 | function! emmet#util#pointInRegion(point, region) 84 | if !emmet#util#regionIsValid(a:region) | return 0 | endif 85 | if a:region[0][0] > a:point[0] | return 0 | endif 86 | if a:region[1][0] < a:point[0] | return 0 | endif 87 | if a:region[0][0] == a:point[0] && a:region[0][1] > a:point[1] | return 0 | endif 88 | if a:region[1][0] == a:point[0] && a:region[1][1] < a:point[1] | return 0 | endif 89 | return 1 90 | endfunction 91 | 92 | " cursor_in_region : check cursor is in the region 93 | " this function return 0 or 1 94 | function! emmet#util#cursorInRegion(region) 95 | if !emmet#util#regionIsValid(a:region) | return 0 | endif 96 | let cur = getpos('.')[1:2] 97 | return emmet#util#pointInRegion(cur, a:region) 98 | endfunction 99 | 100 | " region_is_valid : check region is valid 101 | " this function return 0 or 1 102 | function! emmet#util#regionIsValid(region) 103 | if a:region[0][0] == 0 || a:region[1][0] == 0 | return 0 | endif 104 | return 1 105 | endfunction 106 | 107 | " search_region : make region from pattern which is composing start/end 108 | " this function return array of position 109 | function! emmet#util#searchRegion(start, end) 110 | return [searchpairpos(a:start, '', a:end, 'bcnW'), searchpairpos(a:start, '\%#', a:end, 'nW')] 111 | endfunction 112 | 113 | " get_content : get content in region 114 | " this function return string in region 115 | function! emmet#util#getContent(region) 116 | if !emmet#util#regionIsValid(a:region) 117 | return '' 118 | endif 119 | let lines = getline(a:region[0][0], a:region[1][0]) 120 | if a:region[0][0] == a:region[1][0] 121 | let lines[0] = lines[0][a:region[0][1]-1:a:region[1][1]-1] 122 | else 123 | let lines[0] = lines[0][a:region[0][1]-1:] 124 | let lines[-1] = lines[-1][:a:region[1][1]-1] 125 | endif 126 | return join(lines, "\n") 127 | endfunction 128 | 129 | " region_in_region : check region is in the region 130 | " this function return 0 or 1 131 | function! emmet#util#regionInRegion(outer, inner) 132 | if !emmet#util#regionIsValid(a:inner) || !emmet#util#regionIsValid(a:outer) 133 | return 0 134 | endif 135 | return emmet#util#pointInRegion(a:inner[0], a:outer) && emmet#util#pointInRegion(a:inner[1], a:outer) 136 | endfunction 137 | 138 | " get_visualblock : get region of visual block 139 | " this function return region of visual block 140 | function! emmet#util#getVisualBlock() 141 | return [[line("'<"), col("'<")], [line("'>"), col("'>")]] 142 | endfunction 143 | 144 | "============================================================================== 145 | " html utils 146 | "============================================================================== 147 | function! emmet#util#getContentFromURL(url) 148 | let res = system(printf("%s %s", g:emmet_curl_command, shellescape(substitute(a:url, '#.*', '', '')))) 149 | let charset = matchstr(res, ']\+content=["''][^;"'']\+;\s*charset=\zs[^;"'']\+\ze["''][^>]*>') 150 | if len(charset) == 0 151 | let charset = matchstr(res, ']*>') 152 | endif 153 | if len(charset) == 0 154 | let s1 = len(split(res, '?')) 155 | let utf8 = iconv(res, 'utf-8', &encoding) 156 | let s2 = len(split(utf8, '?')) 157 | return (s2 == s1 || s2 >= s1 * 2) ? utf8 : res 158 | endif 159 | return iconv(res, charset, &encoding) 160 | endfunction 161 | 162 | function! emmet#util#getTextFromHTML(buf) 163 | let threshold_len = 100 164 | let threshold_per = 0.1 165 | let buf = a:buf 166 | 167 | let buf = strpart(buf, stridx(buf, '')) 168 | let buf = substitute(buf, ']*>.\{-}', '', 'g') 169 | let buf = substitute(buf, ']*>.\{-}', '', 'g') 170 | let res = '' 171 | let max = 0 172 | let mx = '\(]\{-}>\)\|\(<\/td>\)\|\(]\{-}>\)\|\(<\/div>\)' 173 | let m = split(buf, mx) 174 | for str in m 175 | let c = split(str, '<[^>]*?>') 176 | let str = substitute(str, '<[^>]\{-}>', ' ', 'g') 177 | let str = substitute(str, '>', '>', 'g') 178 | let str = substitute(str, '<', '<', 'g') 179 | let str = substitute(str, '"', '"', 'g') 180 | let str = substitute(str, ''', "'", 'g') 181 | let str = substitute(str, ' ', ' ', 'g') 182 | let str = substitute(str, '¥', '\¥', 'g') 183 | let str = substitute(str, '&', '\&', 'g') 184 | let str = substitute(str, '^\s*\(.*\)\s*$', '\1', '') 185 | let str = substitute(str, '\s\+', ' ', 'g') 186 | let l = len(str) 187 | if l > threshold_len 188 | let per = (l+0.0) / len(c) 189 | if max < l && per > threshold_per 190 | let max = l 191 | let res = str 192 | endif 193 | endif 194 | endfor 195 | let res = substitute(res, '^\s*\(.*\)\s*$', '\1', 'g') 196 | return res 197 | endfunction 198 | 199 | function! emmet#util#getImageSize(fn) 200 | let fn = a:fn 201 | 202 | if emmet#util#isImageMagickInstalled() 203 | return emmet#util#imageSizeWithImageMagick(fn) 204 | endif 205 | 206 | if filereadable(fn) 207 | let hex = substitute(system('xxd -p "'.fn.'"'), '\n', '', 'g') 208 | else 209 | let hex = substitute(system(g:emmet_curl_command.' "'.fn.'" | xxd -p'), '\n', '', 'g') 210 | endif 211 | 212 | let [width, height] = [-1, -1] 213 | if hex =~ '^89504e470d0a1a0a' 214 | let width = eval('0x'.hex[32:39]) 215 | let height = eval('0x'.hex[40:47]) 216 | endif 217 | if hex =~ '^ffd8' 218 | let pos = 4 219 | while pos < len(hex) 220 | let bs = hex[pos+0:pos+3] 221 | let pos += 4 222 | if bs == 'ffc0' || bs == 'ffc2' 223 | let pos += 6 224 | let height = eval('0x'.hex[pos+0:pos+1])*256 + eval('0x'.hex[pos+2:pos+3]) 225 | let pos += 4 226 | let width = eval('0x'.hex[pos+0:pos+1])*256 + eval('0x'.hex[pos+2:pos+3]) 227 | break 228 | elseif bs =~ 'ffd[9a]' 229 | break 230 | elseif bs =~ 'ff\(e[0-9a-e]\|fe\|db\|dd\|c4\)' 231 | let pos += (eval('0x'.hex[pos+0:pos+1])*256 + eval('0x'.hex[pos+2:pos+3])) * 2 232 | endif 233 | endwhile 234 | endif 235 | if hex =~ '^47494638' 236 | let width = eval('0x'.hex[14:15].hex[12:13]) 237 | let height = eval('0x'.hex[18:19].hex[16:17]) 238 | endif 239 | 240 | return [width, height] 241 | endfunction 242 | 243 | function! emmet#util#imageSizeWithImageMagick(fn) 244 | let fn = a:fn 245 | let img_info = system('identify -format "%wx%h" "'.a:fn.'"') 246 | let img_size = split(substitute(img_info, '\n', '', ''), 'x') 247 | if len(img_size) != 2 248 | return [-1, -1] 249 | endif 250 | return img_size 251 | endfunction 252 | 253 | function! emmet#util#isImageMagickInstalled() 254 | if !get(s:, 'emmet_use_identify', 1) 255 | return 0 256 | endif 257 | return executable('identify') 258 | endfunction 259 | 260 | function! emmet#util#unique(arr) 261 | let m = {} 262 | let r = [] 263 | for i in a:arr 264 | if !has_key(m, i) 265 | let m[i] = 1 266 | call add(r, i) 267 | endif 268 | endfor 269 | return r 270 | endfunction 271 | 272 | let s:seed = localtime() 273 | function! emmet#util#srand(seed) 274 | let s:seed = a:seed 275 | endfunction 276 | 277 | function! emmet#util#rand() 278 | let s:seed = s:seed * 214013 + 2531011 279 | return (s:seed < 0 ? s:seed - 0x80000000 : s:seed) / 0x10000 % 0x8000 280 | endfunction 281 | 282 | function! emmet#util#cache(name, ...) 283 | let content = get(a:000, 0, "") 284 | let dir = expand("~/.emmet/cache") 285 | if !isdirectory(dir) 286 | call mkdir(dir, "p", 0700) 287 | endif 288 | let file = dir . "/" . substitute(a:name, '\W', '_', 'g') 289 | if len(content) == 0 290 | if !filereadable(file) 291 | return "" 292 | endif 293 | return join(readfile(file), "\n") 294 | endif 295 | call writefile(split(content, "\n"), file) 296 | endfunction 297 | -------------------------------------------------------------------------------- /nerdtree_plugin/fs_menu.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================ 2 | " File: fs_menu.vim 3 | " Description: plugin for the NERD Tree that provides a file system menu 4 | " Maintainer: Martin Grenfell 5 | " Last Change: 17 July, 2009 6 | " License: This program is free software. It comes without any warranty, 7 | " to the extent permitted by applicable law. You can redistribute 8 | " it and/or modify it under the terms of the Do What The Fuck You 9 | " Want To Public License, Version 2, as published by Sam Hocevar. 10 | " See http://sam.zoy.org/wtfpl/COPYING for more details. 11 | " 12 | " ============================================================================ 13 | if exists("g:loaded_nerdtree_fs_menu") 14 | finish 15 | endif 16 | let g:loaded_nerdtree_fs_menu = 1 17 | 18 | "Automatically delete the buffer after deleting or renaming a file 19 | if !exists("g:NERDTreeAutoDeleteBuffer") 20 | let g:NERDTreeAutoDeleteBuffer = 0 21 | endif 22 | 23 | call NERDTreeAddMenuItem({'text': '(a)dd a childnode', 'shortcut': 'a', 'callback': 'NERDTreeAddNode'}) 24 | call NERDTreeAddMenuItem({'text': '(m)ove the current node', 'shortcut': 'm', 'callback': 'NERDTreeMoveNode'}) 25 | call NERDTreeAddMenuItem({'text': '(d)elete the current node', 'shortcut': 'd', 'callback': 'NERDTreeDeleteNode'}) 26 | 27 | if has("gui_mac") || has("gui_macvim") 28 | call NERDTreeAddMenuItem({'text': '(r)eveal in Finder the current node', 'shortcut': 'r', 'callback': 'NERDTreeRevealInFinder'}) 29 | call NERDTreeAddMenuItem({'text': '(o)pen the current node with system editor', 'shortcut': 'o', 'callback': 'NERDTreeExecuteFile'}) 30 | call NERDTreeAddMenuItem({'text': '(q)uicklook the current node', 'shortcut': 'q', 'callback': 'NERDTreeQuickLook'}) 31 | endif 32 | 33 | if g:NERDTreePath.CopyingSupported() 34 | call NERDTreeAddMenuItem({'text': '(c)opy the current node', 'shortcut': 'c', 'callback': 'NERDTreeCopyNode'}) 35 | endif 36 | 37 | "FUNCTION: s:echo(msg){{{1 38 | function! s:echo(msg) 39 | redraw 40 | echomsg "NERDTree: " . a:msg 41 | endfunction 42 | 43 | "FUNCTION: s:echoWarning(msg){{{1 44 | function! s:echoWarning(msg) 45 | echohl warningmsg 46 | call s:echo(a:msg) 47 | echohl normal 48 | endfunction 49 | 50 | "FUNCTION: s:promptToDelBuffer(bufnum, msg){{{1 51 | "prints out the given msg and, if the user responds by pushing 'y' then the 52 | "buffer with the given bufnum is deleted 53 | " 54 | "Args: 55 | "bufnum: the buffer that may be deleted 56 | "msg: a message that will be echoed to the user asking them if they wish to 57 | " del the buffer 58 | function! s:promptToDelBuffer(bufnum, msg) 59 | echo a:msg 60 | if g:NERDTreeAutoDeleteBuffer || nr2char(getchar()) ==# 'y' 61 | " 1. ensure that all windows which display the just deleted filename 62 | " now display an empty buffer (so a layout is preserved). 63 | " Is not it better to close single tabs with this file only ? 64 | let s:originalTabNumber = tabpagenr() 65 | let s:originalWindowNumber = winnr() 66 | exec "tabdo windo if winbufnr(0) == " . a:bufnum . " | exec ':enew! ' | endif" 67 | exec "tabnext " . s:originalTabNumber 68 | exec s:originalWindowNumber . "wincmd w" 69 | " 3. We don't need a previous buffer anymore 70 | exec "bwipeout! " . a:bufnum 71 | endif 72 | endfunction 73 | 74 | "FUNCTION: s:promptToRenameBuffer(bufnum, msg){{{1 75 | "prints out the given msg and, if the user responds by pushing 'y' then the 76 | "buffer with the given bufnum is replaced with a new one 77 | " 78 | "Args: 79 | "bufnum: the buffer that may be deleted 80 | "msg: a message that will be echoed to the user asking them if they wish to 81 | " del the buffer 82 | function! s:promptToRenameBuffer(bufnum, msg, newFileName) 83 | echo a:msg 84 | if g:NERDTreeAutoDeleteBuffer || nr2char(getchar()) ==# 'y' 85 | " 1. ensure that a new buffer is loaded 86 | exec "badd " . a:newFileName 87 | " 2. ensure that all windows which display the just deleted filename 88 | " display a buffer for a new filename. 89 | let s:originalTabNumber = tabpagenr() 90 | let s:originalWindowNumber = winnr() 91 | exec "tabdo windo if winbufnr(0) == " . a:bufnum . " | exec ':e! " . a:newFileName . "' | endif" 92 | exec "tabnext " . s:originalTabNumber 93 | exec s:originalWindowNumber . "wincmd w" 94 | " 3. We don't need a previous buffer anymore 95 | exec "bwipeout! " . a:bufnum 96 | endif 97 | endfunction 98 | "FUNCTION: NERDTreeAddNode(){{{1 99 | function! NERDTreeAddNode() 100 | let curDirNode = g:NERDTreeDirNode.GetSelected() 101 | 102 | let newNodeName = input("Add a childnode\n". 103 | \ "==========================================================\n". 104 | \ "Enter the dir/file name to be created. Dirs end with a '/'\n" . 105 | \ "", curDirNode.path.str() . g:NERDTreePath.Slash(), "file") 106 | 107 | if newNodeName ==# '' 108 | call s:echo("Node Creation Aborted.") 109 | return 110 | endif 111 | 112 | try 113 | let newPath = g:NERDTreePath.Create(newNodeName) 114 | let parentNode = b:NERDTreeRoot.findNode(newPath.getParent()) 115 | 116 | let newTreeNode = g:NERDTreeFileNode.New(newPath) 117 | if parentNode.isOpen || !empty(parentNode.children) 118 | call parentNode.addChild(newTreeNode, 1) 119 | call NERDTreeRender() 120 | call newTreeNode.putCursorHere(1, 0) 121 | endif 122 | catch /^NERDTree/ 123 | call s:echoWarning("Node Not Created.") 124 | endtry 125 | endfunction 126 | 127 | "FUNCTION: NERDTreeMoveNode(){{{1 128 | function! NERDTreeMoveNode() 129 | let curNode = g:NERDTreeFileNode.GetSelected() 130 | let newNodePath = input("Rename the current node\n" . 131 | \ "==========================================================\n" . 132 | \ "Enter the new path for the node: \n" . 133 | \ "", curNode.path.str(), "file") 134 | 135 | if newNodePath ==# '' 136 | call s:echo("Node Renaming Aborted.") 137 | return 138 | endif 139 | 140 | try 141 | let bufnum = bufnr(curNode.path.str()) 142 | 143 | call curNode.rename(newNodePath) 144 | call NERDTreeRender() 145 | 146 | "if the node is open in a buffer, ask the user if they want to 147 | "close that buffer 148 | if bufnum != -1 149 | let prompt = "\nNode renamed.\n\nThe old file is open in buffer ". bufnum . (bufwinnr(bufnum) ==# -1 ? " (hidden)" : "") .". Replace this buffer with a new file? (yN)" 150 | call s:promptToRenameBuffer(bufnum, prompt, newNodePath) 151 | endif 152 | 153 | call curNode.putCursorHere(1, 0) 154 | 155 | redraw 156 | catch /^NERDTree/ 157 | call s:echoWarning("Node Not Renamed.") 158 | endtry 159 | endfunction 160 | 161 | " FUNCTION: NERDTreeDeleteNode() {{{1 162 | function! NERDTreeDeleteNode() 163 | let currentNode = g:NERDTreeFileNode.GetSelected() 164 | let confirmed = 0 165 | 166 | if currentNode.path.isDirectory 167 | let choice =input("Delete the current node\n" . 168 | \ "==========================================================\n" . 169 | \ "STOP! To delete this entire directory, type 'yes'\n" . 170 | \ "" . currentNode.path.str() . ": ") 171 | let confirmed = choice ==# 'yes' 172 | else 173 | echo "Delete the current node\n" . 174 | \ "==========================================================\n". 175 | \ "Are you sure you wish to delete the node:\n" . 176 | \ "" . currentNode.path.str() . " (yN):" 177 | let choice = nr2char(getchar()) 178 | let confirmed = choice ==# 'y' 179 | endif 180 | 181 | 182 | if confirmed 183 | try 184 | call currentNode.delete() 185 | call NERDTreeRender() 186 | 187 | "if the node is open in a buffer, ask the user if they want to 188 | "close that buffer 189 | let bufnum = bufnr(currentNode.path.str()) 190 | if buflisted(bufnum) 191 | let prompt = "\nNode deleted.\n\nThe file is open in buffer ". bufnum . (bufwinnr(bufnum) ==# -1 ? " (hidden)" : "") .". Delete this buffer? (yN)" 192 | call s:promptToDelBuffer(bufnum, prompt) 193 | endif 194 | 195 | redraw 196 | catch /^NERDTree/ 197 | call s:echoWarning("Could not remove node") 198 | endtry 199 | else 200 | call s:echo("delete aborted") 201 | endif 202 | 203 | endfunction 204 | 205 | " FUNCTION: NERDTreeCopyNode() {{{1 206 | function! NERDTreeCopyNode() 207 | let currentNode = g:NERDTreeFileNode.GetSelected() 208 | let newNodePath = input("Copy the current node\n" . 209 | \ "==========================================================\n" . 210 | \ "Enter the new path to copy the node to: \n" . 211 | \ "", currentNode.path.str(), "file") 212 | 213 | if newNodePath != "" 214 | "strip trailing slash 215 | let newNodePath = substitute(newNodePath, '\/$', '', '') 216 | 217 | let confirmed = 1 218 | if currentNode.path.copyingWillOverwrite(newNodePath) 219 | call s:echo("Warning: copying may overwrite files! Continue? (yN)") 220 | let choice = nr2char(getchar()) 221 | let confirmed = choice ==# 'y' 222 | endif 223 | 224 | if confirmed 225 | try 226 | let newNode = currentNode.copy(newNodePath) 227 | if !empty(newNode) 228 | call NERDTreeRender() 229 | call newNode.putCursorHere(0, 0) 230 | endif 231 | catch /^NERDTree/ 232 | call s:echoWarning("Could not copy node") 233 | endtry 234 | endif 235 | else 236 | call s:echo("Copy aborted.") 237 | endif 238 | redraw 239 | endfunction 240 | 241 | function! NERDTreeQuickLook() 242 | let treenode = g:NERDTreeFileNode.GetSelected() 243 | if treenode != {} 244 | call system("qlmanage -p 2>/dev/null '" . treenode.path.str() . "'") 245 | endif 246 | endfunction 247 | 248 | function! NERDTreeRevealInFinder() 249 | let treenode = g:NERDTreeFileNode.GetSelected() 250 | if treenode != {} 251 | let x = system("open -R '" . treenode.path.str() . "'") 252 | endif 253 | endfunction 254 | 255 | function! NERDTreeExecuteFile() 256 | let treenode = g:NERDTreeFileNode.GetSelected() 257 | if treenode != {} 258 | let x = system("open '" . treenode.path.str() . "'") 259 | endif 260 | endfunction 261 | 262 | " vim: set sw=4 sts=4 et fdm=marker: 263 | -------------------------------------------------------------------------------- /lib/nerdtree/creator.vim: -------------------------------------------------------------------------------- 1 | "CLASS: Creator 2 | "Creates primary/secondary/mirror nerdtree windows. Sets up all the window and 3 | "buffer options and key mappings etc. 4 | "============================================================ 5 | let s:Creator = {} 6 | let g:NERDTreeCreator = s:Creator 7 | 8 | "FUNCTION: s:Creator._bindMappings() {{{1 9 | function! s:Creator._bindMappings() 10 | "make do the same as the default 'o' mapping 11 | exec "nnoremap :call nerdtree#invokeKeyMap('". g:NERDTreeMapActivateNode ."')" 12 | 13 | call g:NERDTreeKeyMap.BindAll() 14 | 15 | command! -buffer -nargs=? Bookmark :call nerdtree#bookmarkNode('') 16 | command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=1 RevealBookmark :call nerdtree#revealBookmark('') 17 | command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=1 OpenBookmark :call nerdtree#openBookmark('') 18 | command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=* ClearBookmarks call nerdtree#clearBookmarks('') 19 | command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=+ BookmarkToRoot call g:NERDTreeBookmark.ToRoot('') 20 | command! -buffer -nargs=0 ClearAllBookmarks call g:NERDTreeBookmark.ClearAll() call nerdtree#renderView() 21 | command! -buffer -nargs=0 ReadBookmarks call g:NERDTreeBookmark.CacheBookmarks(0) call nerdtree#renderView() 22 | command! -buffer -nargs=0 WriteBookmarks call g:NERDTreeBookmark.Write() 23 | endfunction 24 | 25 | "FUNCTION: s:Creator._broadcastInitEvent() {{{1 26 | function! s:Creator._broadcastInitEvent() 27 | silent doautocmd User NERDTreeInit 28 | endfunction 29 | 30 | " FUNCTION: s:Creator.BufNamePrefix() {{{2 31 | function! s:Creator.BufNamePrefix() 32 | return 'NERD_tree_' 33 | endfunction 34 | 35 | "FUNCTION: s:Creator.CreatePrimary(a:name) {{{1 36 | function! s:Creator.CreatePrimary(name) 37 | let creator = s:Creator.New() 38 | call creator.createPrimary(a:name) 39 | endfunction 40 | 41 | "FUNCTION: s:Creator.createPrimary(a:name) {{{1 42 | "name: the name of a bookmark or a directory 43 | function! s:Creator.createPrimary(name) 44 | let path = self._pathForString(a:name) 45 | 46 | "if instructed to, then change the vim CWD to the dir the NERDTree is 47 | "inited in 48 | if g:NERDTreeChDirMode != 0 49 | call path.changeToDir() 50 | endif 51 | 52 | if nerdtree#treeExistsForTab() 53 | if nerdtree#isTreeOpen() 54 | call nerdtree#closeTree() 55 | endif 56 | unlet t:NERDTreeBufName 57 | endif 58 | 59 | let newRoot = g:NERDTreeDirNode.New(path) 60 | call newRoot.open() 61 | 62 | call self._createTreeWin() 63 | let b:treeShowHelp = 0 64 | let b:NERDTreeIgnoreEnabled = 1 65 | let b:NERDTreeShowFiles = g:NERDTreeShowFiles 66 | let b:NERDTreeShowHidden = g:NERDTreeShowHidden 67 | let b:NERDTreeShowBookmarks = g:NERDTreeShowBookmarks 68 | let b:NERDTreeRoot = newRoot 69 | let b:NERDTreeType = "primary" 70 | 71 | call nerdtree#renderView() 72 | call b:NERDTreeRoot.putCursorHere(0, 0) 73 | 74 | call self._broadcastInitEvent() 75 | endfunction 76 | 77 | "FUNCTION: s:Creator.CreateSecondary(dir) {{{1 78 | function! s:Creator.CreateSecondary(dir) 79 | let creator = s:Creator.New() 80 | call creator.createSecondary(a:dir) 81 | endfunction 82 | 83 | "FUNCTION: s:Creator.createSecondary(dir) {{{1 84 | function! s:Creator.createSecondary(dir) 85 | try 86 | let path = g:NERDTreePath.New(a:dir) 87 | catch /^NERDTree.InvalidArgumentsError/ 88 | call nerdtree#echo("Invalid directory name:" . a:name) 89 | return 90 | endtry 91 | 92 | "we want the directory buffer to disappear when we do the :edit below 93 | setlocal bufhidden=wipe 94 | 95 | let previousBuf = expand("#") 96 | 97 | "we need a unique name for each secondary tree buffer to ensure they are 98 | "all independent 99 | exec "silent edit " . self._nextBufferName() 100 | 101 | let b:NERDTreePreviousBuf = bufnr(previousBuf) 102 | 103 | let b:NERDTreeRoot = g:NERDTreeDirNode.New(path) 104 | call b:NERDTreeRoot.open() 105 | 106 | call self._setCommonBufOptions() 107 | let b:NERDTreeType = "secondary" 108 | 109 | call nerdtree#renderView() 110 | 111 | call self._broadcastInitEvent() 112 | endfunction 113 | 114 | " FUNCTION: s:Creator.CreateMirror() {{{1 115 | function! s:Creator.CreateMirror() 116 | let creator = s:Creator.New() 117 | call creator.createMirror() 118 | endfunction 119 | 120 | " FUNCTION: s:Creator.createMirror() {{{1 121 | function! s:Creator.createMirror() 122 | "get the names off all the nerd tree buffers 123 | let treeBufNames = [] 124 | for i in range(1, tabpagenr("$")) 125 | let nextName = nerdtree#tabpagevar(i, 'NERDTreeBufName') 126 | if nextName != -1 && (!exists("t:NERDTreeBufName") || nextName != t:NERDTreeBufName) 127 | call add(treeBufNames, nextName) 128 | endif 129 | endfor 130 | let treeBufNames = nerdtree#unique(treeBufNames) 131 | 132 | "map the option names (that the user will be prompted with) to the nerd 133 | "tree buffer names 134 | let options = {} 135 | let i = 0 136 | while i < len(treeBufNames) 137 | let bufName = treeBufNames[i] 138 | let treeRoot = getbufvar(bufName, "NERDTreeRoot") 139 | let options[i+1 . '. ' . treeRoot.path.str() . ' (buf name: ' . bufName . ')'] = bufName 140 | let i = i + 1 141 | endwhile 142 | 143 | "work out which tree to mirror, if there is more than 1 then ask the user 144 | let bufferName = '' 145 | if len(keys(options)) > 1 146 | let choices = ["Choose a tree to mirror"] 147 | let choices = extend(choices, sort(keys(options))) 148 | let choice = inputlist(choices) 149 | if choice < 1 || choice > len(options) || choice ==# '' 150 | return 151 | endif 152 | 153 | let bufferName = options[sort(keys(options))[choice-1]] 154 | elseif len(keys(options)) ==# 1 155 | let bufferName = values(options)[0] 156 | else 157 | call nerdtree#echo("No trees to mirror") 158 | return 159 | endif 160 | 161 | if nerdtree#treeExistsForTab() && nerdtree#isTreeOpen() 162 | call nerdtree#closeTree() 163 | endif 164 | 165 | let t:NERDTreeBufName = bufferName 166 | call self._createTreeWin() 167 | exec 'buffer ' . bufferName 168 | if !&hidden 169 | call nerdtree#renderView() 170 | endif 171 | endfunction 172 | 173 | "FUNCTION: s:Creator._createTreeWin() {{{1 174 | "Inits the NERD tree window. ie. opens it, sizes it, sets all the local 175 | "options etc 176 | function! s:Creator._createTreeWin() 177 | "create the nerd tree window 178 | let splitLocation = g:NERDTreeWinPos ==# "left" ? "topleft " : "botright " 179 | let splitSize = g:NERDTreeWinSize 180 | 181 | if !exists('t:NERDTreeBufName') 182 | let t:NERDTreeBufName = self._nextBufferName() 183 | silent! exec splitLocation . 'vertical ' . splitSize . ' new' 184 | silent! exec "edit " . t:NERDTreeBufName 185 | else 186 | silent! exec splitLocation . 'vertical ' . splitSize . ' split' 187 | silent! exec "buffer " . t:NERDTreeBufName 188 | endif 189 | 190 | setlocal winfixwidth 191 | call self._setCommonBufOptions() 192 | endfunction 193 | 194 | "FUNCTION: s:Creator.New() {{{1 195 | function! s:Creator.New() 196 | let newCreator = copy(self) 197 | return newCreator 198 | endfunction 199 | 200 | " FUNCTION: s:Creator._nextBufferName() {{{2 201 | " returns the buffer name for the next nerd tree 202 | function! s:Creator._nextBufferName() 203 | let name = s:Creator.BufNamePrefix() . self._nextBufferNumber() 204 | return name 205 | endfunction 206 | 207 | " FUNCTION: s:Creator._nextBufferNumber() {{{2 208 | " the number to add to the nerd tree buffer name to make the buf name unique 209 | function! s:Creator._nextBufferNumber() 210 | if !exists("s:Creator._NextBufNum") 211 | let s:Creator._NextBufNum = 1 212 | else 213 | let s:Creator._NextBufNum += 1 214 | endif 215 | 216 | return s:Creator._NextBufNum 217 | endfunction 218 | 219 | "FUNCTION: s:Creator._pathForString(str) {{{1 220 | "find a bookmark or adirectory for the given string 221 | function! s:Creator._pathForString(str) 222 | let path = {} 223 | if g:NERDTreeBookmark.BookmarkExistsFor(a:str) 224 | let path = g:NERDTreeBookmark.BookmarkFor(a:str).path 225 | else 226 | let dir = a:str ==# '' ? getcwd() : a:str 227 | 228 | "hack to get an absolute path if a relative path is given 229 | if dir =~# '^\.' 230 | let dir = getcwd() . g:NERDTreePath.Slash() . dir 231 | endif 232 | let dir = g:NERDTreePath.Resolve(dir) 233 | 234 | try 235 | let path = g:NERDTreePath.New(dir) 236 | catch /^NERDTree.InvalidArgumentsError/ 237 | call nerdtree#echo("No bookmark or directory found for: " . a:str) 238 | return 239 | endtry 240 | endif 241 | if !path.isDirectory 242 | let path = path.getParent() 243 | endif 244 | 245 | return path 246 | endfunction 247 | 248 | "FUNCTION: s:Creator._setCommonBufOptions() {{{1 249 | function! s:Creator._setCommonBufOptions() 250 | "throwaway buffer options 251 | setlocal noswapfile 252 | setlocal buftype=nofile 253 | setlocal bufhidden=hide 254 | setlocal nowrap 255 | setlocal foldcolumn=0 256 | setlocal foldmethod=manual 257 | setlocal nofoldenable 258 | setlocal nobuflisted 259 | setlocal nospell 260 | if g:NERDTreeShowLineNumbers 261 | setlocal nu 262 | else 263 | setlocal nonu 264 | if v:version >= 703 265 | setlocal nornu 266 | endif 267 | endif 268 | 269 | iabc 270 | 271 | if g:NERDTreeHighlightCursorline 272 | setlocal cursorline 273 | endif 274 | 275 | call self._setupStatusline() 276 | 277 | let b:treeShowHelp = 0 278 | let b:NERDTreeIgnoreEnabled = 1 279 | let b:NERDTreeShowFiles = g:NERDTreeShowFiles 280 | let b:NERDTreeShowHidden = g:NERDTreeShowHidden 281 | let b:NERDTreeShowBookmarks = g:NERDTreeShowBookmarks 282 | setfiletype nerdtree 283 | call self._bindMappings() 284 | endfunction 285 | 286 | "FUNCTION: s:Creator._setupStatusline() {{{1 287 | function! s:Creator._setupStatusline() 288 | if g:NERDTreeStatusline != -1 289 | let &l:statusline = g:NERDTreeStatusline 290 | endif 291 | endfunction 292 | 293 | "FUNCTION: s:Creator.TogglePrimary(dir) {{{1 294 | function! s:Creator.TogglePrimary(dir) 295 | let creator = s:Creator.New() 296 | call creator.togglePrimary(a:dir) 297 | endfunction 298 | 299 | "FUNCTION: s:Creator.togglePrimary(dir) {{{1 300 | "Toggles the NERD tree. I.e the NERD tree is open, it is closed, if it is 301 | "closed it is restored or initialized (if it doesnt exist) 302 | " 303 | "Args: 304 | "dir: the full path for the root node (is only used if the NERD tree is being 305 | "initialized. 306 | function! s:Creator.togglePrimary(dir) 307 | if nerdtree#treeExistsForTab() 308 | if !nerdtree#isTreeOpen() 309 | call self._createTreeWin() 310 | if !&hidden 311 | call nerdtree#renderView() 312 | endif 313 | call nerdtree#restoreScreenState() 314 | else 315 | call nerdtree#closeTree() 316 | endif 317 | else 318 | call self.createPrimary(a:dir) 319 | endif 320 | endfunction 321 | 322 | " vim: set sw=4 sts=4 et fdm=marker: 323 | -------------------------------------------------------------------------------- /lib/nerdtree/bookmark.vim: -------------------------------------------------------------------------------- 1 | "CLASS: Bookmark 2 | "============================================================ 3 | let s:Bookmark = {} 4 | let g:NERDTreeBookmark = s:Bookmark 5 | 6 | " FUNCTION: Bookmark.activate() {{{1 7 | function! s:Bookmark.activate(...) 8 | call self.open(a:0 ? a:1 : {}) 9 | endfunction 10 | 11 | " FUNCTION: Bookmark.AddBookmark(name, path) {{{1 12 | " Class method to add a new bookmark to the list, if a previous bookmark exists 13 | " with the same name, just update the path for that bookmark 14 | function! s:Bookmark.AddBookmark(name, path) 15 | for i in s:Bookmark.Bookmarks() 16 | if i.name ==# a:name 17 | let i.path = a:path 18 | return 19 | endif 20 | endfor 21 | call add(s:Bookmark.Bookmarks(), s:Bookmark.New(a:name, a:path)) 22 | call s:Bookmark.Sort() 23 | endfunction 24 | 25 | " FUNCTION: Bookmark.Bookmarks() {{{1 26 | " Class method to get all bookmarks. Lazily initializes the bookmarks global 27 | " variable 28 | function! s:Bookmark.Bookmarks() 29 | if !exists("g:NERDTreeBookmarks") 30 | let g:NERDTreeBookmarks = [] 31 | endif 32 | return g:NERDTreeBookmarks 33 | endfunction 34 | 35 | " FUNCTION: Bookmark.BookmarkExistsFor(name) {{{1 36 | " class method that returns 1 if a bookmark with the given name is found, 0 37 | " otherwise 38 | function! s:Bookmark.BookmarkExistsFor(name) 39 | try 40 | call s:Bookmark.BookmarkFor(a:name) 41 | return 1 42 | catch /^NERDTree.BookmarkNotFoundError/ 43 | return 0 44 | endtry 45 | endfunction 46 | 47 | " FUNCTION: Bookmark.BookmarkFor(name) {{{1 48 | " Class method to get the bookmark that has the given name. {} is return if no 49 | " bookmark is found 50 | function! s:Bookmark.BookmarkFor(name) 51 | for i in s:Bookmark.Bookmarks() 52 | if i.name ==# a:name 53 | return i 54 | endif 55 | endfor 56 | throw "NERDTree.BookmarkNotFoundError: no bookmark found for name: \"". a:name .'"' 57 | endfunction 58 | 59 | " FUNCTION: Bookmark.BookmarkNames() {{{1 60 | " Class method to return an array of all bookmark names 61 | function! s:Bookmark.BookmarkNames() 62 | let names = [] 63 | for i in s:Bookmark.Bookmarks() 64 | call add(names, i.name) 65 | endfor 66 | return names 67 | endfunction 68 | 69 | " FUNCTION: Bookmark.CacheBookmarks(silent) {{{1 70 | " Class method to read all bookmarks from the bookmarks file initialize 71 | " bookmark objects for each one. 72 | " 73 | " Args: 74 | " silent - dont echo an error msg if invalid bookmarks are found 75 | function! s:Bookmark.CacheBookmarks(silent) 76 | if filereadable(g:NERDTreeBookmarksFile) 77 | let g:NERDTreeBookmarks = [] 78 | let g:NERDTreeInvalidBookmarks = [] 79 | let bookmarkStrings = readfile(g:NERDTreeBookmarksFile) 80 | let invalidBookmarksFound = 0 81 | for i in bookmarkStrings 82 | 83 | "ignore blank lines 84 | if i != '' 85 | 86 | let name = substitute(i, '^\(.\{-}\) .*$', '\1', '') 87 | let path = substitute(i, '^.\{-} \(.*\)$', '\1', '') 88 | 89 | try 90 | let bookmark = s:Bookmark.New(name, g:NERDTreePath.New(path)) 91 | call add(g:NERDTreeBookmarks, bookmark) 92 | catch /^NERDTree.InvalidArgumentsError/ 93 | call add(g:NERDTreeInvalidBookmarks, i) 94 | let invalidBookmarksFound += 1 95 | endtry 96 | endif 97 | endfor 98 | if invalidBookmarksFound 99 | call s:Bookmark.Write() 100 | if !a:silent 101 | call nerdtree#echo(invalidBookmarksFound . " invalid bookmarks were read. See :help NERDTreeInvalidBookmarks for info.") 102 | endif 103 | endif 104 | call s:Bookmark.Sort() 105 | endif 106 | endfunction 107 | 108 | " FUNCTION: Bookmark.compareTo(otherbookmark) {{{1 109 | " Compare these two bookmarks for sorting purposes 110 | function! s:Bookmark.compareTo(otherbookmark) 111 | return a:otherbookmark.name < self.name 112 | endfunction 113 | " FUNCTION: Bookmark.ClearAll() {{{1 114 | " Class method to delete all bookmarks. 115 | function! s:Bookmark.ClearAll() 116 | for i in s:Bookmark.Bookmarks() 117 | call i.delete() 118 | endfor 119 | call s:Bookmark.Write() 120 | endfunction 121 | 122 | " FUNCTION: Bookmark.delete() {{{1 123 | " Delete this bookmark. If the node for this bookmark is under the current 124 | " root, then recache bookmarks for its Path object 125 | function! s:Bookmark.delete() 126 | let node = {} 127 | try 128 | let node = self.getNode(1) 129 | catch /^NERDTree.BookmarkedNodeNotFoundError/ 130 | endtry 131 | call remove(s:Bookmark.Bookmarks(), index(s:Bookmark.Bookmarks(), self)) 132 | if !empty(node) 133 | call node.path.cacheDisplayString() 134 | endif 135 | call s:Bookmark.Write() 136 | endfunction 137 | 138 | " FUNCTION: Bookmark.getNode(searchFromAbsoluteRoot) {{{1 139 | " Gets the treenode for this bookmark 140 | " 141 | " Args: 142 | " searchFromAbsoluteRoot: specifies whether we should search from the current 143 | " tree root, or the highest cached node 144 | function! s:Bookmark.getNode(searchFromAbsoluteRoot) 145 | let searchRoot = a:searchFromAbsoluteRoot ? g:NERDTreeDirNode.AbsoluteTreeRoot() : b:NERDTreeRoot 146 | let targetNode = searchRoot.findNode(self.path) 147 | if empty(targetNode) 148 | throw "NERDTree.BookmarkedNodeNotFoundError: no node was found for bookmark: " . self.name 149 | endif 150 | return targetNode 151 | endfunction 152 | 153 | " FUNCTION: Bookmark.GetNodeForName(name, searchFromAbsoluteRoot) {{{1 154 | " Class method that finds the bookmark with the given name and returns the 155 | " treenode for it. 156 | function! s:Bookmark.GetNodeForName(name, searchFromAbsoluteRoot) 157 | let bookmark = s:Bookmark.BookmarkFor(a:name) 158 | return bookmark.getNode(a:searchFromAbsoluteRoot) 159 | endfunction 160 | 161 | " FUNCTION: Bookmark.GetSelected() {{{1 162 | " returns the Bookmark the cursor is over, or {} 163 | function! s:Bookmark.GetSelected() 164 | let line = getline(".") 165 | let name = substitute(line, '^>\(.\{-}\) .\+$', '\1', '') 166 | if name != line 167 | try 168 | return s:Bookmark.BookmarkFor(name) 169 | catch /^NERDTree.BookmarkNotFoundError/ 170 | return {} 171 | endtry 172 | endif 173 | return {} 174 | endfunction 175 | 176 | " FUNCTION: Bookmark.InvalidBookmarks() {{{1 177 | " Class method to get all invalid bookmark strings read from the bookmarks 178 | " file 179 | function! s:Bookmark.InvalidBookmarks() 180 | if !exists("g:NERDTreeInvalidBookmarks") 181 | let g:NERDTreeInvalidBookmarks = [] 182 | endif 183 | return g:NERDTreeInvalidBookmarks 184 | endfunction 185 | 186 | " FUNCTION: Bookmark.mustExist() {{{1 187 | function! s:Bookmark.mustExist() 188 | if !self.path.exists() 189 | call s:Bookmark.CacheBookmarks(1) 190 | throw "NERDTree.BookmarkPointsToInvalidLocationError: the bookmark \"". 191 | \ self.name ."\" points to a non existing location: \"". self.path.str() 192 | endif 193 | endfunction 194 | 195 | " FUNCTION: Bookmark.New(name, path) {{{1 196 | " Create a new bookmark object with the given name and path object 197 | function! s:Bookmark.New(name, path) 198 | if a:name =~# ' ' 199 | throw "NERDTree.IllegalBookmarkNameError: illegal name:" . a:name 200 | endif 201 | 202 | let newBookmark = copy(self) 203 | let newBookmark.name = a:name 204 | let newBookmark.path = a:path 205 | return newBookmark 206 | endfunction 207 | 208 | " FUNCTION: Bookmark.open([options]) {{{1 209 | "Args: 210 | "A dictionary containing the following keys (all optional): 211 | " 'where': Specifies whether the node should be opened in new split/tab or in 212 | " the previous window. Can be either 'v' (vertical split), 'h' 213 | " (horizontal split), 't' (new tab) or 'p' (previous window). 214 | " 'reuse': if a window is displaying the file then jump the cursor there 215 | " 'keepopen': dont close the tree window 216 | " 'stay': open the file, but keep the cursor in the tree win 217 | " 218 | function! s:Bookmark.open(...) 219 | let opts = a:0 ? a:1 : {} 220 | 221 | if self.path.isDirectory && !has_key(opts, 'where') 222 | call self.toRoot() 223 | else 224 | let opener = g:NERDTreeOpener.New(self.path, opts) 225 | call opener.open(self) 226 | endif 227 | endfunction 228 | 229 | " FUNCTION: Bookmark.openInNewTab(options) {{{1 230 | " Create a new bookmark object with the given name and path object 231 | function! s:Bookmark.openInNewTab(options) 232 | call nerdtree#deprecated('Bookmark.openInNewTab', 'is deprecated, use open() instead') 233 | call self.open(a:options) 234 | endfunction 235 | 236 | " FUNCTION: Bookmark.setPath(path) {{{1 237 | " makes this bookmark point to the given path 238 | function! s:Bookmark.setPath(path) 239 | let self.path = a:path 240 | endfunction 241 | 242 | " FUNCTION: Bookmark.Sort() {{{1 243 | " Class method that sorts all bookmarks 244 | function! s:Bookmark.Sort() 245 | let CompareFunc = function("nerdtree#compareBookmarks") 246 | call sort(s:Bookmark.Bookmarks(), CompareFunc) 247 | endfunction 248 | 249 | " FUNCTION: Bookmark.str() {{{1 250 | " Get the string that should be rendered in the view for this bookmark 251 | function! s:Bookmark.str() 252 | let pathStrMaxLen = winwidth(nerdtree#getTreeWinNum()) - 4 - len(self.name) 253 | if &nu 254 | let pathStrMaxLen = pathStrMaxLen - &numberwidth 255 | endif 256 | 257 | let pathStr = self.path.str({'format': 'UI'}) 258 | if len(pathStr) > pathStrMaxLen 259 | let pathStr = '<' . strpart(pathStr, len(pathStr) - pathStrMaxLen) 260 | endif 261 | return '>' . self.name . ' ' . pathStr 262 | endfunction 263 | 264 | " FUNCTION: Bookmark.toRoot() {{{1 265 | " Make the node for this bookmark the new tree root 266 | function! s:Bookmark.toRoot() 267 | if self.validate() 268 | try 269 | let targetNode = self.getNode(1) 270 | catch /^NERDTree.BookmarkedNodeNotFoundError/ 271 | let targetNode = g:NERDTreeFileNode.New(s:Bookmark.BookmarkFor(self.name).path) 272 | endtry 273 | call targetNode.makeRoot() 274 | call nerdtree#renderView() 275 | call targetNode.putCursorHere(0, 0) 276 | endif 277 | endfunction 278 | 279 | " FUNCTION: Bookmark.ToRoot(name) {{{1 280 | " Make the node for this bookmark the new tree root 281 | function! s:Bookmark.ToRoot(name) 282 | let bookmark = s:Bookmark.BookmarkFor(a:name) 283 | call bookmark.toRoot() 284 | endfunction 285 | 286 | " FUNCTION: Bookmark.validate() {{{1 287 | function! s:Bookmark.validate() 288 | if self.path.exists() 289 | return 1 290 | else 291 | call s:Bookmark.CacheBookmarks(1) 292 | call nerdtree#renderView() 293 | call nerdtree#echo(self.name . "now points to an invalid location. See :help NERDTreeInvalidBookmarks for info.") 294 | return 0 295 | endif 296 | endfunction 297 | 298 | " FUNCTION: Bookmark.Write() {{{1 299 | " Class method to write all bookmarks to the bookmarks file 300 | function! s:Bookmark.Write() 301 | let bookmarkStrings = [] 302 | for i in s:Bookmark.Bookmarks() 303 | call add(bookmarkStrings, i.name . ' ' . i.path.str()) 304 | endfor 305 | 306 | "add a blank line before the invalid ones 307 | call add(bookmarkStrings, "") 308 | 309 | for j in s:Bookmark.InvalidBookmarks() 310 | call add(bookmarkStrings, j) 311 | endfor 312 | call writefile(bookmarkStrings, g:NERDTreeBookmarksFile) 313 | endfunction 314 | 315 | " vim: set sw=4 sts=4 et fdm=marker: 316 | -------------------------------------------------------------------------------- /ftplugin/coffee.vim: -------------------------------------------------------------------------------- 1 | " Language: CoffeeScript 2 | " Maintainer: Mick Koch 3 | " URL: http://github.com/kchmck/vim-coffee-script 4 | " License: WTFPL 5 | 6 | if exists('b:did_ftplugin') 7 | finish 8 | endif 9 | 10 | let b:did_ftplugin = 1 11 | call coffee#CoffeeSetUpVariables() 12 | 13 | setlocal formatoptions-=t formatoptions+=croql 14 | setlocal comments=:# commentstring=#\ %s 15 | setlocal omnifunc=javascriptcomplete#CompleteJS 16 | setlocal suffixesadd+=coffee 17 | 18 | " Create custom augroups. 19 | augroup CoffeeBufUpdate | augroup END 20 | augroup CoffeeBufNew | augroup END 21 | 22 | " Enable coffee compiler if a compiler isn't set already. 23 | if !len(&l:makeprg) 24 | compiler coffee 25 | endif 26 | 27 | " Switch to the window for buf. 28 | function! s:SwitchWindow(buf) 29 | exec bufwinnr(a:buf) 'wincmd w' 30 | endfunction 31 | 32 | " Create a new scratch buffer and return the bufnr of it. After the function 33 | " returns, vim remains in the scratch buffer so more set up can be done. 34 | function! s:ScratchBufBuild(src, vert, size) 35 | if a:size <= 0 36 | if a:vert 37 | let size = winwidth(bufwinnr(a:src)) / 2 38 | else 39 | let size = winheight(bufwinnr(a:src)) / 2 40 | endif 41 | endif 42 | 43 | if a:vert 44 | vertical belowright new 45 | exec 'vertical resize' size 46 | else 47 | belowright new 48 | exec 'resize' size 49 | endif 50 | 51 | setlocal bufhidden=wipe buftype=nofile nobuflisted noswapfile nomodifiable 52 | nnoremap q :hide 53 | 54 | return bufnr('%') 55 | endfunction 56 | 57 | " Replace buffer contents with text and delete the last empty line. 58 | function! s:ScratchBufUpdate(buf, text) 59 | " Move to the scratch buffer. 60 | call s:SwitchWindow(a:buf) 61 | 62 | " Double check we're in the scratch buffer before overwriting. 63 | if bufnr('%') != a:buf 64 | throw 'unable to change to scratch buffer' 65 | endif 66 | 67 | setlocal modifiable 68 | silent exec '% delete _' 69 | silent put! =a:text 70 | silent exec '$ delete _' 71 | setlocal nomodifiable 72 | endfunction 73 | 74 | " Parse the output of coffee into a qflist entry for src buffer. 75 | function! s:ParseCoffeeError(output, src, startline) 76 | " Coffee error is always on first line? 77 | let match = matchlist(a:output, 78 | \ '^\(\f\+\|\[stdin\]\):\(\d\):\(\d\): error: \(.\{-}\)' . "\n") 79 | 80 | if !len(match) 81 | return 82 | endif 83 | 84 | " Consider the line number from coffee as relative and add it to the beginning 85 | " line number of the range the command was called on, then subtract one for 86 | " zero-based relativity. 87 | call setqflist([{'bufnr': a:src, 'lnum': a:startline + str2nr(match[2]) - 1, 88 | \ 'type': 'E', 'col': str2nr(match[3]), 'text': match[4]}], 'r') 89 | endfunction 90 | 91 | " Reset source buffer variables. 92 | function! s:CoffeeCompileResetVars() 93 | " Variables defined in source buffer: 94 | " b:coffee_compile_buf: bufnr of output buffer 95 | " Variables defined in output buffer: 96 | " b:coffee_src_buf: bufnr of source buffer 97 | " b:coffee_compile_pos: previous cursor position in output buffer 98 | 99 | let b:coffee_compile_buf = -1 100 | endfunction 101 | 102 | function! s:CoffeeWatchResetVars() 103 | " Variables defined in source buffer: 104 | " b:coffee_watch_buf: bufnr of output buffer 105 | " Variables defined in output buffer: 106 | " b:coffee_src_buf: bufnr of source buffer 107 | " b:coffee_watch_pos: previous cursor position in output buffer 108 | 109 | let b:coffee_watch_buf = -1 110 | endfunction 111 | 112 | function! s:CoffeeRunResetVars() 113 | " Variables defined in CoffeeRun source buffer: 114 | " b:coffee_run_buf: bufnr of output buffer 115 | " Variables defined in CoffeeRun output buffer: 116 | " b:coffee_src_buf: bufnr of source buffer 117 | " b:coffee_run_pos: previous cursor position in output buffer 118 | 119 | let b:coffee_run_buf = -1 120 | endfunction 121 | 122 | " Clean things up in the source buffers. 123 | function! s:CoffeeCompileClose() 124 | " Switch to the source buffer if not already in it. 125 | silent! call s:SwitchWindow(b:coffee_src_buf) 126 | call s:CoffeeCompileResetVars() 127 | endfunction 128 | 129 | function! s:CoffeeWatchClose() 130 | silent! call s:SwitchWindow(b:coffee_src_buf) 131 | silent! autocmd! CoffeeAuWatch * 132 | call s:CoffeeWatchResetVars() 133 | endfunction 134 | 135 | function! s:CoffeeRunClose() 136 | silent! call s:SwitchWindow(b:coffee_src_buf) 137 | call s:CoffeeRunResetVars() 138 | endfunction 139 | 140 | " Compile the lines between startline and endline and put the result into buf. 141 | function! s:CoffeeCompileToBuf(buf, startline, endline) 142 | let src = bufnr('%') 143 | let input = join(getline(a:startline, a:endline), "\n") 144 | 145 | " Coffee doesn't like empty input. 146 | if !len(input) 147 | " Function should still return within output buffer. 148 | call s:SwitchWindow(a:buf) 149 | return 150 | endif 151 | 152 | " Pipe lines into coffee. 153 | let output = system(g:coffee_compiler . 154 | \ ' -scb' . 155 | \ ' ' . b:coffee_litcoffee . 156 | \ ' 2>&1', input) 157 | 158 | " Paste output into output buffer. 159 | call s:ScratchBufUpdate(a:buf, output) 160 | 161 | " Highlight as JavaScript if there were no compile errors. 162 | if v:shell_error 163 | call s:ParseCoffeeError(output, src, a:startline) 164 | setlocal filetype= 165 | else 166 | " Clear the quickfix list. 167 | call setqflist([], 'r') 168 | setlocal filetype=javascript 169 | endif 170 | endfunction 171 | 172 | " Peek at compiled CoffeeScript in a scratch buffer. We handle ranges like this 173 | " to prevent the cursor from being moved (and its position saved) before the 174 | " function is called. 175 | function! s:CoffeeCompile(startline, endline, args) 176 | if a:args =~ '\' 177 | echoerr 'CoffeeCompile watch is deprecated! Please use CoffeeWatch instead' 178 | sleep 5 179 | call s:CoffeeWatch(a:args) 180 | return 181 | endif 182 | 183 | " Switch to the source buffer if not already in it. 184 | silent! call s:SwitchWindow(b:coffee_src_buf) 185 | 186 | " Bail if not in source buffer. 187 | if !exists('b:coffee_compile_buf') 188 | return 189 | endif 190 | 191 | " Build the output buffer if it doesn't exist. 192 | if bufwinnr(b:coffee_compile_buf) == -1 193 | let src = bufnr('%') 194 | 195 | let vert = exists('g:coffee_compile_vert') || a:args =~ '\' 196 | let size = str2nr(matchstr(a:args, '\<\d\+\>')) 197 | 198 | " Build the output buffer and save the source bufnr. 199 | let buf = s:ScratchBufBuild(src, vert, size) 200 | let b:coffee_src_buf = src 201 | 202 | " Set the buffer name. 203 | exec 'silent! file [CoffeeCompile ' . src . ']' 204 | 205 | " Clean up the source buffer when the output buffer is closed. 206 | autocmd BufWipeout call s:CoffeeCompileClose() 207 | " Save the cursor when leaving the output buffer. 208 | autocmd BufLeave let b:coffee_compile_pos = getpos('.') 209 | 210 | " Run user-defined commands on new buffer. 211 | silent doautocmd CoffeeBufNew User CoffeeCompile 212 | 213 | " Switch back to the source buffer and save the output bufnr. This also 214 | " triggers BufLeave above. 215 | call s:SwitchWindow(src) 216 | let b:coffee_compile_buf = buf 217 | endif 218 | 219 | " Fill the scratch buffer. 220 | call s:CoffeeCompileToBuf(b:coffee_compile_buf, a:startline, a:endline) 221 | " Reset cursor to previous position. 222 | call setpos('.', b:coffee_compile_pos) 223 | 224 | " Run any user-defined commands on the scratch buffer. 225 | silent doautocmd CoffeeBufUpdate User CoffeeCompile 226 | endfunction 227 | 228 | " Update the scratch buffer and switch back to the source buffer. 229 | function! s:CoffeeWatchUpdate() 230 | call s:CoffeeCompileToBuf(b:coffee_watch_buf, 1, '$') 231 | call setpos('.', b:coffee_watch_pos) 232 | silent doautocmd CoffeeBufUpdate User CoffeeWatch 233 | call s:SwitchWindow(b:coffee_src_buf) 234 | endfunction 235 | 236 | " Continually compile a source buffer. 237 | function! s:CoffeeWatch(args) 238 | silent! call s:SwitchWindow(b:coffee_src_buf) 239 | 240 | if !exists('b:coffee_watch_buf') 241 | return 242 | endif 243 | 244 | if bufwinnr(b:coffee_watch_buf) == -1 245 | let src = bufnr('%') 246 | 247 | let vert = exists('g:coffee_watch_vert') || a:args =~ '\' 248 | let size = str2nr(matchstr(a:args, '\<\d\+\>')) 249 | 250 | let buf = s:ScratchBufBuild(src, vert, size) 251 | let b:coffee_src_buf = src 252 | 253 | exec 'silent! file [CoffeeWatch ' . src . ']' 254 | 255 | autocmd BufWipeout call s:CoffeeWatchClose() 256 | autocmd BufLeave let b:coffee_watch_pos = getpos('.') 257 | 258 | silent doautocmd CoffeeBufNew User CoffeeWatch 259 | 260 | call s:SwitchWindow(src) 261 | let b:coffee_watch_buf = buf 262 | endif 263 | 264 | " Make sure only one watch autocmd is defined on this buffer. 265 | silent! autocmd! CoffeeAuWatch * 266 | 267 | augroup CoffeeAuWatch 268 | autocmd InsertLeave call s:CoffeeWatchUpdate() 269 | autocmd BufWritePost call s:CoffeeWatchUpdate() 270 | augroup END 271 | 272 | call s:CoffeeWatchUpdate() 273 | endfunction 274 | 275 | " Run a snippet of CoffeeScript between startline and endline. 276 | function! s:CoffeeRun(startline, endline, args) 277 | silent! call s:SwitchWindow(b:coffee_src_buf) 278 | 279 | if !exists('b:coffee_run_buf') 280 | return 281 | endif 282 | 283 | if bufwinnr(b:coffee_run_buf) == -1 284 | let src = bufnr('%') 285 | 286 | let buf = s:ScratchBufBuild(src, exists('g:coffee_run_vert'), 0) 287 | let b:coffee_src_buf = src 288 | 289 | exec 'silent! file [CoffeeRun ' . src . ']' 290 | 291 | autocmd BufWipeout call s:CoffeeRunClose() 292 | autocmd BufLeave let b:coffee_run_pos = getpos('.') 293 | 294 | silent doautocmd CoffeeBufNew User CoffeeRun 295 | 296 | call s:SwitchWindow(src) 297 | let b:coffee_run_buf = buf 298 | endif 299 | 300 | if a:startline == 1 && a:endline == line('$') 301 | let output = system(g:coffee_compiler . 302 | \ ' ' . b:coffee_litcoffee . 303 | \ ' ' . fnameescape(expand('%')) . 304 | \ ' ' . a:args) 305 | else 306 | let input = join(getline(a:startline, a:endline), "\n") 307 | 308 | if !len(input) 309 | return 310 | endif 311 | 312 | let output = system(g:coffee_compiler . 313 | \ ' -s' . 314 | \ ' ' . b:coffee_litcoffee . 315 | \ ' ' . a:args, input) 316 | endif 317 | 318 | call s:ScratchBufUpdate(b:coffee_run_buf, output) 319 | call setpos('.', b:coffee_run_pos) 320 | 321 | silent doautocmd CoffeeBufUpdate User CoffeeRun 322 | endfunction 323 | 324 | " Run coffeelint on a file, and add any errors between startline and endline 325 | " to the quickfix list. 326 | function! s:CoffeeLint(startline, endline, bang, args) 327 | let input = join(getline(a:startline, a:endline), "\n") 328 | 329 | if !len(input) 330 | return 331 | endif 332 | 333 | let output = system(g:coffee_linter . 334 | \ ' -s --reporter csv' . 335 | \ ' ' . b:coffee_litcoffee . 336 | \ ' ' . g:coffee_lint_options . 337 | \ ' ' . a:args . 338 | \ ' 2>&1', input) 339 | 340 | " Convert output into an array and strip off the csv header. 341 | let lines = split(output, "\n")[1:] 342 | let buf = bufnr('%') 343 | let qflist = [] 344 | 345 | for line in lines 346 | let match = matchlist(line, '^stdin,\(\d\+\),\d*,\(error\|warn\),\(.\+\)$') 347 | 348 | " Ignore unmatched lines. 349 | if !len(match) 350 | continue 351 | endif 352 | 353 | " The 'type' will result in either 'E' or 'W'. 354 | call add(qflist, {'bufnr': buf, 'lnum': a:startline + str2nr(match[1]) - 1, 355 | \ 'type': toupper(match[2][0]), 'text': match[3]}) 356 | endfor 357 | 358 | " Replace the quicklist with our items. 359 | call setqflist(qflist, 'r') 360 | 361 | " If not given a bang, jump to first error. 362 | if !len(a:bang) 363 | silent! cc 1 364 | endif 365 | endfunction 366 | 367 | " Complete arguments for Coffee* commands. 368 | function! s:CoffeeComplete(cmd, cmdline, cursor) 369 | let args = ['vertical'] 370 | 371 | " If no partial command, return all possibilities. 372 | if !len(a:cmd) 373 | return args 374 | endif 375 | 376 | let pat = '^' . a:cmd 377 | 378 | for arg in args 379 | if arg =~ pat 380 | return [arg] 381 | endif 382 | endfor 383 | endfunction 384 | 385 | " Set initial state variables if they don't exist 386 | if !exists('b:coffee_compile_buf') 387 | call s:CoffeeCompileResetVars() 388 | endif 389 | 390 | if !exists('b:coffee_watch_buf') 391 | call s:CoffeeWatchResetVars() 392 | endif 393 | 394 | if !exists('b:coffee_run_buf') 395 | call s:CoffeeRunResetVars() 396 | endif 397 | 398 | command! -buffer -range=% -bar -nargs=* -complete=customlist,s:CoffeeComplete 399 | \ CoffeeCompile call s:CoffeeCompile(, , ) 400 | command! -buffer -bar -nargs=* -complete=customlist,s:CoffeeComplete 401 | \ CoffeeWatch call s:CoffeeWatch() 402 | command! -buffer -range=% -bar -nargs=* CoffeeRun 403 | \ call s:CoffeeRun(, , ) 404 | command! -buffer -range=% -bang -bar -nargs=* CoffeeLint 405 | \ call s:CoffeeLint(, , , ) 406 | --------------------------------------------------------------------------------