Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Introduce consistent command naming, closes #49
Old command names still work but show deprecated warning
  • Loading branch information
Mattes Groeger committed Jul 25, 2014
1 parent 0f7b91d commit 2eb9c77
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 66 deletions.
34 changes: 17 additions & 17 deletions README.md
Expand Up @@ -48,15 +48,15 @@ After installation you can directly start using it. You can do this by either us

| Action | Shortcut | Command |
|-------------------------------------------------|-------------|------------------------------|
| Add/remove bookmark at current line | `mm` | `:ToggleBookmark` |
| Add/edit/remove annotation at current line | `mi` | `:Annotate <TEXT>` |
| Jump to next bookmark in buffer | `mn` | `:NextBookmark` |
| Jump to previous bookmark in buffer | `mp` | `:PrevBookmark` |
| Show all bookmarks | `ma` | `:ShowAllBookmarks` |
| Clear bookmarks in current buffer only | `mc` | `:ClearBookmarks` |
| Clear bookmarks in all buffers | `mx` | `:ClearAllBookmarks` |
| Save all bookmarks to a file | | `:SaveBookmarks <FILE_PATH>` |
| Load bookmarks from a file | | `:LoadBookmarks <FILE_PATH>` |
| Add/remove bookmark at current line | `mm` | `:BookmarkToggle` |
| Add/edit/remove annotation at current line | `mi` | `:BookmarkAnnotate <TEXT>` |
| Jump to next bookmark in buffer | `mn` | `:BookmarkNext` |
| Jump to previous bookmark in buffer | `mp` | `:BookmarkPrev` |
| Show all bookmarks | `ma` | `:BookmarkShowAll` |
| Clear bookmarks in current buffer only | `mc` | `:BookmarkClear` |
| Clear bookmarks in all buffers | `mx` | `:BookmarkClearAll` |
| Save all bookmarks to a file | | `:BookmarkSave <FILE_PATH>` |
| Load bookmarks from a file | | `:BookmarkLoad <FILE_PATH>` |

You can change the shortcuts as you like, just read on...

Expand All @@ -67,13 +67,13 @@ You can change the shortcuts as you like, just read on...
You can overwrite any of the default mappings. Just put the following into your `~/.vimrc` and adjust as you like:

```
nmap <Leader><Leader> <Plug>ToggleBookmark
nmap <Leader>i <Plug>Annotate
nmap <Leader>a <Plug>ShowAllBookmarks
nmap <Leader>j <Plug>NextBookmark
nmap <Leader>k <Plug>PrevBookmark
nmap <Leader>c <Plug>ClearBookmarks
nmap <Leader>x <Plug>ClearAllBookmarks
nmap <Leader><Leader> <Plug>BookmarkToggle
nmap <Leader>i <Plug>BookmarkAnnotate
nmap <Leader>a <Plug>BookmarkShowAll
nmap <Leader>j <Plug>BookmarkNext
nmap <Leader>k <Plug>BookmarkPrev
nmap <Leader>c <Plug>BookmarkClear
nmap <Leader>x <Plug>BookmarkClearAll
```

### Colors
Expand Down Expand Up @@ -104,7 +104,7 @@ Put any of the following options into your `~/.vimrc` in order to overwrite the

### Silent saving and loading

Call functions SaveBookmarks, LoadBookmarks and ClearAllBookmarks with the last argument set to 0 to perform these operations silently. You may use this to manage your bookmark list transparently from within your custom script.
Call functions BookmarkSave, BookmarkLoad and BookmarkClearAll with the last argument set to 0 to perform these operations silently. You may use this to manage your bookmark list transparently from within your custom script.

## FAQ

Expand Down
38 changes: 19 additions & 19 deletions doc/bookmarks.txt
Expand Up @@ -60,32 +60,32 @@ You don't have to do anything: it just works.

Commands for using Bookmarks

:ToggleBookmark *:ToggleBookmark*
:BookmarkToggle *:BookmarkToggle*
Add or remove bookmark at current line

:Annotate <TEXT> *:Annotate*
:BookmarkAnnotate <TEXT> *:BookmarkAnnotate*
Add/edit/remove annotation at current line

:NextBookmark *:NextBookmark*
:BookmarkNext *:BookmarkNext*
Jump to the next bookmark downwards

:PrevBookmark *:PrevBookmark*
:BookmarkPrev *:BookmarkPrev*
Jump to the next bookmark upwards

:ShowAllBookmarks *:ShowAllBookmarks*
:BookmarkShowAll *:BookmarkShowAll*
Show bookmarks across all buffers in new window

:ClearBookmarks *:ClearBookmarks*
:BookmarkClear *:BookmarkClear*
Removes bookmarks for current buffer

:ClearAllBookmarks *:ClearAllBookmarks*
:BookmarkClearAll *:BookmarkClearAll*
Removes bookmarks for all buffer

