Skip to content

Commit 5a37961

Browse files
dfishburnvim-scripts
authored andcommitted
Version 11.0
NF: Documented the global variables to customize the location of the YankRing menu. NF: The YankRing menu now shows the maps used for the default actions to help learn them more easily. NF: Added g:yankring_menu_root and g:yankring_menu_priority (David Barsam). NF: Added a warning indicating a stored value has been truncated based on g:yankring_max_element_length and a new option to suppress this warning, g:yankring_warn_on_truncate (Hans-Günter). BF: The YRAfterMaps() function (if it exists) was not re-run if YRToggle was used to disable and enable the YankRing. BF: Multibyte strings may not have been pasted correctly (Dr. Chip). BF: When pasting a string of 1111's, and additional -1 could also be included in the output.
1 parent d3aa600 commit 5a37961

File tree

2 files changed

+134
-41
lines changed

2 files changed

+134
-41
lines changed

doc/yankring.txt

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
*yankring.txt* For Vim version 7.0.
22

33
Author: David Fishburn August 29, 2009
4-
Version: 10.0
4+
Version: 11.0
55

66
For instructions on installing this file, type
77
:help add-local-help |add-local-help| inside Vim.
88

9+
Homepage: http://vim.sourceforge.net/script.php?script_id=1234
10+
911

1012
==============================================================================
1113
1. Contents *yankring* *yankring-contents*
@@ -16,6 +18,7 @@ For instructions on installing this file, type
1618
3.1 Global Variables...................: |yankring-globals|
1719
3.2 Default Keys.......................: |yankring-mappings|
1820
3.3 Customizing Maps...................: |yankring-custom-maps|
21+
3.4 Customizing Menus..................: |yankring-custom-menus|
1922
4. Using the YankRing Window..............: |yankring-window|
2023
5. Commands...............................: |yankring-commands|
2124
5.1 YRToggle..........................: |YRToggle|
@@ -46,6 +49,7 @@ For instructions on installing this file, type
4649
6.12 YRSearch..........................: |YRSearch-example|
4750
7. History................................: |yankring-history|
4851

52+
4953
==============================================================================
5054
2. Description *yankring-description*
5155

@@ -78,6 +82,7 @@ always welcome.
7882

7983
For details on the changes between versions see |yankring-history|.
8084

85+
8186
==============================================================================
8287
3. Configuration *yankring-configure*
8388

@@ -269,6 +274,33 @@ your |.vimrc|.
269274
no way to noticing. To disable this feature you can put the following
270275
in your |vimrc| >
271276
let g:yankring_paste_check_default_buffer = 0
277+
yankring_default_menu_mode
278+
< - Menus are useful for a number of reasons:
279+
See a list of available commands.
280+
Remember what the shortcut maps are.
281+
Have a floating menu when using the plugin a lot.
282+
Quick reference guide.
283+
There are four settings that will control the placement
284+
of the menu:
285+
"0": Turns the menu off.
286+
"1": Turns the 'Yankring' menu on with no menu shortcut.
287+
"2": Turns the 'Yankring 'menu on with <alt>-y as the shortcut.
288+
"3": Turns the 'Plugin -> YankRing' menu on with <alt>-y as
289+
the shortcut.
290+
This option defaults to a value of 3 and can be changed
291+
by adding the following to your vimrc: >
292+
:let g:yankring_default_menu_mode = 3
293+
yankring_menu_root
294+
< - Can be used in conjuction with g:yankring_default_menu_mode = 3 but
295+
it also allows you to control the fullname and location of the
296+
YankRing menu. To create the menu: 'MyPlugins -> YankRing' you
297+
can create the following variable: >
298+
:let g:yankring_menu_root = 'MyPlugin.&YankRing'
299+
yankring_menu_priority
300+
< - Menus are created in a documented order by Vim (|menu-priority|).
301+
This option allows you to override the setting and shift the
302+
YankRing menu item to the left between the Edit and Tools menu. >
303+
:let g:yankring_menu_priority = 30
272304
273305
<
274306
3.2 Default Keys *yankring-mappings*
@@ -466,6 +498,15 @@ You can do anything you need in this function. >
466498
This line remaps Y (which the user presses) to the YRYankCount command. The
467499
YRYankCount tells Vim to execute y$ instead.
468500

