@@ -37,10 +37,6 @@ if !exists('g:quickmenu_options')
37
37
let g: quickmenu_options = ' '
38
38
endif
39
39
40
- if ! exists (' g:quickmenu_special_keys' )
41
- let g: quickmenu_special_keys = 1
42
- endif
43
-
44
40
" ----------------------------------------------------------------------
45
41
" Internal State
46
42
" ----------------------------------------------------------------------
@@ -53,20 +49,6 @@ let s:quickmenu_name = '[quickmenu]'
53
49
let s: quickmenu_line = 0
54
50
let s: quickmenu_custom_keys = {}
55
51
56
- function ! s: reset_key_map ()
57
- let s: quickmenu_custom_keys = {}
58
- if g: quickmenu_special_keys == 1
59
- " Prevent user to bind special keys
60
- let s: quickmenu_custom_keys [' g' ]= 1
61
- let s: quickmenu_custom_keys [' G' ]= 1
62
- let s: quickmenu_custom_keys [' j' ]= 1
63
- let s: quickmenu_custom_keys [' k' ]= 1
64
- let s: quickmenu_custom_keys [' q' ]= 1
65
- endif
66
- endfunction
67
-
68
- call s: reset_key_map ()
69
-
70
52
" ----------------------------------------------------------------------
71
53
" popup window management
72
54
" ----------------------------------------------------------------------
@@ -143,29 +125,28 @@ function! quickmenu#reset()
143
125
let s: quickmenu_items [s: quickmenu_mid ] = []
144
126
let s: quickmenu_line = 0
145
127
let s: quickmenu_cursor [s: quickmenu_mid ] = 0
146
- call s: reset_key_map ()
147
128
endfunc
148
129
149
130
function ! quickmenu#append (text, event , ... )
150
131
let help = (a: 0 >= 1 )? a: 1 : ' '
151
132
let filetype = (a: 0 >= 2 )? a: 2 : ' '
152
133
let weight = (a: 0 >= 3 )? a: 3 : 0
153
134
let item = {}
154
- let item.key = ' '
155
- if a: 0 >= 4
156
- if has_key (s: quickmenu_custom_keys , a: 4 )
157
- call s: errmsg (" Quickmenu: Found duplicate binding for key " .a: 4 )
158
- else
159
- let item.key = a: 4
160
- let s: quickmenu_custom_keys [a: 4 ]= 1
161
- endif
162
- endif
135
+
163
136
let item.mode = 0
164
137
let item.event = a: event
165
138
let item.text = a: text
166
- let item.ft = []
139
+
140
+ let item.key = ' '
141
+ if a: 0 >= 4
142
+ let item.key = a: 4
143
+ " all used keys for this panel
144
+ let s: quickmenu_custom_keys [a: 4 ]= 1
145
+ endif
146
+
167
147
let item.weight = weight
168
148
let item.help = help
149
+
169
150
if a: event != ' '
170
151
let item.mode = 0
171
152
elseif a: text [0 ] != ' #'
@@ -174,9 +155,12 @@ function! quickmenu#append(text, event, ...)
174
155
let item.mode = 2
175
156
let item.text = matchstr (a: text , ' ^#\+\s*\zs.*' )
176
157
endif
158
+
159
+ let item.ft = []
177
160
for ft in split (filetype , ' ,' )
178
161
let item.ft += [substitute (ft , ' ^\s*\(.\{-}\)\s*$' , ' \1' , ' ' )]
179
162
endfor
163
+
180
164
let index = -1
181
165
if ! has_key (s: quickmenu_items , s: quickmenu_mid )
182
166
let s: quickmenu_items [s: quickmenu_mid ] = []
@@ -199,7 +183,6 @@ endfunc
199
183
200
184
function ! quickmenu#current (mid)
201
185
let s: quickmenu_mid = a: mid
202
- call s: reset_key_map ()
203
186
endfunc
204
187
205
188
@@ -378,7 +361,7 @@ function! s:set_cursor() abort
378
361
let find = select - 2
379
362
endif
380
363
if find < 0
381
- call s: errmsg ( " fatal error in set_cursor() " .find )
364
+ call s: start_error_message ( " Quickmenu: fatal error in set_cursor() " .find )
382
365
return
383
366
endif
384
367
let s: quickmenu_line = find + 2
@@ -453,6 +436,7 @@ endfunc
453
436
" select items by &ft, generate keymap and add some default items
454
437
" ----------------------------------------------------------------------
455
438
function ! s: select_by_ft (mid, ft ) abort
439
+ let duplicate_key_check = {}
456
440
let hint = ' 123456789abcdefhilmnoprstuvwxyzACDIOPQRSUX*'
457
441
" let hint = '12abcdefhlmnoprstuvwxyz*'
458
442
let items = []
@@ -478,9 +462,14 @@ function! s:select_by_ft(mid, ft) abort
478
462
let lastmode = item.mode
479
463
" allocate key for non-filetype specific items
480
464
if item.mode == 0 && len (item.ft ) == 0
465
+ " discard already used mapping
466
+ if has_key (duplicate_key_check, item.key )
467
+ call s: run_error_message (" Quickmenu: duplicate mapping for " .item.key )
468
+ let item.key = ' '
469
+ endif
481
470
if item.key == ' '
482
- " Avdoid to remap existing key
483
- while has_key (s: quickmenu_custom_keys , hint[index ]) && index < strlen (hint)-1
471
+ " Avdoid to remap already used mapping
472
+ while has_key (duplicate_key_check , hint[index ]) && index < strlen (hint)-1
484
473
let index += 1
485
474
endwhile
486
475
let item.key = hint[index ]
@@ -489,6 +478,7 @@ function! s:select_by_ft(mid, ft) abort
489
478
let index = strlen (hint) - 1
490
479
endif
491
480
endif
481
+ let duplicate_key_check[item.key ] = 1
492
482
endif
493
483
let items += [item]
494
484
if item.mode == 2
@@ -500,9 +490,14 @@ function! s:select_by_ft(mid, ft) abort
500
490
" allocate key for filetype specific items
501
491
for item in items
502
492
if item.mode == 0 && len (item.ft ) > 0
493
+ " discard already used mapping
494
+ if has_key (duplicate_key_check, item.key )
495
+ call s: run_error_message (" Quickmenu: duplicate mapping for " .item.key )
496
+ let item.key = ' '
497
+ endif
503
498
if item.key == ' '
504
- " Avdoid to remap existing key
505
- while has_key (s: quickmenu_custom_keys , hint[index ]) && index < strlen (hint)-1
499
+ " Avdoid to remap already used mapping
500
+ while has_key (duplicate_key_check , hint[index ]) && index < strlen (hint)-1
506
501
let index += 1
507
502
endwhile
508
503
let item.key = hint[index ]
@@ -511,6 +506,8 @@ function! s:select_by_ft(mid, ft) abort
511
506
let index = strlen (hint) - 1
512
507
endif
513
508
endif
509
+ " keep all used keys
510
+ let duplicate_key_check[item.key ] = 1
514
511
endif
515
512
endfor
516
513
if len (items )
@@ -663,12 +660,16 @@ endfunc
663
660
" ----------------------------------------------------------------------
664
661
" echo a error msg
665
662
" ----------------------------------------------------------------------
666
- function ! s: errmsg (msg)
663
+ function ! s: start_error_message (msg)
667
664
echohl ErrorMsg
668
665
echo a: msg
669
666
echohl None
670
667
endfunc
671
668
669
+ function ! s: run_error_message (msg)
670
+ echom a: msg
671
+ endfunc
672
+
672
673
673
674
" ----------------------------------------------------------------------
674
675
" echo highlight
0 commit comments