:SaveBookmarks <FILE_PATH> *:SaveBookmarks*
:BookmarkSave <FILE_PATH> *:BookmarkSave*
Saves all bookmarks to a file so you can load them back in later

:LoadBookmarks <FILE_PATH> *:LoadBookmarks*
Loads bookmarks from a file (see :SaveBookmarks)
:BookmarkLoad <FILE_PATH> *:BookmarkLoad*
Loads bookmarks from a file (see :BookmarkSave)

===============================================================================
5. CUSTOMISATION *BookmarksCustomisation*
Expand Down Expand Up @@ -154,13 +154,13 @@ KEY MAPPINGS

To change the default keys:
>
nmap <Leader><Leader> <Plug>ToggleBookmark
nmap <Leader>i <Plug>Annotate
nmap <Leader>a <Plug>ShowAllBookmarks
nmap <Leader>j <Plug>NextBookmark
nmap <Leader>k <Plug>PrevBookmark
nmap <Leader>c <Plug>ClearBookmarks
nmap <Leader>x <Plug>ClearAllBookmarks
nmap <Leader><Leader> <Plug>BookmarkToggle
nmap <Leader>i <Plug>BookmarkAnnotate
nmap <Leader>a <Plug>BookmarkShowAll
nmap <Leader>j <Plug>BookmarkNext
nmap <Leader>k <Plug>BookmarkPrev
nmap <Leader>c <Plug>BookmarkClear
nmap <Leader>x <Plug>BookmarkClearAll
<

MORE OPTIONS
Expand Down Expand Up @@ -206,9 +206,9 @@ Automatically close bookmarks split when jumping to a bookmark (default 0):
6. EXTENDING *BookmarksExtending*

You can implement automatic switching of bookmarks file on your desired event.
To do so, use functions SaveBookmarks, LoadBookmarks and ClearAllBookmarks with
To do so, use functions BookmarkSave, BookmarkLoad and BookmarkClearAll with
the last argument set to 1. This will suppress any messages and prompts these
functions normally issue. The LoadBookmarks function will return 1 to indicate
functions normally issue. The BookmarkLoad function will return 1 to indicate
that file loading was successful, and 0 for failure. An example script using
this feature is located in the 'examples/bm-autoload-example.vim' file.

Expand Down
4 changes: 2 additions & 2 deletions examples/bm-autoload-example.vim
Expand Up @@ -23,7 +23,7 @@ function! AutoloadBookmarks(file_name)
if (root_is_found && found_root != s:last_root)
let s:last_file = found_root . '/.bookmarks'
let s:last_root = found_root
call LoadBookmarks(s:last_file, 0, 1)
call BookmarkLoad(s:last_file, 0, 1)

augroup AutoSaveBookmarks
autocmd!
Expand All @@ -40,7 +40,7 @@ augroup AutoLoadBookmarks
augroup END

function! s:remove_group()
call SaveBookmarks(s:last_file, 1)
call BookmarkSave(s:last_file, 1)
augroup AutoSaveBookmarks
autocmd!
augroup END
Expand Down
70 changes: 42 additions & 28 deletions plugin/bookmark.vim
Expand Up @@ -35,7 +35,7 @@ augroup END

" Commands {{{

function! ToggleBookmark()
function! BookmarkToggle()
call s:refresh_line_numbers()
let file = expand("%:p")
if file ==# ""
Expand All @@ -50,9 +50,9 @@ function! ToggleBookmark()
echo "Bookmark added"
endif
endfunction
command! ToggleBookmark call ToggleBookmark()

function! Annotate(...)
command! ToggleBookmark call CallDeprecatedCommand('BookmarkToggle', [])
command! BookmarkToggle call BookmarkToggle()
function! BookmarkAnnotate(...)
call s:refresh_line_numbers()
let file = expand("%:p")
if file ==# ""
Expand Down Expand Up @@ -93,9 +93,10 @@ function! Annotate(...)
echo "Bookmark added with annotation: ". new_annotation
endif
endfunction
command! -nargs=* Annotate call Annotate(<q-args>, 0)
command! -nargs=* Annotate call CallDeprecatedCommand('BookmarkAnnotate', [<q-args>, 0])
command! -nargs=* BookmarkAnnotate call BookmarkAnnotate(<q-args>, 0)

function! ClearBookmarks()
function! BookmarkClear()
call s:refresh_line_numbers()
let file = expand("%:p")
let lines = bm#all_lines(file)
Expand All @@ -104,9 +105,10 @@ function! ClearBookmarks()
endfor
echo "Bookmarks removed"
endfunction
command! ClearBookmarks call ClearBookmarks()
command! ClearBookmarks call CallDeprecatedCommand('BookmarkClear', [])
command! BookmarkClear call BookmarkClear()

function! ClearAllBookmarks(silent)
function! BookmarkClearAll(silent)
call s:refresh_line_numbers()
let files = bm#all_files()
let file_count = len(files)
Expand All @@ -124,21 +126,24 @@ function! ClearAllBookmarks(silent)
endif
endif
endfunction
command! ClearAllBookmarks call ClearAllBookmarks(0)
command! ClearAllBookmarks call CallDeprecatedCommand('BookmarkClearAll', [0])
command! BookmarkClearAll call BookmarkClearAll(0)