501+
3.4 Customizing Menus *yankring-custom-menus*
502+
503+
There are several global variables which can be created in your vimrc to
504+
allow you to customize where and what is displayed for the YankRing menu.
505+
Simply look up the following global variables: >
506+
yankring_default_menu_mode
507+
yankring_menu_root
508+
yankring_menu_priority
509+
469510
470511
==============================================================================
471512
4. Using the YankRing Window: *yankring-window*
@@ -526,8 +567,6 @@ in the YankRing window.
526567
g:yankring_window_increment setting.
527568
? Toggles the display of the help.
528569

529-
530-
531570

532571
==============================================================================
533572
5. Commands: *yankring-commands*
@@ -1131,6 +1170,22 @@ mapping: >
11311170
==============================================================================
11321171
7. History *yankring-history*
11331172

1173+
11.0: August 09, 2010
1174+
NF: Documented the global variables to customize the location
1175+
of the YankRing menu.
1176+
NF: The YankRing menu now shows the maps used for the default
1177+
actions to help learn them more easily.
1178+
NF: Added g:yankring_menu_root and g:yankring_menu_priority
1179+
(David Barsam).
1180+
NF: Added a warning indicating a stored value has been truncated
1181+
based on g:yankring_max_element_length and a new option to
1182+
suppress this warning, g:yankring_warn_on_truncate (Hans-Günter).
1183+
BF: The YRAfterMaps() function (if it exists) was not re-run if
1184+
YRToggle was used to disable and enable the YankRing.
1185+
BF: Multibyte strings may not have been pasted correctly (Dr. Chip).
1186+
BF: When pasting a string of 1111's, and additional -1 could also
1187+
be included in the output.
1188+
11341189
10.0: January 31, 2010
11351190
NF: Change the buffer name to [YankRing] to resemble other
11361191
non-user buffers.

plugin/yankring.vim

Lines changed: 76 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
" yankring.vim - Yank / Delete Ring for Vim
22
" ---------------------------------------------------------------
3-
" Version: 10.0
3+
" Version: 11.0
44
" Authors: David Fishburn <[email protected]>
5-
" Last Modified: 2010 Jan 24
5+
" Last Modified: 2010 Aug 09
66
" Script: http://www.vim.org/scripts/script.php?script_id=1234
77
" Based On: Mocked up version by Yegappan Lakshmanan
88
" http://groups.yahoo.com/group/vim/post?act=reply&messageNum=34406
@@ -18,7 +18,7 @@ if v:version < 700
1818
finish
1919
endif
2020

21-
let loaded_yankring = 100
21+
let loaded_yankring = 110
2222

2323
let s:yr_has_voperator = 0
2424
if v:version > 701 || ( v:version == 701 && has("patch205") )
@@ -52,6 +52,11 @@ if !exists('g:yankring_max_element_length')
5252
let g:yankring_max_element_length = 1048576
5353
endif
5454

55+
" Warn if truncation occurs
56+
if !exists('g:yankring_warn_on_truncate')
57+
let g:yankring_warn_on_truncate = 1
58+
endif
59+
5560
" Allow the user to specify if the plugin is enabled or not
5661
if !exists('g:yankring_enabled')
5762
let g:yankring_enabled = 1
@@ -632,7 +637,7 @@ endfunction
632637

633638
" Resets the common script variables for managing the ring.
634639
function! s:YRReset()
635-
let s:yr_history_list = []
640+
call s:YRHistoryDelete()
636641
" Update the history file
637642
call s:YRHistorySave()
638643
endfunction
@@ -1549,6 +1554,11 @@ function! s:YRMapsCreate(...)
15491554

15501555
let g:yankring_enabled = 1
15511556
let s:yr_maps_created = 1
1557+
1558+
if exists('*YRRunAfterMaps')
1559+
" This will allow you to override the default maps if necessary
1560+
call YRRunAfterMaps()
1561+
endif
15521562
endfunction
15531563

15541564

@@ -1638,38 +1648,31 @@ function! s:YRMapsDelete(...)
16381648
endfunction
16391649

