Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 31d1835

Browse files
committedApr 21, 2013
Make compatibility with miscellaneous scripts explicit
2 parents b257136 + a744d4c commit 31d1835

File tree

8 files changed

+115
-24
lines changed

8 files changed

+115
-24
lines changed
 

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
doc/tags

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ If you have questions, bug reports, suggestions, etc. the author can be contacte
8989
## License
9090

9191
This software is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License).
92-
© 2011 Peter Odding &lt;<peter@peterodding.com>&gt;.
92+
© 2013 Peter Odding &lt;<peter@peterodding.com>&gt;.
9393

9494

9595
[autocmd]: http://vimdoc.sourceforge.net/htmldoc/autocmd.html#:autocmd

‎autoload/xolox/misc/README.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,49 @@
11
# Miscellaneous auto-load Vim scripts
22

3-
The git repository at <http://github.com/xolox/vim-misc> contains Vim scripts that are used by most of the [Vim plug-ins I've written] [plugins] yet don't really belong with any single one. I include this repository as a subdirectory of my plug-in repositories using the following commands:
3+
The git repository at [github.com/xolox/vim-misc] [repository] contains Vim scripts that are used by most of the [Vim plug-ins I've written] [plugins] yet don't really belong with any single one. I include this repository as a subdirectory of my plug-in repositories using the following commands:
44

55
$ git remote add -f vim-misc https://github.com/xolox/vim-misc.git
66
$ git merge -s ours --no-commit vim-misc/master
77
$ git read-tree --prefix=autoload/xolox/misc/ -u vim-misc/master
88
$ git commit -m "Merge vim-misc repository as subdirectory"
99

10-
To update a plug-in repository to the latest versions of the miscellaneous auto-load scripts I execute the following command:
10+
The above trick is called the [subtree merge strategy] [merge-strategy]. To update a plug-in repository to the latest version of the miscellaneous auto-load scripts I execute the following command:
1111

1212
$ git pull -s subtree vim-misc master
1313

14+
## Why make things so complex?
15+
16+
I came up with this solution after multiple years of back and forth between Vim Online users, the GitHub crowd and my own sanity:
17+
18+
1. When I started publishing my first Vim plug-ins I would prepare ZIP archives for Vim Online using makefiles. The makefiles would make sure the miscellaneous scripts were included in the uploaded distributions. This had two disadvantages: It lost git history and the repositories on GitHub were not usable out of the box, so [I got complaints from GitHub (Pathogen) users] [github-complaints].
19+
20+
2. My second attempt to solve the problem used git submodules which seemed like the ideal solution until I actually started doing it. Submodules are not initialized during a normal `git clone`, you need to use `git clone --recursive` instead but Vim plug-in managers like [Pathogen] [pathogen] and [Vundle] [vundle] don't do this (at least [they didn't when I tried] [vundle-discussion]) so people would end up with broken checkouts.
21+
22+
3. After finding out that git submodules were not going to solve my problems I searched for other inclusion strategies supported by git. After a while I came upon the [subtree merge strategy] [merge-strategy] which I have been using for more than two years now.
23+
24+
## Compatibility issues
25+
26+
Regardless of the inclusion strategies discussed above, my current scheme has a flaw: If more than one of my plug-ins are installed in a Vim profile using [Pathogen] [pathogen] or [Vundle] [vundle], the miscellaneous autoload scripts will all be loaded from the subdirectory of one single plug-in.
27+
28+
This means that when I break compatibility in the miscellaneous scripts, I have to make sure to merge the changes into all of my plug-ins. Even then, if a user has more than one of my plug-ins installed but updates only one of them, the other plug-ins (that are not yet up to date) can break (because of the backwards incompatible change).
29+
30+
The `xolox#misc#compat#check()` function makes sure that incompatibilities are detected early so that the user knows which plug-in to update if incompatibilities arise.
31+
1432
## Contact
1533

1634
If you have questions, bug reports, suggestions, etc. the author can be contacted at <peter@peterodding.com>. The latest version is available at <http://peterodding.com/code/vim/misc> and <http://github.com/xolox/vim-misc>.
1735

