annotate runtime/autoload/netrw_gitignore.vim @ 10631:cbf17371627c v8.0.0205

patch 8.0.0205: wrong behavior after :undojoin commit https://github.com/vim/vim/commit/5e4e1b12998b1ed99138cad1c5da4d430f798547 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jan 17 22:09:45 2017 +0100 patch 8.0.0205: wrong behavior after :undojoin Problem: After :undojoin some commands don't work properly, such as :redo. (Matthew Malcomson) Solution: Don't set curbuf->b_u_curhead. (closes #1390)
author Christian Brabandt <cb@256bit.org>
date Tue, 17 Jan 2017 22:15:04 +0100
parents 11d78e58a487
children e9a47bcf7b94
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5618
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1 " netrw_gitignore#Hide: gitignore-based hiding
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2 " Function returns a string of comma separated patterns convenient for
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3 " assignment to `g:netrw_list_hide` option.
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4 " Function can take additional filenames as arguments, example:
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5 " netrw_gitignore#Hide('custom_gitignore1', 'custom_gitignore2')
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6 "
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
7 " Usage examples:
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
8 " let g:netrw_list_hide = netrw_gitignore#Hide()
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
9 " let g:netrw_list_hide = netrw_gitignore#Hide() . 'more,hide,patterns'
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
10 "
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
11 " Copyright: Copyright (C) 2013 Bruno Sutic {{{1
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
12 " Permission is hereby granted to use and distribute this code,
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
13 " with or without modifications, provided that this copyright
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
14 " notice is copied with it. Like anything else that's free,
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
15 " netrw_gitignore.vim is provided *as is* and comes with no
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
16 " warranty of any kind, either expressed or implied. By using
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
17 " this plugin, you agree that in no event will the copyright
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
18 " holder be liable for any damages resulting from the use
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
19 " of this software.
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
20 function! netrw_gitignore#Hide(...)
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
21 let additional_files = a:000
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
22
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
23 let default_files = ['.gitignore', '.git/info/exclude']
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
24
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
25 " get existing global/system gitignore files
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
26 let global_gitignore = expand(substitute(system("git config --global core.excludesfile"), '\n', '', 'g'))
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
27 if global_gitignore !=# ''
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
28 let default_files = add(default_files, global_gitignore)
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
29 endif
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
30 let system_gitignore = expand(substitute(system("git config --system core.excludesfile"), '\n', '', 'g'))
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
31 if system_gitignore !=# ''
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
32 let default_files = add(default_files, system_gitignore)
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
33 endif
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
34
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
35 " append additional files if given as function arguments
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
36 if additional_files !=# []
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
37 let files = extend(default_files, additional_files)
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
38 else
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
39 let files = default_files
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
40 endif
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
41
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
42 " keep only existing/readable files
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
43 let gitignore_files = []
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
44 for file in files
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
45 if filereadable(file)
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
46 let gitignore_files = add(gitignore_files, file)
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
47 endif
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
48 endfor
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
50 " get contents of gitignore patterns from those files
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51 let gitignore_lines = []
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
52 for file in gitignore_files
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
53 for line in readfile(file)
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54 " filter empty lines and comments
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
55 if line !~# '^#' && line !~# '^$'
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
56 let gitignore_lines = add(gitignore_lines, line)
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
57 endif
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
58 endfor
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
59 endfor
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
60
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61 " convert gitignore patterns to Netrw/Vim regex patterns
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
62 let escaped_lines = []
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
63 for line in gitignore_lines
6476
11d78e58a487 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5618
diff changeset
64 let escaped = line
11d78e58a487 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5618
diff changeset
65 let escaped = substitute(escaped, '\*\*', '*', 'g')
11d78e58a487 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5618
diff changeset
66 let escaped = substitute(escaped, '\.', '\\.', 'g')
11d78e58a487 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5618
diff changeset
67 let escaped = substitute(escaped, '\$', '\\$', 'g')
11d78e58a487 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5618
diff changeset
68 let escaped = substitute(escaped, '*', '.*', 'g')
11d78e58a487 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5618
diff changeset
69 " correction: dot, dollar and asterisks chars shouldn't be escaped when
11d78e58a487 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5618
diff changeset
70 " within regex matching groups.
11d78e58a487 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5618
diff changeset
71 let escaped = substitute(escaped, '\(\[[^]]*\)\zs\\\.', '\.', 'g')
11d78e58a487 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5618
diff changeset
72 let escaped = substitute(escaped, '\(\[[^]]*\)\zs\\\$', '\$', 'g')
11d78e58a487 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5618
diff changeset
73 let escaped = substitute(escaped, '\(\[[^]]*\)\zs\.\*', '*', 'g')
5618
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
74 let escaped_lines = add(escaped_lines, escaped)
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
75 endfor
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
76
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
77 return join(escaped_lines, ',')
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
78 endfunction