16401650
function! s:YRGetValElemNbr( position, type )
1641-
16421651
let needed_elem = a:position
16431652

16441653
" The List which contains the items in the yankring
16451654
" history is also ordered, most recent at the top
16461655
let elem = s:YRMRUGet('s:yr_history_list', needed_elem)
16471656

1648-
if elem >= 0
1649-
if a:type == 't'
1650-
return matchstr(elem, '^.*,\zs.*$')
1657+
if a:type == 't'
1658+
let elem = matchstr(elem, '^.*,\zs.*$')
1659+
else
1660+
let elem = matchstr(elem, '^.*\ze,.*$')
1661+
if s:yr_history_version == 'v1'
1662+
" Match three @@@ in a row as long as it is not
1663+
" preceeded by a @@@
1664+
" v1
1665+
let elem = substitute(elem, s:yr_history_v1_nl_pat, "\n", 'g')
1666+
let elem = substitute(elem, '\\@', '@', 'g')
16511667
else
1652-
let elem = matchstr(elem, '^.*\ze,.*$')
1653-
if s:yr_history_version == 'v1'
1654-
" Match three @@@ in a row as long as it is not
1655-
" preceeded by a @@@
1656-
" v1
1657-
let elem = substitute(elem, s:yr_history_v1_nl_pat, "\n", 'g')
1658-
let elem = substitute(elem, '\\@', '@', 'g')
1659-
else
1660-
let elem = substitute(elem, s:yr_history_v2_nl_pat, "\n", 'g')
1661-
endif
1662-
return elem
1668+
let elem = substitute(elem, s:yr_history_v2_nl_pat, "\n", 'g')
16631669
endif
1664-
else
1665-
return -1
16661670
endif
16671671

1668-
return ""
1672+
return elem
16691673
endfunction
16701674

16711675
function! s:YRMRUReset( mru_list )
1672-
16731676
let {a:mru_list} = []
16741677

16751678
return 1
@@ -1683,6 +1686,16 @@ function! s:YRMRUElemFormat( element, element_type )
16831686
let elem = a:element
16841687
if g:yankring_max_element_length != 0
16851688
let elem = strpart(a:element, 0, g:yankring_max_element_length)
1689+
if (g:yankring_warn_on_truncate > 0)
1690+
let bytes = len (a:element) - len(elem)
1691+
if (bytes > 0)
1692+
call s:YRWarningMsg("Yankring truncated its element by ".
1693+
\ bytes.
1694+
\ " bytes due to a g:yankring_max_element_length of ".
1695+
\ g:yankring_max_element_length
1696+
\ )
1697+
endif
1698+
endif
16861699
endif
16871700
if s:yr_history_version == 'v1'
16881701
let elem = escape(elem, '@')
@@ -1754,7 +1767,6 @@ function! s:YRMRUAdd( mru_list, element, element_type )
17541767
endfunction
17551768

17561769
function! s:YRMRUDel( mru_list, elem_nbr )
1757-
17581770
if a:elem_nbr >= 0 && a:elem_nbr < s:yr_count
17591771
call remove({a:mru_list}, a:elem_nbr)
17601772
call s:YRHistorySave()
@@ -1763,6 +1775,23 @@ function! s:YRMRUDel( mru_list, elem_nbr )
17631775
return 1
17641776
endfunction
17651777

1778+
function! s:YRHistoryDelete()
1779+
let s:yr_history_list = []
1780+
let yr_filename = s:yr_history_file_{s:yr_history_version}
1781+
1782+
if filereadable(yr_filename)
1783+
let rc = delete(yr_filename)
1784+
if rc != 0
1785+
call s:YRErrorMsg(
1786+
\ 'YRHistoryDelete: Unable to delete the yankring history file: '.
1787+
\ yr_filename
1788+
\ )
1789+
endif
1790+
endif
1791+
1792+
return 0
1793+
endfunction
1794+
17661795
function! s:YRHistoryRead()
17671796
let refresh_needed = 1
17681797
let yr_history_list = []
@@ -1801,20 +1830,22 @@ function! s:YRHistoryRead()
18011830
endfunction
18021831