1836
## License
1937

20-
This software is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License).
21-
© 2011 Peter Odding &lt;<peter@peterodding.com>&gt;.
38+
This software is licensed under the [MIT license] [mit].
39+
© 2013 Peter Odding &lt;<peter@peterodding.com>&gt;.
2240

2341

42+
[github-complaints]: https://github.com/xolox/vim-easytags/issues/1
43+
[merge-strategy]: http://www.kernel.org/pub/software/scm/git/docs/howto/using-merge-subtree.html
44+
[mit]: http://en.wikipedia.org/wiki/MIT_License
45+
[pathogen]: http://www.vim.org/scripts/script.php?script_id=2332
2446
[plugins]: http://peterodding.com/code/vim/
47+
[repository]: https://github.com/xolox/vim-misc
48+
[vundle-discussion]: https://github.com/gmarik/vundle/pull/41
49+
[vundle]: https://github.com/gmarik/vundle

‎autoload/xolox/misc/buffer.vim

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,51 @@
11
" Vim auto-load script
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: September 4, 2011
3+
" Last Change: April 18, 2013
44
" URL: http://peterodding.com/code/vim/misc/
55

6-
function! xolox#misc#buffer#is_empty()
6+
function! xolox#misc#buffer#is_empty() " {{{1
77
" Check if the current buffer is an empty, unchanged buffer which can be reused.
88
return !&modified && expand('%') == '' && line('$') <= 1 && getline(1) == ''
99
endfunction
1010

