/
menu.vim
3017 lines (2723 loc) · 88.1 KB
/
menu.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"source $HOME/.vim/forms.vim
" ============================================================================
" menu.vim
"
" File: menu.vim
" Summary: Vim Menu and Popup using Form Library
" Author: Richard Emberson <richard.n.embersonATgmailDOTcom>
" Last Modified: 06/30/2012
" Version: 1.0
" Modifications:
" 1.0 : initial public release.
"
" Tested on vim 7.3 on Linux
"
" Depends upon: self.vim forms.vim
"
" ============================================================================
" Intro: {{{1
" This code is basically a demonstration of the capabilities of the Forms
" library. GVim has both a menubar and a popup menu. This code uses
" the Forms library to recreate them or, at least, the vast majority
" of their capabilities. Certainly, the GUI menus look better than
" text-base menus. But, what the heck, the Forms library is for building
" TUIs (Text User Interfaces) not GUIs.
" It is also true, that the act of generating the TUI menus uncovered
" weaknesses and additional requirements for the Forms library ... which
" is a good thing.
" The source for the Vim GUI menus are found in $VIM_RUNTIME/menu.vim
" Some of the supporting Vim script in that file is reproduced and
" used here ... Steal the best, code the rest.
" ============================================================================
" Load Once: {{{1
if &cp || ( exists("g:loaded_menu") && ! g:self#IN_DEVELOPMENT_MODE )
finish
endif
let g:loaded_menu = 'v1.0'
let s:keepcpo = &cpo
set cpo&vim
"-------------------------------------------------------------------------------
" Configuration Options: {{{1
" These help control of the menu library.
"-------------------------------------------------------------------------------
" Maps for Menu and PopUp
" Users can define their own mappings and, of course, then
" define g:menu_map_keys
if !exists("g:menu_map_keys")
nmap <Leader>m :call forms#menu#MakeMenu('n')<CR>
vmap <Leader>m :call forms#menu#MakeMenu('v')<CR>
nmap <Leader>p :call forms#menu#MakePopUp('n')<CR>
vmap <Leader>p :call forms#menu#MakePopUp('v')<CR>
let g:menu_map_keys = 1
endif
"-------------------------------------------------------------------------------
"-------------------------------------------------------------------------------
" Support Forms: {{{1
"-------------------------------------------------------------------------------
"-------------------------------------------------------------------------------
" ------------------------------------------------------------
" s:FnameEscape: {{{2
" Escape string for use as file name
" parameters:
" fname : file name to be escaped
" ------------------------------------------------------------
function! s:FnameEscape(fname)
if exists('*fnameescape')
return fnameescape(a:fname)
endif
return escape(a:fname, " \t\n*?[{`$\\%#'\"|!<")
endfunc
"---------------------------------------------------------------------------
" HelpFind: {{{2
" Presentation:
" Lauches forms#dialog#input#Make
" Executes ":help input"
" Parameters: NONE
"---------------------------------------------------------------------------
function! g:HelpFind()
"call forms#log("HelpFind")
let help_lines = [
\ "Enter a command or word to find help on:",
\ "",
\ "Prepend i_ for Input mode commands (e.g.: i_CTRL-X)",
\ "Prepend c_ for command-line editing commands (e.g.: c_<Del>)",
\ "Prepend ' for an option name (e.g.: 'shiftwidth')"
\ ]
let h = forms#dialog#input#Make(help_lines)
if h != ""
let v:errmsg = ""
silent! execute "help " . h
if v:errmsg != ""
echo v:errmsg
endif
endif
endfunction
"-------------------------------------------------------------------------------
"-------------------------------------------------------------------------------
" Menus: {{{1
"-------------------------------------------------------------------------------
"-------------------------------------------------------------------------------
"-------------------------------------------------------------------------------
" File Menu: {{{2
"-------------------------------------------------------------------------------
if exists("s:fileMenu")
unlet s:fileMenu
endif
"---------------------------------------------------------------------------
" forms#menu#MakeFileMenu: {{{3
" Create File menu
" Example:
" Open... :e
" Split-Open... :sp
" Open Tab... :tabnew
" New :enew
" Close :close
" ──────────────────────
" Save :w
" Save As... :sav
" ──────────────────────
" Split Diff with...
" Split Patched By...
" ──────────────────────
" Print :hardcopy
" Save-Exit :wqa
" Exit :qa
"
" parameters: None
"---------------------------------------------------------------------------
function! forms#menu#MakeFileMenu()
" call forms#log("forms#menu#MakeFileMenu TOP")
function! BrowserAction(title, cmd)
let dict = { 'title' : a:title }
let f = forms#dialog#filebrowser#Make(dict)
call forms#log("forms#menu#MakeFileMenu.BrowserAction f=".f)
if f != ''
let f = substitute(f, ' ', '\\ ', "g")
execute ':'.a:cmd.f
endif
endfunction
if ! exists("s:fileMenu")
let items = []
call add(items, {
\ 'type': 'button',
\ 'label': '&Open...',
\ 'hint': ':e',
\ 'command': ":call BrowserAction('Edit File', 'e')"
\ })
call add(items, {
\ 'type': 'button',
\ 'label': 'Sp&lit-Open...',
\ 'hint': ':sp',
\ 'command': ":call BrowserAction('Edit File in new Window', 'sp')"
\ })
call add(items, {
\ 'type': 'button',
\ 'label': 'Open &Tab...',
\ 'hint': ':tabnew',
\ 'command': ":call BrowserAction('Edit File in new Tab', 'sp')"
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&New',
\ 'hint': ':enew',
\ 'command': ':enew'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&Close',
\ 'hint': ':close',
\ 'command': ":if winheight(2) < 0 | :execute ':enew' | else | :execute ':close' | endif"
\ })
call add(items, {'type': 'separator'})
call add(items, {
\ 'type': 'button',
\ 'label': '&Save',
\ 'hint': ':w',
\ 'command': ":if expand('%') == ''| :call BrowserAction('Save', 'w') | else | :execute ':w' | endif"
\ })
call add(items, {
\ 'type': 'button',
\ 'label': 'Save &As...',
\ 'hint': ':sav',
\ 'command': ":call BrowserAction('Save As', 'saveas')"
\ })
if has("diff")
call add(items, {'type': 'separator'})
call add(items, {
\ 'type': 'button',
\ 'label': 'Split &Diff with...',
\ 'command': ":call BrowserAction('Diff Split', 'vert diffsplit')"
\ })
call add(items, {
\ 'type': 'button',
\ 'label': 'Split Patched &By...',
\ 'command': ":call BrowserAction('Diff Patch', 'vert diffpatch')"
\ })
endif
if has("printer")
call add(items, {'type': 'separator'})
call add(items, {
\ 'type': 'button',
\ 'label': '&Print',
\ 'hint': ':hardcopy',
\ 'command': ':hardcopy'
\ })
elseif has("unix")
call add(items, {'type': 'separator'})
call add(items, {
\ 'type': 'button',
\ 'label': '&Print',
\ 'hint': ':w !lpr',
\ 'command': ':w !lpr'
\ })
else
call add(items, {'type': 'separator'})
endif
call add(items, {
\ 'type': 'button',
\ 'label': 'Sa&ve-Exit',
\ 'hint': ':wqa',
\ 'command': ':wqa'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': 'E&xit',
\ 'hint': ':qa',
\ 'command': ':qa'
\ })
let attrs = { 'items': items }
let s:fileMenu = forms#newMenu(attrs)
endif
return s:fileMenu
endfunction
"-------------------------------------------------------------------------------
" Edit Menu: {{{2
"-------------------------------------------------------------------------------
if exists("s:editMenu")
unlet s:editMenu
endif
"---------------------------------------------------------------------------
" GetSelectedText: {{{3
" Returns visually selected text
" parameters: None
"---------------------------------------------------------------------------
function! GetSelectedText()
if exists("s:firstcol")
let text = ''
let fl =s:firstline
let ll =s:lastline
let fc =s:firstcol
let lc =s:lastcol
if fl == ll
let text = getline(fl)[fc : lc]
else
let text = getline(fl)[fc :]
let cnt = fl+1
while cnt < ll
let text += getline(cnt)
let cnt += 1
endwhile
let text += getline(cnt)[: lc]
endif
return text
else
return ''
endif
endfunction
"---------------------------------------------------------------------------
" forms#menu#MakeEditGlobalSettingsContextMenu: {{{3
" Returns menu
" Example:
" 1 :set so=1
" 2 :set so=2
" 3 :set so=3
" 4 :set so=4
" 5 :set so=5
" 7 :set so=7
" 10 :set so=10
" 100 :set so=100
"
" parameters: None
"---------------------------------------------------------------------------
if g:self#IN_DEVELOPMENT_MODE
if exists("s:editGlobalSettingsContextMenu")
unlet s:editGlobalSettingsContextMenu
endif
endif
function! forms#menu#MakeEditGlobalSettingsContextMenu()
if ! exists("s:editGlobalSettingsContextMenu")
let items = []
call add(items, {
\ 'type': 'button',
\ 'label': '&1',
\ 'hint': ':set so=1',
\ 'command': ':set so=1'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&2',
\ 'hint': ':set so=2',
\ 'command': ':set so=2'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&3',
\ 'hint': ':set so=3',
\ 'command': ':set so=3'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&4',
\ 'hint': ':set so=4',
\ 'command': ':set so=4'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&5',
\ 'hint': ':set so=5',
\ 'command': ':set so=5'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&7',
\ 'hint': ':set so=7',
\ 'command': ':set so=7'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&10',
\ 'hint': ':set so=10',
\ 'command': ':set so=10'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&100',
\ 'hint': ':set so=100',
\ 'command': ':set so=100'
\ })
let attrs = { 'items': items }
let s:editGlobalSettingsContextMenu = forms#newMenu(attrs)
endif
return s:editGlobalSettingsContextMenu
endfunction
"---------------------------------------------------------------------------
" forms#menu#MakeEditGlobalSettingsVEditMenu: {{{3
" Returns menu
" Example:
" Never :set ve=
" Block Selection :set ve=block
" Insert mode :set ve=insert
" Block and Insert :set ve=block,insert
" Always set ve=all
"
" parameters: None
"---------------------------------------------------------------------------
if g:self#IN_DEVELOPMENT_MODE
if exists("s:editGlobalSettingsVEditMenu")
unlet s:editGlobalSettingsVEditMenu
endif
endif
function! forms#menu#MakeEditGlobalSettingsVEditMenu()
if ! exists("s:editGlobalSettingsVEditMenu")
let items = []
call add(items, {
\ 'type': 'button',
\ 'label': '&Never',
\ 'hint': ':set ve=',
\ 'command': ':set ve='
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&Block Selection',
\ 'hint': ':set ve=block',
\ 'command': ':set ve=block'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&Insert mode',
\ 'hint': ':set ve=insert',
\ 'command': ':set ve=insert'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': 'Block &and Insert',
\ 'hint': ':set ve=block,insert',
\ 'command': ':set ve=block,insert'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&Always',
\ 'hint': ':set ve=all',
\ 'command': ':set ve=all'
\ })
let attrs = { 'items': items }
let s:editGlobalSettingsVEditMenu = forms#newMenu(attrs)
endif
return s:editGlobalSettingsVEditMenu
endfunction
"---------------------------------------------------------------------------
" forms#menu#MakeEditGlobalSettingsMenu: {{{3
" Returns menu
" Example:
" Toggle Pattern Highlight :set hls!
" Toggle Ignore-case :set ic!
" Toggle Showmatch :set sm!
" Context lines
" Virtual Edit
" Toggle Insert Mode :set im!
" Toggle Vi Compatible :set cp!
" Search Path...
" Tag Files...
"
" parameters: None
"---------------------------------------------------------------------------
if g:self#IN_DEVELOPMENT_MODE
if exists("s:editGlobalSettingsMenu")
unlet s:editGlobalSettingsMenu
endif
endif
function! forms#menu#MakeEditGlobalSettingsMenu()
if ! exists("s:editGlobalSettingsMenu")
let items = []
" Toggle
call add(items, {
\ 'type': 'button',
\ 'label': 'Toggle Pattern &Highlight',
\ 'hint': ':set hls!',
\ 'command': ':set hls! hls?'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': 'Toggle &Ignore-case',
\ 'hint': ':set ic!',
\ 'command': ':set ic! ic?'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': 'Toggle &Showmatch',
\ 'hint': ':set sm!',
\ 'command': ':set sm! sm?'
\ })
" Context lines ->
let MakeEditGlobalSettingsContextMenuFN = function("forms#menu#MakeEditGlobalSettingsContextMenu")
call add(items, {
\ 'type': 'menu',
\ 'label': '&Context lines',
\ 'menuFN': MakeEditGlobalSettingsContextMenuFN
\ })
" Virtual Edit ->
let MakeEditGlobalSettingsVEditMenuFN = function("forms#menu#MakeEditGlobalSettingsVEditMenu")
call add(items, {
\ 'type': 'menu',
\ 'label': '&Virtual Edit',
\ 'menuFN': MakeEditGlobalSettingsVEditMenuFN
\ })
" Toggle Insert Mode
call add(items, {
\ 'type': 'button',
\ 'label': 'Toggle Insert &Mode',
\ 'hint': ':set im!',
\ 'command': ':set im!'
\ })
" Toggle Vi Compatible
call add(items, {
\ 'type': 'button',
\ 'label': 'Toggle Vi C&ompatible',
\ 'hint': ':set cp!',
\ 'command': ':set cp!'
\ })
" Search Path
function! SearchP()
if !exists("g:menutrans_path_dialog")
let g:menutrans_path_dialog = "Enter search path for files.\nSeparate directory names with a comma."
endif
let n = forms#dialog#input#Make(g:menutrans_path_dialog, substitute(&path, '\\ ', ' ', 'g'))
if n != ""
let &path = substitute(n, ' ', '\\ ', 'g')
endif
endfunction
call add(items, {
\ 'type': 'button',
\ 'label': 'Search &Path...',
\ 'command': ':call SearchP()'
\ })
" Tag Files...
function! TagFiles()
if !exists("g:menutrans_tags_dialog")
let g:menutrans_tags_dialog = "Enter names of tag files.\nSeparate the names with a comma."
endif
let n = forms#dialog#input#Make(g:menutrans_tags_dialog, substitute(&tags, '\\ ', ' ', 'g'))
if n != ""
let &tags = substitute(n, ' ', '\\ ', 'g')
endif
endfunction
call add(items, {
\ 'type': 'button',
\ 'label': 'Ta&g Files...',
\ 'command': ':call TagFiles()'
\ })
" Not supported yet
" Toggle Toolbar
" Toggle Bottom Scrollbar
" Toggle Left Scrollbar
" Toggle Right Scrollbar
let attrs = { 'items': items }
let s:editGlobalSettingsMenu = forms#newMenu(attrs)
endif
return s:editGlobalSettingsMenu
endfunction
"---------------------------------------------------------------------------
" forms#menu#MakeEditFileSettingsShiftwidthMenu: {{{3
" Returns menu
" Example:
" 2 :set sw=2
" 3 :set sw=3
" 4 :set sw=4
" 5 :set sw=5
" 6 :set sw=6
" 8 :set sw=8
"
" parameters: None
"---------------------------------------------------------------------------
if g:self#IN_DEVELOPMENT_MODE
if exists("s:editFileSettingsShiftwidthMenu")
unlet s:editFileSettingsShiftwidthMenu
endif
endif
function! forms#menu#MakeEditFileSettingsShiftwidthMenu()
if ! exists("s:editFileSettingsShiftwidthMenu")
let items = []
" Toggle
call add(items, {
\ 'type': 'button',
\ 'label': '&2',
\ 'hint': ':set sw=2',
\ 'command': ':set sw=2 sw?'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&3',
\ 'hint': ':set sw=3',
\ 'command': ':set sw=3 sw?'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&4',
\ 'hint': ':set sw=4',
\ 'command': ':set sw=4 sw?'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&5',
\ 'hint': ':set sw=5',
\ 'command': ':set sw=5 sw?'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&6',
\ 'hint': ':set sw=6',
\ 'command': ':set sw=6 sw?'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&8',
\ 'hint': ':set sw=8',
\ 'command': ':set sw=8 sw?'
\ })
let attrs = { 'items': items }
let s:editFileSettingsShiftwidthMenu = forms#newMenu(attrs)
endif
return s:editFileSettingsShiftwidthMenu
endfunction
"---------------------------------------------------------------------------
" forms#menu#MakeEditFileSettingsSoftTabstopMenu: {{{3
" Returns menu
" Example:
" 2 :set sts=2
" 3 :set sts=3
" 4 :set sts=4
" 5 :set sts=5
" 6 :set sts=6
" 8 :set sts=8
"
" parameters: None
"---------------------------------------------------------------------------
if g:self#IN_DEVELOPMENT_MODE
if exists("s:editFileSettingsSoftTabstopMenu")
unlet s:editFileSettingsSoftTabstopMenu
endif
endif
function! forms#menu#MakeEditFileSettingsSoftTabstopMenu()
if ! exists("s:editFileSettingsSoftTabstopMenu")
let items = []
" Toggle
call add(items, {
\ 'type': 'button',
\ 'label': '&2',
\ 'hint': 'set sts=2',
\ 'command': ':set sts=2 sts?'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&3',
\ 'hint': 'set sts=3',
\ 'command': ':set sts=3 sts?'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&4',
\ 'hint': ':set sts=4',
\ 'command': ':set sts=4 sts?'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&5',
\ 'hint': ':set sts=5',
\ 'command': ':set sts=5 sts?'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&6',
\ 'hint': ':set sts=6',
\ 'command': ':set sts=6 sts?'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': '&8',
\ 'hint': ':set sts=8',
\ 'command': ':set sts=8 sts?'
\ })
let attrs = { 'items': items }
let s:editFileSettingsSoftTabstopMenu = forms#newMenu(attrs)
endif
return s:editFileSettingsSoftTabstopMenu
endfunction
"---------------------------------------------------------------------------
" forms#menu#MakeEditFileSettingsMenu: {{{3
" Returns menu
" Example:
" Toggle relative Lint Numbering :set rnu!
" Toggle Line Numbering :set nu!
" Toggle List Mode :set list!
" Toggle Line Wrap :set wrap!
" Toggle Wrap at word :set lbr!
" Toggle expand-tab :set et!
" Toggle auto-indent :set ai!
" Toggle C-indenting :set cin!
" ──────────────────────────────────────────
" Shiftwidth
" Soft Tabstop
" Text Width...
" File Format...
"
" parameters: None
"---------------------------------------------------------------------------
if g:self#IN_DEVELOPMENT_MODE
if exists("s:editFileSettingsMenu")
unlet s:editFileSettingsMenu
endif
endif
function! forms#menu#MakeEditFileSettingsMenu()
if ! exists("s:editFileSettingsMenu")
let items = []
" Toggle
call add(items, {
\ 'type': 'button',
\ 'label': 'Toggle relati&ve Lint Numbering',
\ 'hint': ':set rnu!',
\ 'command': ':set nu! nu?'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': 'Toggle Line &Numbering',
\ 'hint': ':set nu!',
\ 'command': ':set rnu! rnu?'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': 'Toggle &List Mode',
\ 'hint': ':set list!',
\ 'command': ':set list! list?'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': 'Toggle Line &Wrap',
\ 'hini': ':set wrap!',
\ 'command': ':set wrap! wrap?'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': 'Toggle W&rap at word',
\ 'hint': ':set lbr!',
\ 'command': ':set lbr! lbr?'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': 'Toggle &expand-tab',
\ 'hint': ':set et!',
\ 'command': ':set et! et?'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': 'Toggle &auto-indent',
\ 'hint': ':set ai!',
\ 'command': ':set ai! ai?'
\ })
call add(items, {
\ 'type': 'button',
\ 'label': 'Toggle &C-indenting',
\ 'hint': ':set cin!',
\ 'command': ':set cin! cin?'
\ })
call add(items, { 'type': 'separator' })
let MakeEditFileSettingsShiftwidthMenuFN = function("forms#menu#MakeEditFileSettingsShiftwidthMenu")
call add(items, {
\ 'type': 'menu',
\ 'label': '&Shiftwidth',
\ 'menuFN': MakeEditFileSettingsShiftwidthMenuFN
\ })
let MakeEditFileSettingsSoftTabstopMenuFN = function("forms#menu#MakeEditFileSettingsSoftTabstopMenu")
call add(items, {
\ 'type': 'menu',
\ 'label': 'Soft &Tabstop',
\ 'menuFN': MakeEditFileSettingsSoftTabstopMenuFN
\ })
function! TextWidth()
if !exists("g:menutrans_textwidth_dialog")
let g:menutrans_textwidth_dialog = "Enter new text width (0 to disable formatting): "
endif
let n = forms#dialog#input#Make(g:menutrans_textwidth_dialog, &tw)
if n != ""
" remove leading zeros to avoid it being used as an octal number
let &tw = substitute(n, "^0*", "", "")
endif
endfunction
call add(items, {
\ 'type': 'button',
\ 'label': 'Te&xt Width...',
\ 'command': ':call TextWidth()'
\ })
function! FileFormat()
if !exists("g:menutrans_fileformat_dialog")
let g:menutrans_fileformat_dialog = "Select format for writing the file"
endif
if !exists("g:menutrans_fileformat_choices")
let g:menutrans_fileformat_choices = "Unix\nDos\nMac"
endif
if &ff == "dos"
let def = 2
elseif &ff == "mac"
let def = 3
else
let def = 1
endif
let n = forms#dialog#confirm#Make(g:menutrans_fileformat_dialog, g:menutrans_fileformat_choices, def)
if n == 1
set ff=unix
elseif n == 2
set ff=dos
elseif n == 3
set ff=mac
endif
endfunction
call add(items, {
\ 'type': 'button',
\ 'label': '&File Format...',
\ 'command': ':call FileFormat()'
\ })
let attrs = { 'items': items }
let s:editFileSettingsMenu = forms#newMenu(attrs)
endif
return s:editFileSettingsMenu
endfunction
"---------------------------------------------------------------------------
" forms#menu#MakeEditColorSchemeMenu: {{{3
" Returns menu
" Example:
" adam
" adaryn
" adrian
" .....
" xemacs
" xian
" zellner
" zenburn
"
" parameters: None
"---------------------------------------------------------------------------
if g:self#IN_DEVELOPMENT_MODE
if exists("s:editColorSchemeMenu")
unlet s:editColorSchemeMenu
endif
endif
function! forms#menu#MakeEditColorSchemeMenu()
if ! exists("s:editColorSchemeMenu")
redraw
:echo "NOTE: Loading Color menu takes time"
" get NL separated string with file names
let s:n = globpath(&runtimepath, "colors/*.vim")
" split at NL, Ignore case for VMS and windows, sort on name
let s:names = sort(map(split(s:n, "\n"), 'substitute(v:val, "\\c.*[/\\\\:\\]]\\([^/\\\\:]*\\)\\.vim", "\\1", "")'), 1)
let items = []
" define all the submenu entries
for s:name in s:names
" exe "an 20.450." . s:idx . ' &Edit.C&olor\ Scheme.' . s:name . " :colors " . s:name . "<CR>"
call add(items, {
\ 'type': 'button',
\ 'label': s:name,
\ 'command': ':colors '.s:name
\ })
endfor
unlet s:name s:names s:n
let attrs = { 'items': items }
let s:editColorSchemeMenu = forms#newMenu(attrs)
endif
return s:editColorSchemeMenu
endfunction
"---------------------------------------------------------------------------
" forms#menu#MakeEditKeymapMenu: {{{3
" Returns menu
" Example:
" None set keymap=
" accents
" arabic
" ....
" thaana
" ukrainian-dvorak
" ukrainian-jcuken
" vietnamese-viqr
"
" parameters: None
"---------------------------------------------------------------------------
if g:self#IN_DEVELOPMENT_MODE
if exists("s:editKeymapMenu")
unlet s:editKeymapMenu
endif
endif
function! forms#menu#MakeEditKeymapMenu()
if ! exists("s:editKeymapMenu")
let items = []
call add(items, {
\ 'type': 'button',
\ 'label': 'None',
\ 'hint': 'set keymap=',
\ 'command': ':set keymap='
\ })
let s:n = globpath(&runtimepath, "keymap/*.vim")
if s:n != ""
let d = {}
while strlen(s:n) > 0
let s:i = stridx(s:n, "\n")
if s:i < 0
let s:name = s:n
let s:n = ""
else
let s:name = strpart(s:n, 0, s:i)
let s:n = strpart(s:n, s:i + 1, 19999)
endif
" Ignore case for VMS and windows
let s:name = substitute(s:name, '\c.*[/\\:\]]\([^/\\:_]*\)\(_[0-9a-zA-Z-]*\)\=\.vim', '\1', '')
if ! has_key(d, s:name)
call add(items, {
\ 'type': 'button',
\ 'label': s:name,
\ 'command': ':set keymap='.s:name
\ })
let d[s:name] = 1
endif
unlet s:name
unlet s:i
endwhile
unlet d
endif
unlet s:n
let attrs = { 'items': items }
let s:editKeymapMenu = forms#newMenu(attrs)
endif
return s:editKeymapMenu
endfunction
"---------------------------------------------------------------------------
" forms#menu#MakeEditMenu: {{{3
" Returns menu
" Example:
" Undo
" Redo
" Repeat
" ────────────────────
" Cut
" Copy
" Paste
" Put Before [p
" Put After ]p
" Select All
" ────────────────────
" Find /
" Find and Replace /
" ────────────────────
" Window :options
" Settings
" Global Settings
" File Settings
" Color Scheme
" Keymap