18031832
function! s:YRHistorySave()
1833+
let yr_filename = s:yr_history_file_{s:yr_history_version}
1834+
18041835
if len(s:yr_history_list) > g:yankring_max_history
18051836
" Remove items which exceed the max # specified
18061837
call remove(s:yr_history_list, g:yankring_max_history)
18071838
endif
18081839

1809-
let rc = writefile(s:yr_history_list, s:yr_history_file_{s:yr_history_version})
1840+
let rc = writefile(s:yr_history_list, yr_filename)
18101841

18111842
if rc == 0
1812-
let s:yr_history_last_upd = getftime(s:yr_history_file_{s:yr_history_version})
1843+
let s:yr_history_last_upd = getftime(yr_filename)
18131844
let s:yr_count = len(s:yr_history_list)
18141845
else
18151846
call s:YRErrorMsg(
18161847
\ 'YRHistorySave: Unable to save yankring history file: '.
1817-
\ s:yr_history_file_{s:yr_history_version}
1848+
\ yr_filename
18181849
\ )
18191850
endif
18201851
endfunction
@@ -2431,30 +2462,37 @@ command! -range -bang -nargs=? YRYankRange <line1>,<line2>call s:YRYankRa
24312462
if has("gui_running") && has("menu") && g:yankring_default_menu_mode != 0
24322463
if g:yankring_default_menu_mode == 1
24332464
let menuRoot = 'YankRing'
2465+
let menuPriority = ''
24342466
elseif g:yankring_default_menu_mode == 2
24352467
let menuRoot = '&YankRing'
2468+
let menuPriority = ''
2469+
elseif g:yankring_default_menu_mode == 3
2470+
let menuRoot = exists("g:yankring_menu_root") ? g:yankring_menu_root : '&Plugin.&YankRing'
2471+
let menuPriority = exists("g:yankring_menu_priority") ? yankring_menu_priority : ''
24362472
else
24372473
let menuRoot = '&Plugin.&YankRing'
2474+
let menuPriority = ''
24382475
endif
24392476

2440-
exec 'noremenu <script> '.menuRoot.'.YankRing\ Window :YRShow<CR>'
2441-
exec 'noremenu <script> '.menuRoot.'.YankRing\ Search :YRSearch<CR>'
2442-
exec 'noremenu <script> '.menuRoot.'.Replace\ with\ Previous :YRReplace ''-1'', ''P''<CR>'
2443-
exec 'noremenu <script> '.menuRoot.'.Replace\ with\ Next :YRReplace ''1'', ''P''<CR>'
2444-
exec 'noremenu <script> '.menuRoot.'.Clear :YRClear<CR>'
2445-
exec 'noremenu <script> '.menuRoot.'.Toggle :YRToggle<CR>'
2477+
let leader = '\'
2478+
if exists('g:mapleader')
2479+
let leader = g:mapleader
2480+
endif
2481+
let leader = escape(leader, '\')
2482+
2483+
exec 'noremenu <script> '.menuPriority.' '.menuRoot.'.YankRing\ Window :YRShow<CR>'
2484+
exec 'noremenu <script> '.menuPriority.' '.menuRoot.'.YankRing\ Search :YRSearch<CR>'
2485+
exec 'noremenu <script> '.menuPriority.' '.menuRoot.'.Replace\ with\ Previous<TAB>'.leader.'<C-P> :YRReplace ''-1'', ''P''<CR>'
2486+
exec 'noremenu <script> '.menuPriority.' '.menuRoot.'.Replace\ with\ Next<TAB>'.leader.'<C-N> :YRReplace ''1'', ''P''<CR>'
2487+
exec 'noremenu <script> '.menuPriority.' '.menuRoot.'.Clear :YRClear<CR>'
2488+
exec 'noremenu <script> '.menuPriority.' '.menuRoot.'.Toggle :YRToggle<CR>'
24462489
endif
24472490

24482491
if g:yankring_enabled == 1
24492492
" Create YankRing Maps
24502493
call s:YRMapsCreate()
24512494
endif
24522495

2453-
if exists('*YRRunAfterMaps')
2454-
" This will allow you to override the default maps if necessary
2455-
call YRRunAfterMaps()
2456-
endif
2457-
24582496
call s:YRInit()
24592497
call s:YRHistoryRead()
24602498

0 commit comments

Comments
 (0)