function! NextBookmark()
function! BookmarkNext()
call s:refresh_line_numbers()
call s:jump_to_bookmark('next')
endfunction
command! NextBookmark call NextBookmark()
command! NextBookmark call CallDeprecatedCommand('BookmarkNext')
command! BookmarkNext call BookmarkNext()

function! PrevBookmark()
function! BookmarkPrev()
call s:refresh_line_numbers()
call s:jump_to_bookmark('prev')
endfunction
command! PrevBookmark call PrevBookmark()
command! PrevBookmark call CallDeprecatedCommand('BookmarkPrev')
command! BookmarkPrev call BookmarkPrev()

function! ShowAllBookmarks()
function! BookmarkShowAll()
call s:refresh_line_numbers()
let oldformat = &errorformat " backup original format
let &errorformat = "%f:%l:%m" " custom format for bookmarks
Expand All @@ -150,19 +155,21 @@ function! ShowAllBookmarks()
augroup END
let &errorformat = oldformat " re-apply original format
endfunction
command! ShowAllBookmarks call ShowAllBookmarks()
command! ShowAllBookmarks call CallDeprecatedCommand('BookmarkShowAll')
command! BookmarkShowAll call BookmarkShowAll()

function! SaveBookmarks(target_file, silent)
function! BookmarkSave(target_file, silent)
call s:refresh_line_numbers()
let serialized_bookmarks = bm#serialize()
call writefile(serialized_bookmarks, a:target_file)
if (!a:silent)
echo "All bookmarks saved"
endif
endfunction
command! -nargs=1 SaveBookmarks call SaveBookmarks(<f-args>, 0)
command! -nargs=1 SaveBookmarks call CallDeprecatedCommand('BookmarkSave', [<f-args>, 0])
command! -nargs=1 BookmarkSave call BookmarkSave(<f-args>, 0)

function! LoadBookmarks(target_file, startup, silent)
function! BookmarkLoad(target_file, startup, silent)
let supports_confirm = has("dialog_con") || has("dialog_gui")
let has_bookmarks = bm#total_count() ># 0
let confirmed = 1
Expand Down Expand Up @@ -191,7 +198,14 @@ function! LoadBookmarks(target_file, startup, silent)
endtry
endif
endfunction
command! -nargs=1 LoadBookmarks call LoadBookmarks(<f-args>, 0, 0)
command! -nargs=1 LoadBookmarks call CallDeprecatedCommand('BookmarkLoad', [<f-args>, 0, 0])
command! -nargs=1 BookmarkLoad call BookmarkLoad(<f-args>, 0, 0)

function! CallDeprecatedCommand(fun, args)
echo "Warning: Deprecated command, please use ':". a:fun ."' instead"
let Fn = function(a:fun)
return call(Fn, a:args)
endfunction

" }}}

Expand Down Expand Up @@ -265,7 +279,7 @@ function! s:remove_all_bookmarks()
endfunction

function! s:startup_load_bookmarks(file)
call LoadBookmarks(g:bookmark_auto_save_file, 1, 0)
call BookmarkLoad(g:bookmark_auto_save_file, 1, 0)
call s:add_missing_signs(a:file)
endfunction

Expand Down Expand Up @@ -297,7 +311,7 @@ function! s:set_up_auto_save(file)
call s:startup_load_bookmarks(a:file)
augroup bm_auto_save
autocmd!
autocmd VimLeave * call SaveBookmarks(g:bookmark_auto_save_file, 0)
autocmd VimLeave * call BookmarkSave(g:bookmark_auto_save_file, 0)
autocmd BufWinEnter * call s:add_missing_signs(expand('<afile>:p'))
augroup END
endif
Expand All @@ -315,12 +329,12 @@ function! s:register_mapping(command, shortcut)
endif
endfunction

call s:register_mapping('ShowAllBookmarks', 'ma')
call s:register_mapping('ToggleBookmark', 'mm')
call s:register_mapping('Annotate', 'mi')
call s:register_mapping('NextBookmark', 'mn')
call s:register_mapping('PrevBookmark', 'mp')
call s:register_mapping('ClearBookmarks', 'mc')
call s:register_mapping('ClearAllBookmarks', 'mx')
call s:register_mapping('BookmarkShowAll', 'ma')
call s:register_mapping('BookmarkToggle', 'mm')
call s:register_mapping('BookmarkAnnotate', 'mi')
call s:register_mapping('BookmarkNext', 'mn')
call s:register_mapping('BookmarkPrev', 'mp')
call s:register_mapping('BookmarkClear', 'mc')
call s:register_mapping('BookmarkClearAll', 'mx')

" }}}

0 comments on commit 2eb9c77

Please sign in to comment.