diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 38881ccc..00000000 --- a/.gitmodules +++ /dev/null @@ -1,6 +0,0 @@ -[submodule "sources_non_forked/vim-gitgutter"] - path = sources_non_forked/vim-gitgutter - url = git://github.com/airblade/vim-gitgutter.git -[submodule "sources_non_forked/gruvbox"] - path = sources_non_forked/gruvbox - url = git@github.com:morhetz/gruvbox.git diff --git a/README.md b/README.md index afd30e18..ff9a8ee7 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ I recommend reading the docs of these plugins to understand them better. Each of * [bufexplorer.zip](https://github.com/vim-scripts/bufexplorer.zip): Buffer Explorer / Browser. This plugin can be opened with `` * [NERD Tree](https://github.com/scrooloose/nerdtree): A tree explorer plugin for vim * [ack.vim](https://github.com/mileszs/ack.vim): Vim plugin for the Perl module / CLI script 'ack' +* [ag.vim](https://github.com/rking/ag.vim): A much faster Ack * [ctrlp.vim](https://github.com/kien/ctrlp.vim): Fuzzy file, buffer, mru and tag finder. In my config it's mapped to ``, because `` is used by YankRing * [mru.vim](https://github.com/vim-scripts/mru.vim): Plugin to manage Most Recently Used (MRU) files. Includes my own fork which adds syntax highlighting to MRU. This plugin can be opened with `` * [open_file_under_cursor.vim](https://github.com/amix/open_file_under_cursor.vim): Open file under cursor when pressing `gf` diff --git a/sources_non_forked/ack.vim/README.md b/sources_non_forked/ack.vim/README.md index 59f00f1d..c2e87067 100644 --- a/sources_non_forked/ack.vim/README.md +++ b/sources_non_forked/ack.vim/README.md @@ -4,7 +4,7 @@ Run your favorite search tool from Vim, with an enhanced results list. This plugin was designed as a Vim frontend for the Perl module [App::Ack]. Ack can be used as a replacement for 99% of the uses of _grep_. The plugin allows -you to run ack from vim, and shows the results in a split window. +you to run ack from Vim, and shows the results in a split window. But here's a little secret for the Vim-seasoned: it's just a light wrapper for Vim's [grepprg] and the [quickfix] window for match results. This makes it easy @@ -28,13 +28,21 @@ It is recommended to use one of the popular plugin managers for Vim. There are many and you probably already have a preferred one, but a few examples for your copy-and-paste convenience: +#### Pathogen + + $ git clone https://github.com/mileszs/ack.vim.git ~/.vim/bundle/ack.vim + #### Vundle - Plugin 'mileszs/ack.vim' +```vim +Plugin 'mileszs/ack.vim' +``` #### NeoBundle - NeoBundle 'mileszs/ack.vim' +```vim +NeoBundle 'mileszs/ack.vim' +``` #### Manual (not recommended) @@ -127,6 +135,7 @@ Please see [the Github releases page][releases]. * Fix the quick help overlay clobbering the list mappings * Fix `:AckFile` when using Dispatch * Restore original `'makeprg'` and `'errorformat'` when using Dispatch +* Arrow keys also work for auto-preview (#158) * Internal refactoring and clean-up ## Credits diff --git a/sources_non_forked/ack.vim/autoload/ack.vim b/sources_non_forked/ack.vim/autoload/ack.vim index fd6e54ca..12237e4e 100644 --- a/sources_non_forked/ack.vim/autoload/ack.vim +++ b/sources_non_forked/ack.vim/autoload/ack.vim @@ -27,11 +27,7 @@ function! ack#Ack(cmd, args) "{{{ endif " If no pattern is provided, search for the word under the cursor - if empty(a:args) - let l:grepargs = expand("") - else - let l:grepargs = a:args . join(a:000, ' ') - end + let l:grepargs = empty(a:args) ? expand("") : a:args . join(a:000, ' ') " NOTE: we escape special chars, but not everything using shellescape to " allow for passing arguments etc @@ -118,6 +114,8 @@ function! s:ApplyMappings() "{{{ if exists("g:ackpreview") " if auto preview in on, remap j and k keys nnoremap j j nnoremap k k + nmap j + nmap k endif endfunction "}}} @@ -157,17 +155,11 @@ function! s:QuickHelp() "{{{ execute 'edit' globpath(&rtp, 'doc/ack_quick_help.txt') silent normal gg - setlocal buftype=nofile - setlocal bufhidden=hide - setlocal noswapfile - setlocal nobuflisted - setlocal nomodifiable + setlocal buftype=nofile bufhidden=hide nobuflisted + setlocal nomodifiable noswapfile setlocal filetype=help - setlocal nonumber - setlocal norelativenumber - setlocal nowrap - setlocal foldlevel=20 - setlocal foldmethod=diff + setlocal nonumber norelativenumber nowrap + setlocal foldmethod=diff foldlevel=20 nnoremap ? :q!:call ack#ShowResults() endfunction "}}} diff --git a/sources_non_forked/ack.vim/doc/ack.txt b/sources_non_forked/ack.vim/doc/ack.txt index 71d74548..bdef3227 100644 --- a/sources_non_forked/ack.vim/doc/ack.txt +++ b/sources_non_forked/ack.vim/doc/ack.txt @@ -84,18 +84,23 @@ g:ackprg Default for ubuntu: "ack-grep" Default for other systems: "ack" -Use this option to specify the ack command and its options +Use this option to specify the search command and its default arguments. Example: > - let g:ackprg = "other-bin-ack" + let g:ackprg = "ag --vimgrep" < *g:ack_default_options* g:ack_default_options Default: " -s -H --nocolor --nogroup --column" -Use this option to specify the options used by ack +Use this option to specify the default arguments given to `ack`. This is only +used if |g:ackprg| has not been customized from the default--if you are using +a custom search program instead of Ack, set your preferred options in +|g:ackprg|. + +NOTE: This option may be deprecated in the future. ~ Example: > diff --git a/sources_non_forked/ack.vim/plugin/ack.vim b/sources_non_forked/ack.vim/plugin/ack.vim index 2cc48036..da3ea9ab 100644 --- a/sources_non_forked/ack.vim/plugin/ack.vim +++ b/sources_non_forked/ack.vim/plugin/ack.vim @@ -71,8 +71,8 @@ command! -bang -nargs=* -complete=file LAckAdd call ack#Ack('lgrepadd -g', ) command! -bang -nargs=* -complete=help AckHelp call ack#AckHelp('grep', ) command! -bang -nargs=* -complete=help LAckHelp call ack#AckHelp('lgrep', ) -command! -bang -nargs=* -complete=help AckWindow call ack#AckWindow('grep', ) -command! -bang -nargs=* -complete=help LAckWindow call ack#AckWindow('lgrep', ) +command! -bang -nargs=* AckWindow call ack#AckWindow('grep', ) +command! -bang -nargs=* LAckWindow call ack#AckWindow('lgrep', ) let g:loaded_ack = 1 diff --git a/sources_non_forked/ag.vim/.gitignore b/sources_non_forked/ag.vim/.gitignore new file mode 100644 index 00000000..e350eccf --- /dev/null +++ b/sources_non_forked/ag.vim/.gitignore @@ -0,0 +1,2 @@ +tags +ag-vim.tgz diff --git a/sources_non_forked/ag.vim/README.md b/sources_non_forked/ag.vim/README.md new file mode 100644 index 00000000..c0e92cbe --- /dev/null +++ b/sources_non_forked/ag.vim/README.md @@ -0,0 +1,76 @@ +# ag.vim # + +This plugin is a front for ag, A.K.A. +[the_silver_searcher](https://github.com/ggreer/the_silver_searcher). Ag can +be used as a replacement for 153% of the uses of `ack`. This plugin will allow +you to run ag from vim, and shows the results in a split window. + +## Installation ## + +See [the_silver_searcher's README](https://github.com/ggreer/the_silver_searcher#installing) for its installation instructions (if you haven't installed it already). + +You have to first install [ag](https://github.com/ggreer/the_silver_searcher), itself. On Mac+Homebrew, Gentoo Linux, several others, there's package named `the_silver_searcher`, but if your OS/distro don't have one, the GitHub repo installs fine: + +Vim has various ways of installing plugins, the standard way is in [the documentation](http://vimdoc.sourceforge.net/htmldoc/usr_05.html#plugin), but most people use a plugin to manage their plugins. If you don't already have a preferred plugin manager plugin, why not try one of the following? +- [vim-plug](https://github.com/junegunn/vim-plug#readme) +- [vim-pathogen](https://github.com/tpope/vim-pathogen#readme) +- [Vundle.vim](https://github.com/gmarik/Vundle.vim#readme) +- Or, if you don't use any sort of Vim plugin management: + + ```sh + cd ~/.vim/bundle && git clone https://github.com/rking/ag.vim ag && echo "set runtimepath^=~/.vim/bundle/ag" >> ~/.vimrc + ``` + + Then open vim and rum `:helptags ~/.vim/bundle/ag/doc`. + +### Configuration ### + +You can specify a custom ag name and path in your .vimrc like so: + + let g:agprg=" --vimgrep" + +You can configure ag.vim to always start searching from your project root +instead of the cwd + + let g:ag_working_path_mode="r" + +## Usage ## + + :Ag [options] {pattern} [{directory}] + +Search recursively in {directory} (which defaults to the current directory) for the {pattern}. + +Files containing the search term will be listed in the split window, along with +the line number of the occurrence, once for each occurrence. [Enter] on a line +in this window will open the file, and place the cursor on the matching line. + +Just like where you use :grep, :grepadd, :lgrep, and :lgrepadd, you can use `:Ag`, `:AgAdd`, `:LAg`, and `:LAgAdd` respectively. (See `doc/ag.txt`, or install and `:h Ag` for more information.) + +### Gotchas ### + +Some characters have special meaning, and need to be escaped your search pattern. For instance, '#'. You have to escape it like this `:Ag '\\\#define foo'` to search for `#define foo`. (From [blueyed in issue #5](https://github.com/mileszs/ack.vim/issues/5).) + +Sometimes `git grep` is even faster, though in my experience it's not noticeably so. + +### Keyboard Shortcuts ### + +In the quickfix window, you can use: + + e to open file and close the quickfix window + o to open (same as enter) + go to preview file (open but maintain focus on ag.vim results) + t to open in new tab + T to open in new tab silently + h to open in horizontal split + H to open in horizontal split silently + v to open in vertical split + gv to open in vertical split silently + q to close the quickfix window + +### Acknowledgements ### + +This Vim plugin is derived (and by derived, I mean copied, almost entirely) +from [milesz's ack.vim](https://github.com/mileszs/ack.vim), which I also +recommend installing since you might be in a situation where you have ack but +not ag, and don't want to stop to install ag. Also, ack supports `--type`, and +a few other features. diff --git a/sources_non_forked/ag.vim/Rakefile b/sources_non_forked/ag.vim/Rakefile new file mode 100644 index 00000000..e6bb6da7 --- /dev/null +++ b/sources_non_forked/ag.vim/Rakefile @@ -0,0 +1,3 @@ +task :tgz do + sh 'cd ..; tar czvf ag/ag-vim.tgz ag/{plugin,autoload,doc}' +end diff --git a/sources_non_forked/ag.vim/autoload/ag.vim b/sources_non_forked/ag.vim/autoload/ag.vim new file mode 100644 index 00000000..6703396b --- /dev/null +++ b/sources_non_forked/ag.vim/autoload/ag.vim @@ -0,0 +1,216 @@ +" NOTE: You must, of course, install ag / the_silver_searcher + +" FIXME: Delete deprecated options below on or after 15-7 (6 months from when they were changed) {{{ + +if exists("g:agprg") + let g:ag_prg = g:agprg +endif + +if exists("g:aghighlight") + let g:ag_highlight = g:aghighlight +endif + +if exists("g:agformat") + let g:ag_format = g:agformat +endif + +" }}} FIXME: Delete the deprecated options above on or after 15-7 (6 months from when they were changed) + +" Location of the ag utility +if !exists("g:ag_prg") + " --vimgrep (consistent output we can parse) is available from version 0.25.0+ + if split(system("ag --version"), "[ \n\r\t]")[2] =~ '\d\+.\(\(2[5-9]\)\|\([3-9][0-9]\)\)\(.\d\+\)\?' + let g:ag_prg="ag --vimgrep" + else + " --noheading seems odd here, but see https://github.com/ggreer/the_silver_searcher/issues/361 + let g:ag_prg="ag --column --nogroup --noheading" + endif +endif + +if !exists("g:ag_apply_qmappings") + let g:ag_apply_qmappings=1 +endif + +if !exists("g:ag_apply_lmappings") + let g:ag_apply_lmappings=1 +endif + +if !exists("g:ag_qhandler") + let g:ag_qhandler="botright copen" +endif + +if !exists("g:ag_lhandler") + let g:ag_lhandler="botright lopen" +endif + +if !exists("g:ag_mapping_message") + let g:ag_mapping_message=1 +endif + +if !exists("g:ag_working_path_mode") + let g:ag_working_path_mode = 'c' +endif + +function! ag#AgBuffer(cmd, args) + let l:bufs = filter(range(1, bufnr('$')), 'buflisted(v:val)') + let l:files = [] + for buf in l:bufs + let l:file = fnamemodify(bufname(buf), ':p') + if !isdirectory(l:file) + call add(l:files, l:file) + endif + endfor + call ag#Ag(a:cmd, a:args . ' ' . join(l:files, ' ')) +endfunction + +function! ag#Ag(cmd, args) + let l:ag_executable = get(split(g:ag_prg, " "), 0) + + " Ensure that `ag` is installed + if !executable(l:ag_executable) + echoe "Ag command '" . l:ag_executable . "' was not found. Is the silver searcher installed and on your $PATH?" + return + endif + + " If no pattern is provided, search for the word under the cursor + if empty(a:args) + let l:grepargs = expand("") + else + let l:grepargs = a:args . join(a:000, ' ') + end + + " Format, used to manage column jump + if a:cmd =~# '-g$' + let s:ag_format_backup=g:ag_format + let g:ag_format="%f" + elseif exists("s:ag_format_backup") + let g:ag_format=s:ag_format_backup + elseif !exists("g:ag_format") + let g:ag_format="%f:%l:%c:%m" + endif + + let l:grepprg_bak=&grepprg + let l:grepformat_bak=&grepformat + let l:t_ti_bak=&t_ti + let l:t_te_bak=&t_te + try + let &grepprg=g:ag_prg + let &grepformat=g:ag_format + set t_ti= + set t_te= + if g:ag_working_path_mode ==? 'r' " Try to find the projectroot for current buffer + let l:cwd_back = getcwd() + let l:cwd = s:guessProjectRoot() + try + exe "lcd ".l:cwd + catch + echom 'Failed to change directory to:'.l:cwd + finally + silent! execute a:cmd . " " . escape(l:grepargs, '|') + exe "lcd ".l:cwd_back + endtry + else " Someone chose an undefined value or 'c' so we revert to the default + silent! execute a:cmd . " " . escape(l:grepargs, '|') + endif + finally + let &grepprg=l:grepprg_bak + let &grepformat=l:grepformat_bak + let &t_ti=l:t_ti_bak + let &t_te=l:t_te_bak + endtry + + if a:cmd =~# '^l' + let l:match_count = len(getloclist(winnr())) + else + let l:match_count = len(getqflist()) + endif + + if a:cmd =~# '^l' && l:match_count + exe g:ag_lhandler + let l:apply_mappings = g:ag_apply_lmappings + let l:matches_window_prefix = 'l' " we're using the location list + elseif l:match_count + exe g:ag_qhandler + let l:apply_mappings = g:ag_apply_qmappings + let l:matches_window_prefix = 'c' " we're using the quickfix window + endif + + " If highlighting is on, highlight the search keyword. + if exists('g:ag_highlight') + let @/ = matchstr(a:args, "\\v(-)\@", 'n') + end + + redraw! + + if l:match_count + if l:apply_mappings + nnoremap h K + nnoremap H Kb + nnoremap o + nnoremap t T + nnoremap T TgT + nnoremap v HbJt + + exe 'nnoremap e :' . l:matches_window_prefix .'close' + exe 'nnoremap go :' . l:matches_window_prefix . 'open' + exe 'nnoremap q :' . l:matches_window_prefix . 'close' + + exe 'nnoremap gv :let b:height=winheight(0)H:' . l:matches_window_prefix . 'openJ:exe printf(":normal %d\c-w>_", b:height)' + " Interpretation: + " :let b:height=winheight(0) Get the height of the quickfix/location list window + " Open the current item in a new split + " H Slam the newly opened window against the left edge + " :copen -or- :lopen Open either the quickfix window or the location list (whichever we were using) + " J Slam the quickfix/location list window against the bottom edge + " :exe printf(":normal %d\c-w>_", b:height) Restore the quickfix/location list window's height from before we opened the match + + if g:ag_mapping_message && l:apply_mappings + echom "ag.vim keys: q=quit /e/t/h/v=enter/edit/tab/split/vsplit go/T/H/gv=preview versions of same" + endif + endif + else + echom 'No matches for "'.a:args.'"' + endif +endfunction + +function! ag#AgFromSearch(cmd, args) + let search = getreg('/') + " translate vim regular expression to perl regular expression. + let search = substitute(search,'\(\\<\|\\>\)','\\b','g') + call ag#Ag(a:cmd, '"' . search .'" '. a:args) +endfunction + +function! ag#GetDocLocations() + let dp = '' + for p in split(&runtimepath,',') + let p = p.'doc/' + if isdirectory(p) + let dp = p.'*.txt '.dp + endif + endfor + return dp +endfunction + +function! ag#AgHelp(cmd,args) + let args = a:args.' '.ag#GetDocLocations() + call ag#Ag(a:cmd,args) +endfunction + +function! s:guessProjectRoot() + let l:splitsearchdir = split(getcwd(), "/") + + while len(l:splitsearchdir) > 2 + let l:searchdir = '/'.join(l:splitsearchdir, '/').'/' + for l:marker in ['.rootdir', '.git', '.hg', '.svn', 'bzr', '_darcs', 'build.xml'] + " found it! Return the dir + if filereadable(l:searchdir.l:marker) || isdirectory(l:searchdir.l:marker) + return l:searchdir + endif + endfor + let l:splitsearchdir = l:splitsearchdir[0:-2] " Splice the list to get rid of the tail directory + endwhile + + " Nothing found, fallback to current working dir + return getcwd() +endfunction diff --git a/sources_non_forked/ag.vim/doc/ag.txt b/sources_non_forked/ag.vim/doc/ag.txt new file mode 100644 index 00000000..e702c291 --- /dev/null +++ b/sources_non_forked/ag.vim/doc/ag.txt @@ -0,0 +1,174 @@ +*ag.txt* Plugin that integrates ag with Vim + +============================================================================== +INTRODUCTION *ag* + +This plugin is a front for the_silver_searcher: ag. Ag can be used as a +replacement for ack. This plugin will allow you to run ag from vim, and shows +the results in a split window. + +:Ag[!] [options] {pattern} [{directory}] *:Ag* + + Search recursively in {directory} (which defaults to the current + directory) for the {pattern}. Behaves just like the |:grep| command, but + will open the |Quickfix| window for you. If [!] is not given the first + error is jumped to. + +:AgBuffer[!] [options] {pattern} *:AgBuffer* + + Search for {pattern} in all open buffers. Behaves just like the |:grep| + command, but will open the |Quickfix| window for you. If [!] is not given + the first error is jumped to. + + Note: this will not find changes in modified buffers, since ag can only + find what is on disk! You can save buffers automatically when searching + with the 'autowrite' option. A buffer will be ignored if it is a directory + (an explorer, like netrw). + +:AgAdd [options] {pattern} [{directory}] *:AgAdd* + + Just like |:Ag|, but instead of making a new list, the matches are + appended to the current |quickfix| list. + +:AgFromSearch [{directory}] *:AgFromSearch* + + Just like |:Ag| but the pattern is from previous search. + +:LAg [options] {pattern} [{directory}] *:LAg* + + Just like |:Ag| but instead of the |quickfix| list, matches are placed in + the current |location-list|. + +:LAgBuffer [options] {pattern} *:LAgBuffer* + + Just like |:AgBuffer| but instead of the |quickfix| list, matches are + placed in the current |location-list|. + +:LAgAdd [options] {pattern} [{directory}] *:LAgAdd* + + Just like |:AgAdd| but instead of the |quickfix| list, matches are added + to the current |location-list| + +:AgFile [options] {pattern} [{directory}] *:AgFile* + + Search recursively in {directory} (which defaults to the current + directory) for filenames matching the {pattern}. Behaves just like the + |:grep| command, but will open the |Quickfix| window for you. + +:AgHelp[!] [options] {pattern} *:AgHelp* + + Search vim documentation files for the {pattern}. Behaves just like the + |:Ag| command, but searches only vim documentation .txt files + +:LAgHelp [options] {pattern} *:LAgHelp* + + Just like |:AgHelp| but instead of the |quickfix| list, matches are placed + in the current |location-list|. + +Files containing the search term will be listed in the split window, along +with the line number of the occurrence, once for each occurrence. on a +line in this window will open the file, and place the cursor on the matching +line. + +See http://geoff.greer.fm/2011/12/27/the-silver-searcher-better-than-ack/ for +more information. + +============================================================================== +OPTIONS *ag-options* + + *g:ag_prg* +The location of the Ag program, and any options you want passed to it before +searching. Default: "ag --vimgrep" (for parsable output). Example: > + let g:ag_prg="ag --vimgrep --smart-case" +< +Note: the `--vimgrep` option was added in Ag 0.25.0. If ag.vim detects that +you're using a lower version, the following default will be used instead: > + let g:ag_prg="ag --column --nogroup --noheading" +< +This works around inconsistent behaviors in earlier Ag versions, but it is +recommended that you upgrade if possible for a better experience. `--vimgrep` +supports multiple matches on the same line of text, for example. + +For background, see: https://github.com/rking/ag.vim/pull/88 + + *g:ag_working_path_mode* +A mapping that describes where ag will be run. Default is the current working +directory. Specifying 'r' as the argument will tell it to run from the project +rootdirectory. For now any other mapping will result to the default. +Example: + let g:ag_working_path_mode='r' + + *g:ag_highlight* +If 1, highlight the search terms after searching. Default: 0. Example: > + let g:ag_highlight=1 +< + + *g:ag_format* +Format to recognize the matches. See 'errorformat' for more info. Default: +"%f" when searching for files, "%f:%l:%c:%m" if not otherwise set. For +example, if your `g:ag_prg` is set to just "ag" (no column numbers in the +output, so when you jump to a match your cursor will be on the start of the +line): > + let g:ag_format="%f:%l:%m" +< + + *g:ag_apply_lmappings* +Whether or not to add custom mappings to location list windows opened by this +plugin. Only applies if you're using the location list. Default 1. Example: > + let g:ag_apply_lmappings=0 +< + + *g:ag_apply_qmappings* +Whether or not to add custom mappings to quickfix windows opened by this +plugin. Only applies if you're using the error list. Default 1. Example: > + let g:ag_apply_qmappings=0 +< + + *g:ag_lhandler* +A custom command used to open the location list after it's populated. +Default: "botright lopen". You might want to set this to change where the +location list is opened, or what size it is. Example: > + let g:ag_lhandler="topleft lopen" +< + + *g:ag_qhandler* +A custom command used to open the error list after it's populated. Default: +"botright copen". You might want to set this to change where the quickfix +window is opened, or what size it is. Example: > + let g:ag_qhandler="copen 20" +< + + *g:ag_mapping_message* +Whether or not to show the message explaining the extra mappings that are +added to the results list this plugin populates. This message is not shown if +the mappings are not applied (see |g:ag_apply_qmappings| and +|g:ag_apply_lmappings| for more info. Default 1. Example: > + let g:ag_mapping_message=0 +< + +============================================================================== +MAPPINGS *ag-mappings* + +The following keyboard shortcuts are available in the quickfix window: + +e open file and close the quickfix window. + +o open file (same as enter). + +go preview file (open but maintain focus on ag.vim results). + +t open in a new tab. + +T open in new tab silently. + +h open in horizontal split. + +H open in horizontal split silently. + +v open in vertical split. + +gv open in vertical split silently. + +q close the quickfix window. + + vim:tw=78:fo=tcq2:ft=help:norl: diff --git a/sources_non_forked/ag.vim/plugin/ag.vim b/sources_non_forked/ag.vim/plugin/ag.vim new file mode 100644 index 00000000..053f213c --- /dev/null +++ b/sources_non_forked/ag.vim/plugin/ag.vim @@ -0,0 +1,11 @@ +" NOTE: You must, of course, install ag / the_silver_searcher +command! -bang -nargs=* -complete=file Ag call ag#Ag('grep',) +command! -bang -nargs=* -complete=file AgBuffer call ag#AgBuffer('grep',) +command! -bang -nargs=* -complete=file AgAdd call ag#Ag('grepadd', ) +command! -bang -nargs=* -complete=file AgFromSearch call ag#AgFromSearch('grep', ) +command! -bang -nargs=* -complete=file LAg call ag#Ag('lgrep', ) +command! -bang -nargs=* -complete=file LAgBuffer call ag#AgBuffer('lgrep',) +command! -bang -nargs=* -complete=file LAgAdd call ag#Ag('lgrepadd', ) +command! -bang -nargs=* -complete=file AgFile call ag#Ag('grep -g', ) +command! -bang -nargs=* -complete=help AgHelp call ag#AgHelp('grep',) +command! -bang -nargs=* -complete=help LAgHelp call ag#AgHelp('lgrep',) diff --git a/sources_non_forked/goyo.vim/autoload/goyo.vim b/sources_non_forked/goyo.vim/autoload/goyo.vim index b790e893..9d3d1eb5 100644 --- a/sources_non_forked/goyo.vim/autoload/goyo.vim +++ b/sources_non_forked/goyo.vim/autoload/goyo.vim @@ -24,6 +24,10 @@ let s:cpo_save = &cpo set cpo&vim +function! s:const(val, min, max) + return min([max([a:val, a:min]), a:max]) +endfunction + function! s:get_color(group, attr) return synIDattr(synIDtrans(hlID(a:group)), a:attr) endfunction @@ -78,28 +82,27 @@ function! s:setup_pad(bufnr, vert, size, repel) execute winnr('#') . 'wincmd w' endfunction -function! s:hmargin() - let nwidth = max([len(string(line('$'))) + 1, &numberwidth]) - let width = t:goyo_width + (&number ? nwidth : 0) - return (&columns - width) -endfunction - function! s:resize_pads() - let t:goyo_width = max([2, t:goyo_width]) - let t:goyo_margin_top = min([max([2, t:goyo_margin_top]), &lines / 2 - 1]) - let t:goyo_margin_bottom = min([max([2, t:goyo_margin_bottom]), &lines / 2 - 1]) - - let hmargin = s:hmargin() - augroup goyop autocmd! augroup END - call s:setup_pad(t:goyo_pads.t, 0, t:goyo_margin_top - 1, 'j') - call s:setup_pad(t:goyo_pads.b, 0, t:goyo_margin_bottom - 2, 'k') - call s:setup_pad(t:goyo_pads.l, 1, hmargin / 2 - 1, 'l') - call s:setup_pad(t:goyo_pads.r, 1, hmargin / 2 - 1, 'h') - let t:goyo_width = winwidth(0) + let t:goyo_dim.width = s:const(t:goyo_dim.width, 2, &columns) + let t:goyo_dim.height = s:const(t:goyo_dim.height, 2, &lines) + + let vmargin = max([0, (&lines - t:goyo_dim.height) / 2 - 1]) + let yoff = s:const(t:goyo_dim.yoff, - vmargin, vmargin) + let top = vmargin + yoff + let bot = vmargin - yoff - 1 + call s:setup_pad(t:goyo_pads.t, 0, top, 'j') + call s:setup_pad(t:goyo_pads.b, 0, bot, 'k') + + let nwidth = max([len(string(line('$'))) + 1, &numberwidth]) + let width = t:goyo_dim.width + (&number ? nwidth : 0) + let hmargin = max([0, (&columns - width) / 2 - 1]) + let xoff = s:const(t:goyo_dim.xoff, - hmargin, hmargin) + call s:setup_pad(t:goyo_pads.l, 1, hmargin + xoff, 'l') + call s:setup_pad(t:goyo_pads.r, 1, hmargin - xoff, 'h') endfunction function! s:tranquilize() @@ -145,11 +148,11 @@ endfunction function! s:maps_resize() let commands = { - \ '=': ':let [t:goyo_width, t:goyo_margin_top, t:goyo_margin_bottom] = t:goyo_initial_dim call resize_pads()', - \ '>': ':let t:goyo_width = winwidth(0) + 2 * v:count1 call resize_pads()', - \ '<': ':let t:goyo_width = winwidth(0) - 2 * v:count1 call resize_pads()', - \ '+': ':let t:goyo_margin_top -= v:count1 let t:goyo_margin_bottom -= v:count1 call resize_pads()', - \ '-': ':let t:goyo_margin_top += v:count1 let t:goyo_margin_bottom += v:count1 call resize_pads()' + \ '=': ':let t:goyo_dim = parse_arg(t:goyo_dim_expr) call resize_pads()', + \ '>': ':let t:goyo_dim.width = winwidth(0) + 2 * v:count1 call resize_pads()', + \ '<': ':let t:goyo_dim.width = winwidth(0) - 2 * v:count1 call resize_pads()', + \ '+': ':let t:goyo_dim.height += 2 * v:count1 call resize_pads()', + \ '-': ':let t:goyo_dim.height -= 2 * v:count1 call resize_pads()' \ } let mapped = filter(keys(commands), "empty(maparg(\"\\".v:val, 'n'))") for c in mapped @@ -158,7 +161,12 @@ function! s:maps_resize() return mapped endfunction -function! s:goyo_on(width) +function! s:goyo_on(dim) + let dim = s:parse_arg(a:dim) + if empty(dim) + return + endif + let s:orig_tab = tabpagenr() let settings = \ { 'laststatus': &laststatus, @@ -177,10 +185,8 @@ function! s:goyo_on(width) tab split let t:goyo_master = winbufnr(0) - let t:goyo_width = a:width - let t:goyo_margin_top = get(g:, 'goyo_margin_top', 4) - let t:goyo_margin_bottom = get(g:, 'goyo_margin_bottom', 4) - let t:goyo_initial_dim = [t:goyo_width, t:goyo_margin_top, t:goyo_margin_bottom] + let t:goyo_dim = dim + let t:goyo_dim_expr = a:dim let t:goyo_pads = {} let t:goyo_revert = settings let t:goyo_maps = extend(s:maps_nop(), s:maps_resize()) @@ -360,19 +366,60 @@ function! s:goyo_off() silent! doautocmd User GoyoLeave endfunction -function! goyo#execute(bang, ...) - let width = a:0 > 0 ? a:1 : get(g:, 'goyo_width', 80) +function! s:relsz(expr, limit) + if a:expr !~ '%$' + return str2nr(a:expr) + endif + return a:limit * str2nr(a:expr[:-2]) / 100 +endfunction +function! s:parse_arg(arg) + if exists('g:goyo_height') || !exists('g:goyo_margin_top') && !exists('g:goyo_margin_bottom') + let height = s:relsz(get(g:, 'goyo_height', '85%'), &lines) + let yoff = 0 + else + let top = max([0, s:relsz(get(g:, 'goyo_margin_top', 4), &lines)]) + let bot = max([0, s:relsz(get(g:, 'goyo_margin_bottom', 4), &lines)]) + let height = &lines - top - bot + let yoff = top - bot + endif + + let dim = { 'width': s:relsz(get(g:, 'goyo_width', 80), &columns), + \ 'height': height, + \ 'xoff': 0, + \ 'yoff': yoff } + if empty(a:arg) + return dim + endif + let parts = matchlist(a:arg, '^\s*\([0-9]\+%\?\)\?\([+-][0-9]\+%\?\)\?\%(x\([0-9]\+%\?\)\?\([+-][0-9]\+%\?\)\?\)\?\s*$') + if empty(parts) + echohl WarningMsg + echo 'Invalid dimension expression: '.a:arg + echohl None + return {} + endif + if !empty(parts[1]) | let dim.width = s:relsz(parts[1], &columns) | endif + if !empty(parts[2]) | let dim.xoff = s:relsz(parts[2], &columns) | endif + if !empty(parts[3]) | let dim.height = s:relsz(parts[3], &lines) | endif + if !empty(parts[4]) | let dim.yoff = s:relsz(parts[4], &lines) | endif + return dim +endfunction + +function! goyo#execute(bang, dim) if a:bang if exists('#goyo') call s:goyo_off() endif else if exists('#goyo') == 0 - call s:goyo_on(width) - elseif a:0 > 0 - let t:goyo_width = width - call s:resize_pads() + call s:goyo_on(a:dim) + elseif !empty(a:dim) + let dim = s:parse_arg(a:dim) + if !empty(dim) + let t:goyo_dim = dim + let t:goyo_dim_expr = a:dim + call s:resize_pads() + endif else call s:goyo_off() end diff --git a/sources_non_forked/goyo.vim/plugin/goyo.vim b/sources_non_forked/goyo.vim/plugin/goyo.vim index 76e9ad36..af4793a1 100644 --- a/sources_non_forked/goyo.vim/plugin/goyo.vim +++ b/sources_non_forked/goyo.vim/plugin/goyo.vim @@ -21,4 +21,4 @@ " OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION " WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -command! -nargs=? -bar -bang Goyo call goyo#execute(0, ) +command! -nargs=? -bar -bang Goyo call goyo#execute(0, ) diff --git a/sources_non_forked/nerdtree/README.markdown b/sources_non_forked/nerdtree/README.markdown index 4234b54f..0317e624 100644 --- a/sources_non_forked/nerdtree/README.markdown +++ b/sources_non_forked/nerdtree/README.markdown @@ -66,48 +66,42 @@ Then reload vim, run `:Helptags`, and check out `:help NERD_tree.txt`. Faq --- -__Q. Can I have the nerdtree on every tab automatically?__ +> Is there any support for `git` flags? -A. Nope. If this is something you want then chances are you aren't using tabs - and buffers as they were intended to be used. Read this - http://stackoverflow.com/questions/102384/using-vims-tabs-like-buffers +Yes, install [nerdtree-git-plugin](https://github.com/Xuyuanp/nerdtree-git-plugin). - If you are interested in this behaviour then consider [vim-nerdtree-tabs](https://github.com/jistr/vim-nerdtree-tabs) -__Q. How can I open a NERDTree automatically when vim starts up?__ +> Can I have the nerdtree on every tab automatically? -A. Stick this in your vimrc: `autocmd vimenter * NERDTree` +Nope. If this is something you want then chances are you aren't using tabs and +buffers as they were intended to be used. Read this +http://stackoverflow.com/questions/102384/using-vims-tabs-like-buffers -__Q. How can I open a NERDTree automatically when vim starts up if no files were specified?__ +If you are interested in this behaviour then consider [vim-nerdtree-tabs](https://github.com/jistr/vim-nerdtree-tabs) -A. Stick this in your vimrc +> How can I open a NERDTree automatically when vim starts up? + +Stick this in your vimrc: `autocmd vimenter * NERDTree` + +> How can I open a NERDTree automatically when vim starts up if no files were specified? + +Stick this in your vimrc autocmd StdinReadPre * let s:std_in=1 autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif -__Q. How can I map a specific key or shortcut to open NERDTree?__ +> How can I map a specific key or shortcut to open NERDTree? -A. Stick this in your vimrc to open NERDTree with `Ctrl+n` (you can set whatever key you want): +Stick this in your vimrc to open NERDTree with `Ctrl+n` (you can set whatever key you want): -`map :NERDTreeToggle` + map :NERDTreeToggle -__Q. How can I close vim if the only window left open is a NERDTree?__ +> How can I close vim if the only window left open is a NERDTree? -A. Stick this in your vimrc: +Stick this in your vimrc: - `autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif` + autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif +> Can I have different highlighting for different file extensions? -Changelog ---------- - -4.2.0 (2011-12-28) - - * Add NERDTreeDirArrows option to make the UI use pretty arrow chars instead of the old +~| chars to define the tree structure (sickill) - * shift the syntax highlighting out into its own syntax file (gnap) * add some mac specific options to the filesystem menu - for macvim only (andersonfreitas) - * Add NERDTreeMinimalUI option to remove some non functional parts of the nerdtree ui (camthompson) - * tweak the behaviour of :NERDTreeFind - see :help :NERDTreeFind for the new behaviour (benjamingeiger) - * if no name is given to :Bookmark, make it default to the name of the target file/dir (minyoung) - * use 'file' completion when doing copying, create, and move operations (EvanDotPro) - * lots of misc bug fixes (paddyoloughlin, sdewald, camthompson, Vitaly Bogdanov, AndrewRadev, mathias, scottstvnsn, kml, wycats, me RAWR!) - +See here: https://github.com/scrooloose/nerdtree/issues/433#issuecomment-92590696 diff --git a/sources_non_forked/nerdtree/autoload/nerdtree.vim b/sources_non_forked/nerdtree/autoload/nerdtree.vim index 539e7838..37d7d105 100644 --- a/sources_non_forked/nerdtree/autoload/nerdtree.vim +++ b/sources_non_forked/nerdtree/autoload/nerdtree.vim @@ -34,6 +34,17 @@ function! nerdtree#compareNodes(n1, n2) return a:n1.path.compareTo(a:n2.path) endfunction +"FUNCTION: nerdtree#compareNodesBySortKey(n1, n2) {{{2 +function! nerdtree#compareNodesBySortKey(n1, n2) + if a:n1.path.getSortKey() <# a:n2.path.getSortKey() + return -1 + elseif a:n1.path.getSortKey() ># a:n2.path.getSortKey() + return 1 + else + return 0 + endif +endfunction + " FUNCTION: nerdtree#deprecated(func, [msg]) {{{2 " Issue a deprecation warning for a:func. If a second arg is given, use this " as the deprecation message @@ -95,175 +106,9 @@ function! nerdtree#runningWindows() return has("win16") || has("win32") || has("win64") endfunction -"FUNCTION: nerdtree#treeMarkupReg(dir) {{{2 -function! nerdtree#treeMarkupReg() - if g:NERDTreeDirArrows - return '^\([▾▸] \| \+[▾▸] \| \+\)' - endif - - return '^[ `|]*[\-+~]' -endfunction - -"FUNCTION: nerdtree#treeUpDirLine(dir) {{{2 -function! nerdtree#treeUpDirLine() - return '.. (up a dir)' -endfunction - -"FUNCTION: nerdtree#treeWid(dir) {{{2 -function! nerdtree#treeWid() - return 2 -endfunction - " SECTION: View Functions {{{1 "============================================================ -"FUNCTION: nerdtree#closeTree() {{{2 -"Closes the primary NERD tree window for this tab -function! nerdtree#closeTree() - if !nerdtree#isTreeOpen() - throw "NERDTree.NoTreeFoundError: no NERDTree is open" - endif - - if winnr("$") != 1 - if winnr() == nerdtree#getTreeWinNum() - call nerdtree#exec("wincmd p") - let bufnr = bufnr("") - call nerdtree#exec("wincmd p") - else - let bufnr = bufnr("") - endif - - call nerdtree#exec(nerdtree#getTreeWinNum() . " wincmd w") - close - call nerdtree#exec(bufwinnr(bufnr) . " wincmd w") - else - close - endif -endfunction - -"FUNCTION: nerdtree#closeTreeIfOpen() {{{2 -"Closes the NERD tree window if it is open -function! nerdtree#closeTreeIfOpen() - if nerdtree#isTreeOpen() - call nerdtree#closeTree() - endif -endfunction - -"FUNCTION: nerdtree#closeTreeIfQuitOnOpen() {{{2 -"Closes the NERD tree window if the close on open option is set -function! nerdtree#closeTreeIfQuitOnOpen() - if g:NERDTreeQuitOnOpen && nerdtree#isTreeOpen() - call nerdtree#closeTree() - endif -endfunction - -"FUNCTION: nerdtree#dumpHelp {{{2 -"prints out the quick help -function! nerdtree#dumpHelp() - let old_h = @h - if b:treeShowHelp ==# 1 - let @h= "\" NERD tree (" . nerdtree#version() . ") quickhelp~\n" - let @h=@h."\" ============================\n" - let @h=@h."\" File node mappings~\n" - let @h=@h."\" ". (g:NERDTreeMouseMode ==# 3 ? "single" : "double") ."-click,\n" - let @h=@h."\" ,\n" - if b:NERDTreeType ==# "primary" - let @h=@h."\" ". g:NERDTreeMapActivateNode .": open in prev window\n" - else - let @h=@h."\" ". g:NERDTreeMapActivateNode .": open in current window\n" - endif - if b:NERDTreeType ==# "primary" - let @h=@h."\" ". g:NERDTreeMapPreview .": preview\n" - endif - let @h=@h."\" ". g:NERDTreeMapOpenInTab.": open in new tab\n" - let @h=@h."\" ". g:NERDTreeMapOpenInTabSilent .": open in new tab silently\n" - let @h=@h."\" middle-click,\n" - let @h=@h."\" ". g:NERDTreeMapOpenSplit .": open split\n" - let @h=@h."\" ". g:NERDTreeMapPreviewSplit .": preview split\n" - let @h=@h."\" ". g:NERDTreeMapOpenVSplit .": open vsplit\n" - let @h=@h."\" ". g:NERDTreeMapPreviewVSplit .": preview vsplit\n" - - let @h=@h."\"\n\" ----------------------------\n" - let @h=@h."\" Directory node mappings~\n" - let @h=@h."\" ". (g:NERDTreeMouseMode ==# 1 ? "double" : "single") ."-click,\n" - let @h=@h."\" ". g:NERDTreeMapActivateNode .": open & close node\n" - let @h=@h."\" ". g:NERDTreeMapOpenRecursively .": recursively open node\n" - let @h=@h."\" ". g:NERDTreeMapCloseDir .": close parent of node\n" - let @h=@h."\" ". g:NERDTreeMapCloseChildren .": close all child nodes of\n" - let @h=@h."\" current node recursively\n" - let @h=@h."\" middle-click,\n" - let @h=@h."\" ". g:NERDTreeMapOpenExpl.": explore selected dir\n" - - let @h=@h."\"\n\" ----------------------------\n" - let @h=@h."\" Bookmark table mappings~\n" - let @h=@h."\" double-click,\n" - let @h=@h."\" ". g:NERDTreeMapActivateNode .": open bookmark\n" - let @h=@h."\" ". g:NERDTreeMapOpenInTab.": open in new tab\n" - let @h=@h."\" ". g:NERDTreeMapOpenInTabSilent .": open in new tab silently\n" - let @h=@h."\" ". g:NERDTreeMapDeleteBookmark .": delete bookmark\n" - - let @h=@h."\"\n\" ----------------------------\n" - let @h=@h."\" Tree navigation mappings~\n" - let @h=@h."\" ". g:NERDTreeMapJumpRoot .": go to root\n" - let @h=@h."\" ". g:NERDTreeMapJumpParent .": go to parent\n" - let @h=@h."\" ". g:NERDTreeMapJumpFirstChild .": go to first child\n" - let @h=@h."\" ". g:NERDTreeMapJumpLastChild .": go to last child\n" - let @h=@h."\" ". g:NERDTreeMapJumpNextSibling .": go to next sibling\n" - let @h=@h."\" ". g:NERDTreeMapJumpPrevSibling .": go to prev sibling\n" - - let @h=@h."\"\n\" ----------------------------\n" - let @h=@h."\" Filesystem mappings~\n" - let @h=@h."\" ". g:NERDTreeMapChangeRoot .": change tree root to the\n" - let @h=@h."\" selected dir\n" - let @h=@h."\" ". g:NERDTreeMapUpdir .": move tree root up a dir\n" - let @h=@h."\" ". g:NERDTreeMapUpdirKeepOpen .": move tree root up a dir\n" - let @h=@h."\" but leave old root open\n" - let @h=@h."\" ". g:NERDTreeMapRefresh .": refresh cursor dir\n" - let @h=@h."\" ". g:NERDTreeMapRefreshRoot .": refresh current root\n" - let @h=@h."\" ". g:NERDTreeMapMenu .": Show menu\n" - let @h=@h."\" ". g:NERDTreeMapChdir .":change the CWD to the\n" - let @h=@h."\" selected dir\n" - let @h=@h."\" ". g:NERDTreeMapCWD .":change tree root to CWD\n" - - let @h=@h."\"\n\" ----------------------------\n" - let @h=@h."\" Tree filtering mappings~\n" - let @h=@h."\" ". g:NERDTreeMapToggleHidden .": hidden files (" . (b:NERDTreeShowHidden ? "on" : "off") . ")\n" - let @h=@h."\" ". g:NERDTreeMapToggleFilters .": file filters (" . (b:NERDTreeIgnoreEnabled ? "on" : "off") . ")\n" - let @h=@h."\" ". g:NERDTreeMapToggleFiles .": files (" . (b:NERDTreeShowFiles ? "on" : "off") . ")\n" - let @h=@h."\" ". g:NERDTreeMapToggleBookmarks .": bookmarks (" . (b:NERDTreeShowBookmarks ? "on" : "off") . ")\n" - - "add quickhelp entries for each custom key map - let @h=@h."\"\n\" ----------------------------\n" - let @h=@h."\" Custom mappings~\n" - for i in g:NERDTreeKeyMap.All() - if !empty(i.quickhelpText) - let @h=@h."\" ". i.key .": ". i.quickhelpText ."\n" - endif - endfor - - let @h=@h."\"\n\" ----------------------------\n" - let @h=@h."\" Other mappings~\n" - let @h=@h."\" ". g:NERDTreeMapQuit .": Close the NERDTree window\n" - let @h=@h."\" ". g:NERDTreeMapToggleZoom .": Zoom (maximize-minimize)\n" - let @h=@h."\" the NERDTree window\n" - let @h=@h."\" ". g:NERDTreeMapHelp .": toggle help\n" - let @h=@h."\"\n\" ----------------------------\n" - let @h=@h."\" Bookmark commands~\n" - let @h=@h."\" :Bookmark []\n" - let @h=@h."\" :BookmarkToRoot \n" - let @h=@h."\" :RevealBookmark \n" - let @h=@h."\" :OpenBookmark \n" - let @h=@h."\" :ClearBookmarks []\n" - let @h=@h."\" :ClearAllBookmarks\n" - silent! put h - elseif g:NERDTreeMinimalUI == 0 - let @h="\" Press ". g:NERDTreeMapHelp ." for help\n" - silent! put h - endif - - let @h = old_h -endfunction - "FUNCTION: nerdtree#echo {{{2 "A wrapper for :echo. Appends 'NERDTree:' on the front of all messages " @@ -294,114 +139,9 @@ function! nerdtree#echoWarning(msg) echohl normal endfunction -"FUNCTION: nerdtree#getTreeWinNum() {{{2 -"gets the nerd tree window number for this tab -function! nerdtree#getTreeWinNum() - if exists("t:NERDTreeBufName") - return bufwinnr(t:NERDTreeBufName) - else - return -1 - endif -endfunction - -"FUNCTION: nerdtree#isTreeOpen() {{{2 -function! nerdtree#isTreeOpen() - return nerdtree#getTreeWinNum() != -1 -endfunction - -"FUNCTION: nerdtree#putCursorOnBookmarkTable(){{{2 -"Places the cursor at the top of the bookmarks table -function! nerdtree#putCursorOnBookmarkTable() - if !b:NERDTreeShowBookmarks - throw "NERDTree.IllegalOperationError: cant find bookmark table, bookmarks arent active" - endif - - if g:NERDTreeMinimalUI - return cursor(1, 2) - endif - - let rootNodeLine = b:NERDTree.ui.getRootLineNum() - - let line = 1 - while getline(line) !~# '^>-\+Bookmarks-\+$' - let line = line + 1 - if line >= rootNodeLine - throw "NERDTree.BookmarkTableNotFoundError: didnt find the bookmarks table" - endif - endwhile - call cursor(line, 2) -endfunction - -"FUNCTION: nerdtree#putCursorInTreeWin(){{{2 -"Places the cursor in the nerd tree window -function! nerdtree#putCursorInTreeWin() - if !nerdtree#isTreeOpen() - throw "NERDTree.InvalidOperationError: cant put cursor in NERD tree window, no window exists" - endif - - call nerdtree#exec(nerdtree#getTreeWinNum() . "wincmd w") -endfunction - -"FUNCTION: nerdtree#renderBookmarks {{{2 -function! nerdtree#renderBookmarks() - - if g:NERDTreeMinimalUI == 0 - call setline(line(".")+1, ">----------Bookmarks----------") - call cursor(line(".")+1, col(".")) - endif - - for i in g:NERDTreeBookmark.Bookmarks() - call setline(line(".")+1, i.str()) - call cursor(line(".")+1, col(".")) - endfor - - call setline(line(".")+1, '') - call cursor(line(".")+1, col(".")) -endfunction - "FUNCTION: nerdtree#renderView {{{2 function! nerdtree#renderView() call b:NERDTree.render() endfunction -" -"FUNCTION: nerdtree#stripMarkupFromLine(line, removeLeadingSpaces){{{2 -"returns the given line with all the tree parts stripped off -" -"Args: -"line: the subject line -"removeLeadingSpaces: 1 if leading spaces are to be removed (leading spaces = -"any spaces before the actual text of the node) -function! nerdtree#stripMarkupFromLine(line, removeLeadingSpaces) - let line = a:line - "remove the tree parts and the leading space - let line = substitute (line, nerdtree#treeMarkupReg(),"","") - - "strip off any read only flag - let line = substitute (line, ' \[RO\]', "","") - - "strip off any bookmark flags - let line = substitute (line, ' {[^}]*}', "","") - - "strip off any executable flags - let line = substitute (line, '*\ze\($\| \)', "","") - - "strip off any generic flags - let line = substitute (line, '\[[^]]*\]', "","") - - let wasdir = 0 - if line =~# '/$' - let wasdir = 1 - endif - let line = substitute (line,' -> .*',"","") " remove link to - if wasdir ==# 1 - let line = substitute (line, '/\?$', '/', "") - endif - - if a:removeLeadingSpaces - let line = substitute (line, '^ *', '', '') - endif - - return line -endfunction " vim: set sw=4 sts=4 et fdm=marker: diff --git a/sources_non_forked/nerdtree/autoload/nerdtree/ui_glue.vim b/sources_non_forked/nerdtree/autoload/nerdtree/ui_glue.vim index 8607389d..1f922df1 100644 --- a/sources_non_forked/nerdtree/autoload/nerdtree/ui_glue.vim +++ b/sources_non_forked/nerdtree/autoload/nerdtree/ui_glue.vim @@ -85,7 +85,7 @@ endfunction "FUNCTION: s:activateAll() {{{1 "handle the user activating the updir line function! s:activateAll() - if getline(".") ==# nerdtree#treeUpDirLine() + if getline(".") ==# g:NERDTreeUI.UpDirLine() return nerdtree#ui_glue#upDir(0) endif endfunction @@ -93,13 +93,13 @@ endfunction "FUNCTION: s:activateDirNode() {{{1 "handle the user activating a tree node function! s:activateDirNode(node) - call a:node.activate({'reuse': 1}) + call a:node.activate() endfunction "FUNCTION: s:activateFileNode() {{{1 "handle the user activating a tree node function! s:activateFileNode(node) - call a:node.activate({'reuse': 1, 'where': 'p'}) + call a:node.activate({'reuse': 'all', 'where': 'p'}) endfunction "FUNCTION: s:activateBookmark() {{{1 @@ -212,7 +212,7 @@ function! s:closeTreeWindow() exec "buffer " . b:NERDTreePreviousBuf else if winnr("$") > 1 - call nerdtree#closeTree() + call g:NERDTree.Close() else call nerdtree#echo("Cannot close last window") endif @@ -275,20 +275,20 @@ function! s:findAndRevealPath() endif else if !p.isUnder(g:NERDTreeFileNode.GetRootForTab().path) - if !nerdtree#isTreeOpen() + if !g:NERDTree.IsOpen() call g:NERDTreeCreator.TogglePrimary('') else - call nerdtree#putCursorInTreeWin() + call g:NERDTree.CursorToTreeWin() endif let b:NERDTreeShowHidden = g:NERDTreeShowHidden call s:chRoot(g:NERDTreeDirNode.New(p.getParent())) else - if !nerdtree#isTreeOpen() + if !g:NERDTree.IsOpen() call g:NERDTreeCreator.TogglePrimary("") endif endif endif - call nerdtree#putCursorInTreeWin() + call g:NERDTree.CursorToTreeWin() call b:NERDTreeRoot.reveal(p) if p.isUnixHiddenFile() @@ -312,7 +312,7 @@ function! s:handleLeftClick() endfor if currentNode.path.isDirectory - if startToCur =~# nerdtree#treeMarkupReg() && startToCur =~# '[+~▾▸] \?$' + if startToCur =~# g:NERDTreeUI.MarkupReg() && startToCur =~# '[+~▾▸] \?$' call currentNode.activate() return endif @@ -320,11 +320,11 @@ function! s:handleLeftClick() if (g:NERDTreeMouseMode ==# 2 && currentNode.path.isDirectory) || g:NERDTreeMouseMode ==# 3 let char = strpart(startToCur, strlen(startToCur)-1, 1) - if char !~# nerdtree#treeMarkupReg() + if char !~# g:NERDTreeUI.MarkupReg() if currentNode.path.isDirectory call currentNode.activate() else - call currentNode.activate({'reuse': 1, 'where': 'p'}) + call currentNode.activate({'reuse': 'all', 'where': 'p'}) endif return endif @@ -547,7 +547,7 @@ endfunction function! nerdtree#ui_glue#setupCommands() command! -n=? -complete=dir -bar NERDTree :call g:NERDTreeCreator.CreatePrimary('') command! -n=? -complete=dir -bar NERDTreeToggle :call g:NERDTreeCreator.TogglePrimary('') - command! -n=0 -bar NERDTreeClose :call nerdtree#closeTreeIfOpen() + command! -n=0 -bar NERDTreeClose :call g:NERDTree.Close() command! -n=1 -complete=customlist,nerdtree#completeBookmarks -bar NERDTreeFromBookmark call g:NERDTreeCreator.CreatePrimary('') command! -n=0 -bar NERDTreeMirror call g:NERDTreeCreator.CreateMirror() command! -n=0 -bar NERDTreeFind call s:findAndRevealPath() diff --git a/sources_non_forked/nerdtree/doc/NERD_tree.txt b/sources_non_forked/nerdtree/doc/NERD_tree.txt index 5d5b3f6f..cfc8ed9b 100644 --- a/sources_non_forked/nerdtree/doc/NERD_tree.txt +++ b/sources_non_forked/nerdtree/doc/NERD_tree.txt @@ -34,6 +34,8 @@ CONTENTS *NERDTree-contents* 4.The NERD tree API.......................|NERDTreeAPI| 4.1.Key map API.......................|NERDTreeKeymapAPI| 4.2.Menu API..........................|NERDTreeMenuAPI| + 4.3.Menu API..........................|NERDTreeAddPathFilter()| + 4.4.Path Listener API.................|NERDTreePathListenerAPI| 5.About...................................|NERDTreeAbout| 6.Changelog...............................|NERDTreeChangelog| 7.Credits.................................|NERDTreeCredits| @@ -131,7 +133,7 @@ The following features and functionality are provided by the NERD tree: :NERDTreeFind *:NERDTreeFind* Find the current file in the tree. - If not tree exists and the current file is under vim's CWD, then init a + If no tree exists and the current file is under vim's CWD, then init a tree at the CWD and reveal the file. Otherwise init a tree in the current file's directory. @@ -1173,6 +1175,44 @@ Where selecting "a (s)ub menu" will lead to a second menu: > When any of the 3 concrete menu items are selected the function "SomeFunction" will be called. +------------------------------------------------------------------------------ +4.3 NERDTreeAddPathFilter(callback) *NERDTreeAddPathFilter()* + +Path filters are essentially a more powerful version of |NERDTreeIgnore|. +If the simple regex matching in |NERDTreeIgnore| is not enough then use +|NERDTreeAddPathFilter()| to add a callback function that paths will be +checked against when the decision to ignore them is made. Example > + + call NERDTreeAddPathFilter('MyFilter') + + function! MyFilter(params) + "params is a dict containing keys: 'nerdtree' and 'path' which are + "g:NERDTree and g:NERDTreePath objects + + "return 1 to ignore params['path'] or 0 otherwise + endfunction +< +------------------------------------------------------------------------------ +4.4 Path Listener API *NERDTreePathListenerAPI* + +Use this API if you want to run a callback for events on Path objects. E.G > + + call g:NERDTreePathNotifier.AddListener("init", "MyListener") + + ".... + + function! MyListener(event) + "This function will be called whenever a Path object is created. + + "a:event is an object that contains a bunch of relevant info - + "including the path in question. See lib/event.vim for details. + endfunction +< +Current events supported: + init ~ + refresh ~ + refreshFlags ~ + ------------------------------------------------------------------------------ NERDTreeRender() *NERDTreeRender()* Re-renders the NERD tree buffer. Useful if you change the state of the @@ -1203,6 +1243,8 @@ Next - add 'scope' argument to the key map API - add NERDTreeCustomIgnoreFilter hook - needs doc - add magic [[dir]] and [[file]] flags to NERDTreeIgnore + - add support for custom path filters. See :help NERDTreeAddPathFilter() + - add path listener API. See :help NERDTreePathListenerAPI. 4.2.0 - Add NERDTreeDirArrows option to make the UI use pretty arrow chars diff --git a/sources_non_forked/nerdtree/lib/nerdtree/bookmark.vim b/sources_non_forked/nerdtree/lib/nerdtree/bookmark.vim index 6de9be4c..8a94b256 100644 --- a/sources_non_forked/nerdtree/lib/nerdtree/bookmark.vim +++ b/sources_non_forked/nerdtree/lib/nerdtree/bookmark.vim @@ -253,7 +253,7 @@ endfunction " FUNCTION: Bookmark.str() {{{1 " Get the string that should be rendered in the view for this bookmark function! s:Bookmark.str() - let pathStrMaxLen = winwidth(nerdtree#getTreeWinNum()) - 4 - len(self.name) + let pathStrMaxLen = winwidth(g:NERDTree.GetWinNum()) - 4 - len(self.name) if &nu let pathStrMaxLen = pathStrMaxLen - &numberwidth endif diff --git a/sources_non_forked/nerdtree/lib/nerdtree/creator.vim b/sources_non_forked/nerdtree/lib/nerdtree/creator.vim index 86f951ae..2d6a5c2e 100644 --- a/sources_non_forked/nerdtree/lib/nerdtree/creator.vim +++ b/sources_non_forked/nerdtree/lib/nerdtree/creator.vim @@ -42,6 +42,11 @@ endfunction "name: the name of a bookmark or a directory function! s:Creator.createPrimary(name) let path = self._pathForString(a:name) + + "abort if exception was thrown (bookmark/dir doesn't exist) + if empty(path) + return + endif "if instructed to, then change the vim CWD to the dir the NERDTree is "inited in @@ -50,8 +55,8 @@ function! s:Creator.createPrimary(name) endif if g:NERDTree.ExistsForTab() - if nerdtree#isTreeOpen() - call nerdtree#closeTree() + if g:NERDTree.IsOpen() + call g:NERDTree.Close() endif unlet t:NERDTreeBufName endif @@ -163,8 +168,8 @@ function! s:Creator.createMirror() return endif - if g:NERDTree.ExistsForTab() && nerdtree#isTreeOpen() - call nerdtree#closeTree() + if g:NERDTree.ExistsForTab() && g:NERDTree.IsOpen() + call g:NERDTree.Close() endif let t:NERDTreeBufName = bufferName @@ -328,14 +333,14 @@ endfunction "initialized. function! s:Creator.togglePrimary(dir) if g:NERDTree.ExistsForTab() - if !nerdtree#isTreeOpen() + if !g:NERDTree.IsOpen() call self._createTreeWin() if !&hidden call b:NERDTree.render() endif call b:NERDTree.ui.restoreScreenState() else - call nerdtree#closeTree() + call g:NERDTree.Close() endif else call self.createPrimary(a:dir) diff --git a/sources_non_forked/nerdtree/lib/nerdtree/nerdtree.vim b/sources_non_forked/nerdtree/lib/nerdtree/nerdtree.vim index a41490b7..55f3dd75 100644 --- a/sources_non_forked/nerdtree/lib/nerdtree/nerdtree.vim +++ b/sources_non_forked/nerdtree/lib/nerdtree/nerdtree.vim @@ -3,6 +3,73 @@ let s:NERDTree = {} let g:NERDTree = s:NERDTree +"FUNCTION: s:NERDTree.AddPathFilter() {{{1 +function! s:NERDTree.AddPathFilter(callback) + call add(s:NERDTree.PathFilters(), a:callback) +endfunction + +"FUNCTION: s:NERDTree.Close() {{{1 +"Closes the primary NERD tree window for this tab +function! s:NERDTree.Close() + if !s:NERDTree.IsOpen() + return + endif + + if winnr("$") != 1 + if winnr() == s:NERDTree.GetWinNum() + call nerdtree#exec("wincmd p") + let bufnr = bufnr("") + call nerdtree#exec("wincmd p") + else + let bufnr = bufnr("") + endif + + call nerdtree#exec(s:NERDTree.GetWinNum() . " wincmd w") + close + call nerdtree#exec(bufwinnr(bufnr) . " wincmd w") + else + close + endif +endfunction + +"FUNCTION: s:NERDTree.CloseIfQuitOnOpen() {{{1 +"Closes the NERD tree window if the close on open option is set +function! s:NERDTree.CloseIfQuitOnOpen() + if g:NERDTreeQuitOnOpen && s:NERDTree.IsOpen() + call s:NERDTree.Close() + endif +endfunction + +"FUNCTION: s:NERDTree.CursorToBookmarkTable(){{{1 +"Places the cursor at the top of the bookmarks table +function! s:NERDTree.CursorToBookmarkTable() + if !b:NERDTreeShowBookmarks + throw "NERDTree.IllegalOperationError: cant find bookmark table, bookmarks arent active" + endif + + if g:NERDTreeMinimalUI + return cursor(1, 2) + endif + + let rootNodeLine = b:NERDTree.ui.getRootLineNum() + + let line = 1 + while getline(line) !~# '^>-\+Bookmarks-\+$' + let line = line + 1 + if line >= rootNodeLine + throw "NERDTree.BookmarkTableNotFoundError: didnt find the bookmarks table" + endif + endwhile + call cursor(line, 2) +endfunction + +"FUNCTION: s:NERDTree.CursorToTreeWin(){{{1 +"Places the cursor in the nerd tree window +function! s:NERDTree.CursorToTreeWin() + call g:NERDTree.MustBeOpen() + call nerdtree#exec(g:NERDTree.GetWinNum() . "wincmd w") +endfunction + " Function: s:NERDTree.ExistsForBuffer() {{{1 " Returns 1 if a nerd tree root exists in the current buffer function! s:NERDTree.ExistsForBuf() @@ -23,6 +90,29 @@ function! s:NERDTree.ForCurrentBuf() endif endfunction +"FUNCTION: s:NERDTree.GetWinNum() {{{1 +"gets the nerd tree window number for this tab +function! s:NERDTree.GetWinNum() + if exists("t:NERDTreeBufName") + return bufwinnr(t:NERDTreeBufName) + else + return -1 + endif +endfunction + +"FUNCTION: s:NERDTree.IsOpen() {{{1 +function! s:NERDTree.IsOpen() + return s:NERDTree.GetWinNum() != -1 +endfunction + +"FUNCTION: s:NERDTree.MustBeOpen() {{{1 +function! s:NERDTree.MustBeOpen() + if !s:NERDTree.IsOpen() + throw "NERDTree.TreeNotOpen" + endif +endfunction + +"FUNCTION: s:NERDTree.New() {{{1 function! s:NERDTree.New(path) let newObj = copy(self) let newObj.ui = g:NERDTreeUI.New(newObj) @@ -31,9 +121,17 @@ function! s:NERDTree.New(path) return newObj endfunction +"FUNCTION: s:NERDTree.PathFilters() {{{1 +function! s:NERDTree.PathFilters() + if !exists('s:NERDTree._PathFilters') + let s:NERDTree._PathFilters = [] + endif + return s:NERDTree._PathFilters +endfunction + + "FUNCTION: s:NERDTree.render() {{{1 "A convenience function - since this is called often function! s:NERDTree.render() call self.ui.render() endfunction - diff --git a/sources_non_forked/nerdtree/lib/nerdtree/opener.vim b/sources_non_forked/nerdtree/lib/nerdtree/opener.vim index 845e55c4..3a6b3924 100644 --- a/sources_non_forked/nerdtree/lib/nerdtree/opener.vim +++ b/sources_non_forked/nerdtree/lib/nerdtree/opener.vim @@ -40,7 +40,7 @@ function! s:Opener._checkToCloseTree(newtab) endif if (a:newtab && self._where == 't') || !a:newtab - call nerdtree#closeTreeIfQuitOnOpen() + call g:NERDTree.CloseIfQuitOnOpen() endif endfunction @@ -131,7 +131,8 @@ endfunction " 'where': Specifies whether the node should be opened in new split/tab or in " the previous window. Can be either 'v' or 'h' or 't' (for open in " new tab) -" 'reuse': if a window is displaying the file then jump the cursor there +" 'reuse': if a window is displaying the file then jump the cursor there. Can +" 'all', 'currenttab' or empty to not reuse. " 'keepopen': dont close the tree window " 'stay': open the file, but keep the cursor in the tree win function! s:Opener.New(path, opts) @@ -139,7 +140,13 @@ function! s:Opener.New(path, opts) let newObj._path = a:path let newObj._stay = nerdtree#has_opt(a:opts, 'stay') - let newObj._reuse = nerdtree#has_opt(a:opts, 'reuse') + + if has_key(a:opts, 'reuse') + let newObj._reuse = a:opts['reuse'] + else + let newObj._reuse = '' + endif + let newObj._keepopen = nerdtree#has_opt(a:opts, 'keepopen') let newObj._where = has_key(a:opts, 'where') ? a:opts['where'] : '' let newObj._treetype = b:NERDTreeType @@ -189,7 +196,7 @@ function! s:Opener._newSplit() try exec(splitMode." sp ") catch /^Vim\%((\a\+)\)\=:E37/ - call nerdtree#putCursorInTreeWin() + call g:NERDTree.CursorToTreeWin() throw "NERDTree.FileAlreadyOpenAndModifiedError: ". self._path.str() ." is already open and modified." catch /^Vim\%((\a\+)\)\=:/ "do nothing @@ -219,7 +226,7 @@ function! s:Opener._newVSplit() vnew "resize the nerd tree back to the original size - call nerdtree#putCursorInTreeWin() + call g:NERDTree.CursorToTreeWin() exec("silent vertical resize ". winwidth) call nerdtree#exec('wincmd p') endfunction @@ -235,7 +242,7 @@ endfunction "FUNCTION: Opener._openFile() {{{1 function! s:Opener._openFile() - if self._reuse && self._reuseWindow() + if self._reuseWindow() return endif @@ -288,7 +295,7 @@ function! s:Opener._previousWindow() call nerdtree#exec('wincmd p') endif catch /^Vim\%((\a\+)\)\=:E37/ - call nerdtree#putCursorInTreeWin() + call g:NERDTree.CursorToTreeWin() throw "NERDTree.FileAlreadyOpenAndModifiedError: ". self._path.str() ." is already open and modified." catch /^Vim\%((\a\+)\)\=:/ echo v:exception @@ -307,23 +314,32 @@ endfunction " "return 1 if we were successful function! s:Opener._reuseWindow() + if empty(self._reuse) + return 0 + endif + "check the current tab for the window let winnr = bufwinnr('^' . self._path.str() . '$') if winnr != -1 call nerdtree#exec(winnr . "wincmd w") call self._checkToCloseTree(0) return 1 - else - "check other tabs - let tabnr = self._path.tabnr() - if tabnr - call self._checkToCloseTree(1) - call nerdtree#exec('normal! ' . tabnr . 'gt') - let winnr = bufwinnr('^' . self._path.str() . '$') - call nerdtree#exec(winnr . "wincmd w") - return 1 - endif endif + + if self._reuse == 'currenttab' + return 0 + endif + + "check other tabs + let tabnr = self._path.tabnr() + if tabnr + call self._checkToCloseTree(1) + call nerdtree#exec('normal! ' . tabnr . 'gt') + let winnr = bufwinnr('^' . self._path.str() . '$') + call nerdtree#exec(winnr . "wincmd w") + return 1 + endif + return 0 endfunction diff --git a/sources_non_forked/nerdtree/lib/nerdtree/path.vim b/sources_non_forked/nerdtree/lib/nerdtree/path.vim index dbecb027..2af07ddb 100644 --- a/sources_non_forked/nerdtree/lib/nerdtree/path.vim +++ b/sources_non_forked/nerdtree/lib/nerdtree/path.vim @@ -1,6 +1,12 @@ "we need to use this number many times for sorting... so we calculate it only "once here let s:NERDTreeSortStarIndex = index(g:NERDTreeSortOrder, '*') +" used in formating sortKey, e.g. '%04d' +if exists("log10") + let s:sortKeyFormat = "%0" . float2nr(ceil(log10(len(g:NERDTreeSortOrder)))) . "d" +else + let s:sortKeyFormat = "%04d" +endif "CLASS: Path "============================================================ @@ -361,6 +367,24 @@ function! s:Path.getSortOrderIndex() return s:NERDTreeSortStarIndex endfunction +"FUNCTION: Path.getSortKey() {{{1 +"returns a string used in compare function for sorting +function! s:Path.getSortKey() + if !exists("self._sortKey") + let path = self.getLastPathComponent(1) + if !g:NERDTreeSortHiddenFirst + let path = substitute(path, '^[._]', '', '') + endif + if !g:NERDTreeCaseSensitiveSort + let path = tolower(path) + endif + let self._sortKey = printf(s:sortKeyFormat, self.getSortOrderIndex()) . path + endif + + return self._sortKey +endfunction + + "FUNCTION: Path.isUnixHiddenFile() {{{1 "check for unix hidden files function! s:Path.isUnixHiddenFile() @@ -392,6 +416,12 @@ function! s:Path.ignore() return 1 endif endfor + + for callback in g:NERDTree.PathFilters() + if {callback}({'path': self, 'nerdtree': b:NERDTree}) + return 1 + endif + endfor endif "dont show hidden files unless instructed to @@ -403,10 +433,6 @@ function! s:Path.ignore() return 1 endif - if exists("*NERDTreeCustomIgnoreFilter") && NERDTreeCustomIgnoreFilter(self) - return 1 - endif - return 0 endfunction @@ -611,7 +637,7 @@ function! s:Path.str(...) if has_key(self, '_strFor' . format) exec 'let toReturn = self._strFor' . format . '()' else - raise 'NERDTree.UnknownFormatError: unknown format "'. format .'"' + throw 'NERDTree.UnknownFormatError: unknown format "'. format .'"' endif else let toReturn = self._str() diff --git a/sources_non_forked/nerdtree/lib/nerdtree/tree_dir_node.vim b/sources_non_forked/nerdtree/lib/nerdtree/tree_dir_node.vim index a24c2704..765982df 100644 --- a/sources_non_forked/nerdtree/lib/nerdtree/tree_dir_node.vim +++ b/sources_non_forked/nerdtree/lib/nerdtree/tree_dir_node.vim @@ -246,8 +246,12 @@ function! s:TreeDirNode._initChildren(silent) "filter out the .. and . directories "Note: we must match .. AND ../ cos sometimes the globpath returns "../ for path with strange chars (eg $) - if i !~# '\/\.\.\/\?$' && i !~# '\/\.\/\?$' - +" if i !~# '\/\.\.\/\?$' && i !~# '\/\.\/\?$' +" + " Regular expression is too expensive. Use simply string comparison + " instead + if i[len(i)-3:2] != ".." && i[len(i)-2:2] != ".." && + \ i[len(i)-2:1] != "." && i[len(i)-1] != "." "put the next file in a new node and attach it try let path = g:NERDTreePath.New(i) @@ -405,8 +409,12 @@ function! s:TreeDirNode.refresh() "filter out the .. and . directories "Note: we must match .. AND ../ cos sometimes the globpath returns "../ for path with strange chars (eg $) - if i !~# '\/\.\.\/\?$' && i !~# '\/\.\/\?$' + "if i !~# '\/\.\.\/\?$' && i !~# '\/\.\/\?$' + " Regular expression is too expensive. Use simply string comparison + " instead + if i[len(i)-3:2] != ".." && i[len(i)-2:2] != ".." && + \ i[len(i)-2:1] != "." && i[len(i)-1] != "." try "create a new path and see if it exists in this nodes children let path = g:NERDTreePath.New(i) @@ -504,7 +512,7 @@ endfunction "directory priority. " function! s:TreeDirNode.sortChildren() - let CompareFunc = function("nerdtree#compareNodes") + let CompareFunc = function("nerdtree#compareNodesBySortKey") call sort(self.children, CompareFunc) endfunction diff --git a/sources_non_forked/nerdtree/lib/nerdtree/ui.vim b/sources_non_forked/nerdtree/lib/nerdtree/ui.vim index ed93d80c..22e450c8 100644 --- a/sources_non_forked/nerdtree/lib/nerdtree/ui.vim +++ b/sources_non_forked/nerdtree/lib/nerdtree/ui.vim @@ -3,11 +3,6 @@ let s:UI = {} let g:NERDTreeUI = s:UI - -function! s:UI.lolcats() - echomsg "lolcats" -endfunction - "FUNCTION: s:UI.centerView() {{{2 "centers the nerd tree window around the cursor (provided the nerd tree "options permit) @@ -15,13 +10,121 @@ function! s:UI.centerView() if g:NERDTreeAutoCenter let current_line = winline() let lines_to_top = current_line - let lines_to_bottom = winheight(nerdtree#getTreeWinNum()) - current_line + let lines_to_bottom = winheight(g:NERDTree.GetWinNum()) - current_line if lines_to_top < g:NERDTreeAutoCenterThreshold || lines_to_bottom < g:NERDTreeAutoCenterThreshold normal! zz endif endif endfunction +"FUNCTION: s:UI._dumpHelp {{{1 +"prints out the quick help +function! s:UI._dumpHelp() + let old_h = @h + if b:treeShowHelp ==# 1 + let @h= "\" NERD tree (" . nerdtree#version() . ") quickhelp~\n" + let @h=@h."\" ============================\n" + let @h=@h."\" File node mappings~\n" + let @h=@h."\" ". (g:NERDTreeMouseMode ==# 3 ? "single" : "double") ."-click,\n" + let @h=@h."\" ,\n" + if b:NERDTreeType ==# "primary" + let @h=@h."\" ". g:NERDTreeMapActivateNode .": open in prev window\n" + else + let @h=@h."\" ". g:NERDTreeMapActivateNode .": open in current window\n" + endif + if b:NERDTreeType ==# "primary" + let @h=@h."\" ". g:NERDTreeMapPreview .": preview\n" + endif + let @h=@h."\" ". g:NERDTreeMapOpenInTab.": open in new tab\n" + let @h=@h."\" ". g:NERDTreeMapOpenInTabSilent .": open in new tab silently\n" + let @h=@h."\" middle-click,\n" + let @h=@h."\" ". g:NERDTreeMapOpenSplit .": open split\n" + let @h=@h."\" ". g:NERDTreeMapPreviewSplit .": preview split\n" + let @h=@h."\" ". g:NERDTreeMapOpenVSplit .": open vsplit\n" + let @h=@h."\" ". g:NERDTreeMapPreviewVSplit .": preview vsplit\n" + + let @h=@h."\"\n\" ----------------------------\n" + let @h=@h."\" Directory node mappings~\n" + let @h=@h."\" ". (g:NERDTreeMouseMode ==# 1 ? "double" : "single") ."-click,\n" + let @h=@h."\" ". g:NERDTreeMapActivateNode .": open & close node\n" + let @h=@h."\" ". g:NERDTreeMapOpenRecursively .": recursively open node\n" + let @h=@h."\" ". g:NERDTreeMapCloseDir .": close parent of node\n" + let @h=@h."\" ". g:NERDTreeMapCloseChildren .": close all child nodes of\n" + let @h=@h."\" current node recursively\n" + let @h=@h."\" middle-click,\n" + let @h=@h."\" ". g:NERDTreeMapOpenExpl.": explore selected dir\n" + + let @h=@h."\"\n\" ----------------------------\n" + let @h=@h."\" Bookmark table mappings~\n" + let @h=@h."\" double-click,\n" + let @h=@h."\" ". g:NERDTreeMapActivateNode .": open bookmark\n" + let @h=@h."\" ". g:NERDTreeMapOpenInTab.": open in new tab\n" + let @h=@h."\" ". g:NERDTreeMapOpenInTabSilent .": open in new tab silently\n" + let @h=@h."\" ". g:NERDTreeMapDeleteBookmark .": delete bookmark\n" + + let @h=@h."\"\n\" ----------------------------\n" + let @h=@h."\" Tree navigation mappings~\n" + let @h=@h."\" ". g:NERDTreeMapJumpRoot .": go to root\n" + let @h=@h."\" ". g:NERDTreeMapJumpParent .": go to parent\n" + let @h=@h."\" ". g:NERDTreeMapJumpFirstChild .": go to first child\n" + let @h=@h."\" ". g:NERDTreeMapJumpLastChild .": go to last child\n" + let @h=@h."\" ". g:NERDTreeMapJumpNextSibling .": go to next sibling\n" + let @h=@h."\" ". g:NERDTreeMapJumpPrevSibling .": go to prev sibling\n" + + let @h=@h."\"\n\" ----------------------------\n" + let @h=@h."\" Filesystem mappings~\n" + let @h=@h."\" ". g:NERDTreeMapChangeRoot .": change tree root to the\n" + let @h=@h."\" selected dir\n" + let @h=@h."\" ". g:NERDTreeMapUpdir .": move tree root up a dir\n" + let @h=@h."\" ". g:NERDTreeMapUpdirKeepOpen .": move tree root up a dir\n" + let @h=@h."\" but leave old root open\n" + let @h=@h."\" ". g:NERDTreeMapRefresh .": refresh cursor dir\n" + let @h=@h."\" ". g:NERDTreeMapRefreshRoot .": refresh current root\n" + let @h=@h."\" ". g:NERDTreeMapMenu .": Show menu\n" + let @h=@h."\" ". g:NERDTreeMapChdir .":change the CWD to the\n" + let @h=@h."\" selected dir\n" + let @h=@h."\" ". g:NERDTreeMapCWD .":change tree root to CWD\n" + + let @h=@h."\"\n\" ----------------------------\n" + let @h=@h."\" Tree filtering mappings~\n" + let @h=@h."\" ". g:NERDTreeMapToggleHidden .": hidden files (" . (b:NERDTreeShowHidden ? "on" : "off") . ")\n" + let @h=@h."\" ". g:NERDTreeMapToggleFilters .": file filters (" . (b:NERDTreeIgnoreEnabled ? "on" : "off") . ")\n" + let @h=@h."\" ". g:NERDTreeMapToggleFiles .": files (" . (b:NERDTreeShowFiles ? "on" : "off") . ")\n" + let @h=@h."\" ". g:NERDTreeMapToggleBookmarks .": bookmarks (" . (b:NERDTreeShowBookmarks ? "on" : "off") . ")\n" + + "add quickhelp entries for each custom key map + let @h=@h."\"\n\" ----------------------------\n" + let @h=@h."\" Custom mappings~\n" + for i in g:NERDTreeKeyMap.All() + if !empty(i.quickhelpText) + let @h=@h."\" ". i.key .": ". i.quickhelpText ."\n" + endif + endfor + + let @h=@h."\"\n\" ----------------------------\n" + let @h=@h."\" Other mappings~\n" + let @h=@h."\" ". g:NERDTreeMapQuit .": Close the NERDTree window\n" + let @h=@h."\" ". g:NERDTreeMapToggleZoom .": Zoom (maximize-minimize)\n" + let @h=@h."\" the NERDTree window\n" + let @h=@h."\" ". g:NERDTreeMapHelp .": toggle help\n" + let @h=@h."\"\n\" ----------------------------\n" + let @h=@h."\" Bookmark commands~\n" + let @h=@h."\" :Bookmark []\n" + let @h=@h."\" :BookmarkToRoot \n" + let @h=@h."\" :RevealBookmark \n" + let @h=@h."\" :OpenBookmark \n" + let @h=@h."\" :ClearBookmarks []\n" + let @h=@h."\" :ClearAllBookmarks\n" + silent! put h + elseif g:NERDTreeMinimalUI == 0 + let @h="\" Press ". g:NERDTreeMapHelp ." for help\n" + silent! put h + endif + + let @h = old_h +endfunction + + "FUNCTION: s:UI.new(nerdtree) {{{1 function! s:UI.New(nerdtree) let newObj = copy(self) @@ -56,14 +159,14 @@ function! s:UI.getPath(ln) endif endif - if line ==# nerdtree#treeUpDirLine() + if line ==# s:UI.UpDirLine() return b:NERDTreeRoot.path.getParent() endif let indent = self._indentLevelFor(line) "remove the tree parts and the leading space - let curFile = nerdtree#stripMarkupFromLine(line, 0) + let curFile = self._stripMarkup(line, 0) let wasdir = 0 if curFile =~# '/$' @@ -76,7 +179,7 @@ function! s:UI.getPath(ln) while lnum > 0 let lnum = lnum - 1 let curLine = getline(lnum) - let curLineStripped = nerdtree#stripMarkupFromLine(curLine, 1) + let curLineStripped = self._stripMarkup(curLine, 1) "have we reached the top of the tree? if lnum == rootLine @@ -127,7 +230,7 @@ function! s:UI.getLineNum(file_node) let indent = self._indentLevelFor(curLine) if indent ==# curPathComponent - let curLine = nerdtree#stripMarkupFromLine(curLine, 1) + let curLine = self._stripMarkup(curLine, 1) let curPath = join(pathcomponents, '/') . '/' . curLine if stridx(fullpath, curPath, 0) ==# 0 @@ -146,7 +249,6 @@ function! s:UI.getLineNum(file_node) return -1 endfunction - "FUNCTION: s:UI.getRootLineNum(){{{1 "gets the line number of the root node function! s:UI.getRootLineNum() @@ -157,9 +259,9 @@ function! s:UI.getRootLineNum() return rootLine endfunction -"FUNCTION: s:UI._indentLevelFor(line) {{{2 +"FUNCTION: s:UI._indentLevelFor(line) {{{1 function! s:UI._indentLevelFor(line) - let level = match(a:line, '[^ \-+~▸▾`|]') / nerdtree#treeWid() + let level = match(a:line, '[^ \-+~▸▾`|]') / s:UI.IndentWid() " check if line includes arrows if match(a:line, '[▸▾]') > -1 " decrement level as arrow uses 3 ascii chars @@ -168,8 +270,38 @@ function! s:UI._indentLevelFor(line) return level endfunction +"FUNCTION: s:UI.IndentWid() {{{1 +function! s:UI.IndentWid() + return 2 +endfunction -"FUNCTION: s:UI.restoreScreenState() {{{2 +"FUNCTION: s:UI.MarkupReg() {{{1 +function! s:UI.MarkupReg() + if g:NERDTreeDirArrows + return '^\([▾▸] \| \+[▾▸] \| \+\)' + endif + + return '^[ `|]*[\-+~]' +endfunction + +"FUNCTION: s:UI._renderBookmarks {{{1 +function! s:UI._renderBookmarks() + + if g:NERDTreeMinimalUI == 0 + call setline(line(".")+1, ">----------Bookmarks----------") + call cursor(line(".")+1, col(".")) + endif + + for i in g:NERDTreeBookmark.Bookmarks() + call setline(line(".")+1, i.str()) + call cursor(line(".")+1, col(".")) + endfor + + call setline(line(".")+1, '') + call cursor(line(".")+1, col(".")) +endfunction + +"FUNCTION: s:UI.restoreScreenState() {{{1 " "Sets the screen state back to what it was when nerdtree#saveScreenState was last "called. @@ -189,23 +321,60 @@ function! s:UI.restoreScreenState() let &scrolloff=old_scrolloff endfunction -"FUNCTION: s:UI.saveScreenState() {{{2 +"FUNCTION: s:UI.saveScreenState() {{{1 "Saves the current cursor position in the current buffer and the window "scroll position function! s:UI.saveScreenState() let win = winnr() - try - call nerdtree#putCursorInTreeWin() - let self._screenState = {} - let self._screenState['oldPos'] = getpos(".") - let self._screenState['oldTopLine'] = line("w0") - let self._screenState['oldWindowSize']= winwidth("") - call nerdtree#exec(win . "wincmd w") - catch /^NERDTree.InvalidOperationError/ - endtry + call g:NERDTree.CursorToTreeWin() + let self._screenState = {} + let self._screenState['oldPos'] = getpos(".") + let self._screenState['oldTopLine'] = line("w0") + let self._screenState['oldWindowSize']= winwidth("") + call nerdtree#exec(win . "wincmd w") endfunction -"FUNCTION: s:UI.render() {{{2 +"FUNCTION: s:UI._stripMarkup(line, removeLeadingSpaces){{{1 +"returns the given line with all the tree parts stripped off +" +"Args: +"line: the subject line +"removeLeadingSpaces: 1 if leading spaces are to be removed (leading spaces = +"any spaces before the actual text of the node) +function! s:UI._stripMarkup(line, removeLeadingSpaces) + let line = a:line + "remove the tree parts and the leading space + let line = substitute (line, g:NERDTreeUI.MarkupReg(),"","") + + "strip off any read only flag + let line = substitute (line, ' \[RO\]', "","") + + "strip off any bookmark flags + let line = substitute (line, ' {[^}]*}', "","") + + "strip off any executable flags + let line = substitute (line, '*\ze\($\| \)', "","") + + "strip off any generic flags + let line = substitute (line, '\[[^]]*\]', "","") + + let wasdir = 0 + if line =~# '/$' + let wasdir = 1 + endif + let line = substitute (line,' -> .*',"","") " remove link to + if wasdir ==# 1 + let line = substitute (line, '/\?$', '/', "") + endif + + if a:removeLeadingSpaces + let line = substitute (line, '^ *', '', '') + endif + + return line +endfunction + +"FUNCTION: s:UI.render() {{{1 function! s:UI.render() setlocal modifiable @@ -218,7 +387,7 @@ function! s:UI.render() "delete all lines in the buffer (being careful not to clobber a register) silent 1,$delete _ - call nerdtree#dumpHelp() + call self._dumpHelp() "delete the blank line before the help and add one after it if g:NERDTreeMinimalUI == 0 @@ -227,12 +396,12 @@ function! s:UI.render() endif if b:NERDTreeShowBookmarks - call nerdtree#renderBookmarks() + call self._renderBookmarks() endif "add the 'up a dir' line if !g:NERDTreeMinimalUI - call setline(line(".")+1, nerdtree#treeUpDirLine()) + call setline(line(".")+1, s:UI.UpDirLine()) call cursor(line(".")+1, col(".")) endif @@ -295,7 +464,7 @@ function! s:UI.toggleShowBookmarks() let b:NERDTreeShowBookmarks = !b:NERDTreeShowBookmarks if b:NERDTreeShowBookmarks call b:NERDTree.render() - call nerdtree#putCursorOnBookmarkTable() + call g:NERDTree.CursorToBookmarkTable() else call b:NERDTree.ui.renderViewSavingPosition() endif @@ -330,3 +499,8 @@ function! s:UI.toggleZoom() let b:NERDTreeZoomed = 1 endif endfunction + +"FUNCTION: s:UI.UpDirLine() {{{1 +function! s:UI.UpDirLine() + return '.. (up a dir)' +endfunction diff --git a/sources_non_forked/nerdtree/plugin/NERD_tree.vim b/sources_non_forked/nerdtree/plugin/NERD_tree.vim index 28fd3ad1..966838c3 100644 --- a/sources_non_forked/nerdtree/plugin/NERD_tree.vim +++ b/sources_non_forked/nerdtree/plugin/NERD_tree.vim @@ -148,7 +148,7 @@ call nerdtree#ui_glue#setupCommands() "============================================================ augroup NERDTree "Save the cursor position whenever we close the nerd tree - exec "autocmd BufLeave ". g:NERDTreeCreator.BufNamePrefix() ."* call b:NERDTree.ui.saveScreenState()" + exec "autocmd BufLeave ". g:NERDTreeCreator.BufNamePrefix() ."* if g:NERDTree.IsOpen() | call b:NERDTree.ui.saveScreenState() | endif" "disallow insert mode in the NERDTree exec "autocmd BufEnter ". g:NERDTreeCreator.BufNamePrefix() ."* stopinsert" @@ -185,8 +185,8 @@ function! NERDTreeRender() endfunction function! NERDTreeFocus() - if nerdtree#isTreeOpen() - call nerdtree#putCursorInTreeWin() + if g:NERDTree.IsOpen() + call g:NERDTree.CursorToTreeWin() else call g:NERDTreeCreator.TogglePrimary("") endif @@ -196,6 +196,11 @@ function! NERDTreeCWD() call NERDTreeFocus() call nerdtree#ui_glue#chRootCwd() endfunction + +function! NERDTreeAddPathFilter(callback) + call g:NERDTree.AddPathFilter(a:callback) +endfunction + " SECTION: Post Source Actions {{{1 call nerdtree#postSourceActions() diff --git a/sources_non_forked/syntastic/README.markdown b/sources_non_forked/syntastic/README.markdown index 6c6fab4f..b9e08c4e 100644 --- a/sources_non_forked/syntastic/README.markdown +++ b/sources_non_forked/syntastic/README.markdown @@ -53,21 +53,22 @@ are detected, the user is notified and is happy because they didn't have to compile their code or execute their script to find them. At the time of this writing, syntastic has checking plugins for ActionScript, -Ada, API Blueprint, AppleScript, AsciiDoc, ASM, BEMHTML, Bro, Bourne shell, -C, C++, C#, Cabal, Chef, CoffeeScript, Coco, Coq, CSS, Cucumber, CUDA, D, -Dart, DocBook, Dust, Elixir, Erlang, eRuby, Fortran, Gentoo metadata, GLSL, -Go, Haml, Haskell, Haxe, Handlebars, HSS, HTML, Java, JavaScript, JSON, JSX, -LESS, Lex, Limbo, LISP, LLVM intermediate language, Lua, Markdown, MATLAB, -NASM, Objective-C, Objective-C++, OCaml, Perl, Perl POD, PHP, gettext Portable +Ada, API Blueprint, AppleScript, AsciiDoc, ASM, BEMHTML, Bro, Bourne shell, C, +C++, C#, Cabal, Chef, CoffeeScript, Coco, Coq, CSS, Cucumber, CUDA, D, Dart, +DocBook, Dust, Elixir, Erlang, eRuby, Fortran, Gentoo metadata, GLSL, Go, Haml, +Haskell, Haxe, Handlebars, HSS, HTML, Java, JavaScript, JSON, JSX, LESS, Lex, +Limbo, LISP, LLVM intermediate language, Lua, Markdown, MATLAB, Mercury, NASM, +Nix, Objective-C, Objective-C++, OCaml, Perl, Perl POD, PHP, gettext Portable Object, OS X and iOS property lists, Puppet, Python, R, Racket, Relax NG, -reStructuredText, RPM spec, Ruby, SASS/SCSS, Scala, Slim, SML, Tcl, TeX, -Texinfo, Twig, TypeScript, Vala, Verilog, VHDL, VimL, xHtml, XML, XSLT, YACC, -YAML, z80, Zope page templates, and zsh. See the [wiki][3] for details about -the corresponding supported checkers. +reStructuredText, RPM spec, Ruby, SASS/SCSS, Scala, Slim, SML, Sphinx, Tcl, +TeX, Texinfo, Twig, TypeScript, Vala, Verilog, VHDL, VimL, xHtml, XML, XSLT, +YACC, YAML, z80, Zope page templates, and zsh. See the [wiki][3] for details +about the corresponding supported checkers. A number of third-party Vim plugins also provide checkers for syntastic, for example: [omnisharp-vim][25], [rust.vim][12], [syntastic-extras][26], -[syntastic-more][27], and [vim-swift][24]. +[syntastic-more][27], [vim-crystal][29], [vim-eastwood][28], and +[vim-swift][24]. Below is a screenshot showing the methods that Syntastic uses to display syntax errors. Note that, in practise, you will only have a subset of these methods @@ -410,7 +411,7 @@ work around it: ```vim nnoremap :lclose:bdelete -cabbrev bd lclose\|bdelete +cabbrev bd =(getcmdtype()==#':' && getcmdpos()==1 ? 'lclose\|bdelete' : 'bd') ``` @@ -456,6 +457,8 @@ a look at [jedi-vim][7], [python-mode][8], or [YouCompleteMe][9]. [25]: https://github.com/OmniSharp/omnisharp-vim [26]: https://github.com/myint/syntastic-extras [27]: https://github.com/roktas/syntastic-more +[28]: https://github.com/venantius/vim-eastwood +[29]: https://github.com/rhysd/vim-crystal