11-
function! xolox#misc#buffer#prepare(bufname)
12-
let bufname = '[' . a:bufname . ']'
13-
let buffers = tabpagebuflist()
14-
call map(buffers, 'fnamemodify(bufname(v:val), ":t:r")')
15-
let idx = index(buffers, bufname)
16-
if idx >= 0
17-
execute (idx + 1) . 'wincmd w'
18-
elseif !(xolox#misc#buffer#is_empty() || expand('%:t') == bufname)
11+
function! xolox#misc#buffer#prepare(...) " {{{1
12+
" Open a special buffer (with generated contents, not directly edited by the user).
13+
if a:0 == 1 && type(a:1) == type('')
14+
" Backwards compatibility with old interface.
15+
let options = {'name': a:1, 'path': a:1}
16+
elseif type(a:1) == type({})
17+
let options = a:1
18+
else
19+
throw "Invalid arguments"
20+
endif
21+
let winnr = 1
22+
let found = 0
23+
for bufnr in tabpagebuflist()
24+
if xolox#misc#path#equals(options['path'], bufname(bufnr))
25+
execute winnr . 'wincmd w'
26+
let found = 1
27+
break
28+
else
29+
let winnr += 1
30+
endif
31+
endfor
32+
if !(found || xolox#misc#buffer#is_empty())
1933
vsplit
2034
endif
21-
silent execute 'edit' fnameescape(bufname)
35+
silent execute 'edit' fnameescape(options['path'])
2236
lcd " clear working directory
2337
setlocal buftype=nofile bufhidden=hide noswapfile
24-
let &l:statusline = bufname
38+
let &l:statusline = '[' . options['name'] . ']'
2539
call xolox#misc#buffer#unlock()
2640
silent %delete
2741
endfunction
2842

29-
function! xolox#misc#buffer#lock()
43+
function! xolox#misc#buffer#lock() " {{{1
3044
" Lock a special buffer so it can no longer be edited.
3145
setlocal readonly nomodifiable nomodified
3246
endfunction
3347

34-
function! xolox#misc#buffer#unlock()
48+
function! xolox#misc#buffer#unlock() " {{{1
3549
" Unlock a special buffer so that its content can be updated.
3650
setlocal noreadonly modifiable
3751
endfunction

‎autoload/xolox/misc/compat.vim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
" Vim auto-load script
2+
" Author: Peter Odding <peter@peterodding.com>
3+
" Last Change: April 20, 2013
4+
" URL: http://peterodding.com/code/vim/misc/
5+
6+
" The following integer will be bumped whenever a change in the miscellaneous
7+
" scripts breaks backwards compatibility. This enables my Vim plug-ins to fail
8+
" early when they detect an incompatible version, instead of breaking at the
9+
" worst possible moments :-).
10+
let g:xolox#misc#compat#version = 1
11+
12+
" Remember the directory where the miscellaneous scripts are loaded from
13+
" so the user knows which plug-in to update if incompatibilities arise.
14+
let s:misc_directory = fnamemodify(expand('<sfile>'), ':p:h')
15+
16+
function! xolox#misc#compat#check(plugin_name, required_version)
17+
if a:required_version != g:xolox#misc#compat#version
18+
let msg = "The %s plug-in requires version %i of the miscellaneous scripts, however version %i was loaded from %s!"
19+
throw printf(msg, a:plugin_name, a:required_version, g:xolox#misc#compat#version, s:misc_directory)
20+
endif
21+
endfunction
22+
23+
" vim: ts=2 sw=2 et

‎autoload/xolox/misc/path.vim

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
" Vim auto-load script
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: September 26, 2011
3+
" Last Change: April 18, 2013
44
" URL: http://peterodding.com/code/vim/misc/
55

66
let s:windows_compatible = has('win32') || has('win64')
7+
let s:mac_os_x_compatible = has('macunix')
78

89
function! xolox#misc#path#which(...)
910
let extensions = s:windows_compatible ? split($PATHEXT, ';') : ['']
@@ -129,7 +130,13 @@ endfunction
129130
" Encode a pathname so it can be used as a filename.
130131

131132
function! xolox#misc#path#encode(path)
132-
let mask = s:windows_compatible ? '[*|\\/:"<>?%]' : '[\\/%]'
133+
if s:windows_compatible
134+
let mask = '[*|\\/:"<>?%]'
135+
elseif s:mac_os_x_compatible
136+
let mask = '[\\/%:]'
137+
else
138+
let mask = '[\\/%]'
139+
endif
133140
return substitute(a:path, mask, '\=printf("%%%x", char2nr(submatch(0)))', 'g')
134141
endfunction
135142

‎autoload/xolox/reload.vim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
" Vim script
2-
" Last Change: December 1, 2011
2+
" Last Change: April 21, 2013
33
" Author: Peter Odding
44
" URL: http://peterodding.com/code/vim/reload/
55

6-
let g:xolox#reload#version = '0.6.8'
6+
let g:xolox#reload#version = '0.6.9'
7+
8+
call xolox#misc#compat#check('reload', 1)
79

810
" Patterns to match various types of Vim script names. {{{1
911

‎doc/reload.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
*reload.txt* Automatic reloading of Vim scripts
22

3+
===============================================================================
4+
*reload-contents*
5+
Contents ~
6+
7+
1. Introduction |reload-introduction|
8+
2. Install & first use |reload-install-first-use|
9+
1. The |g:reload_on_write| option
10+
2. The |:ReloadScript| command
11+
3. Things that prevent reloading |things-that-prevent-reloading|
12+
1. Use a bang in command and function definitions!
13+
2. Use automatic command groups |reload-use-automatic-command-groups|
14+
4. Alternatives |reload-alternatives|
15+
5. Contact |reload-contact|
16+
6. License |reload-license|
17+
18+
===============================================================================
19+
*reload-introduction*
20+
Introduction ~
21+
322
The reload.vim plug-in automatically reloads various types of Vim scripts as
423
you're editing them in Vim to give you instant feedback on the changes you
524
make. For example while writing a Vim syntax script you can open a split
@@ -145,7 +164,7 @@ If you like the plug-in please vote for it on Vim Online [3].
145164
*reload-license*
146165
License ~
147166

148-
This software is licensed under the MIT license [4]. Copyright 2011 Peter
167+
This software is licensed under the MIT license [4]. Copyright 2013 Peter
149168
Odding <peter@peterodding.com>.
150169

151170
===============================================================================

0 commit comments

Comments
 (0)
Please sign in to comment.