/
lh-vim-lib.txt
5228 lines (4442 loc) · 231 KB
/
lh-vim-lib.txt
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
*lh-vim-lib.txt* Vim common libraries (v5.4.0)
For Vim version 7+ Last change: 20th Feb 2024
By Luc Hermitte
hermitte {at} free {dot} fr
==============================================================================
CONTENTS *lhvl-contents* {{{1
|lhvl-presentation| Presentation
|lhvl-functions| Functions
|add-local-help| Instructions on installing this help file
------------------------------------------------------------------------------
PRESENTATION *lhvl-presentation* {{{1
|lh-vim-lib| is a library that defines some common Vim functions I use in my
various plugins and ftplugins.
This library has been conceived as a suite of |autoload| plugins, and a few
|macros| plugins. As such, it requires Vim 7+.
As I only have access to a version 7.3-429 on travis-ci, let's say this is the
minimum vim version I'll try to be compatible with.
==============================================================================
FUNCTIONS *lhvl-functions* {{{1
{{{2Functions list~
Miscellanous functions: |lhvl#misc| {{{2
- |lh#askvim#exe()|
- |lh#askvim#execute()|
- |lh#askvim#execute()|
- |lh#askvim#scriptid()|
- |lh#askvim#scriptnames()|
- |lh#askvim#scriptname()|
- |lh#askvim#where_is_function_defined()|
- |lh#common#check_deps()|
- |lh#common#echomsg_multilines()|
- |lh#common#error_msg()|
- |lh#common#rand()|
- |lh#common#warning_msg()|
- |lh#diff#compute()|
- |lh#encoding#at()|
- |lh#encoding#current_character()|
- |lh#encoding#does_support()|
- |lh#encoding#find_best_glyph()|
- |lh#encoding#iconv()|
- |lh#encoding#previous_character()|
- |lh#encoding#strlen()|
- |lh#encoding#strpart()|
- |lh#env#expand_all()|
- |lh#event#register_for_one_execution_at()|
- |lh#exception#callstack()|
- |lh#exception#callstack_as_qf()|
- |lh#exception#callstack_as_qf_from()|
- |lh#exception#decode()|
- |lh#exception#get_callstack()|
- |lh#file#new_cache()|
- |lh#fmt#printf()|
- |lh#float#min()|, |lh#float#max()|,
|lh#float#arg_min()|, |lh#float#arg_max()|
- |lh#ft#is_script()|
- |lh#ft#is_text()|
- *lh#has#default_in_getbufvar()* returns whether |getbufvar()| has 3 parameters
- *lh#has#jobs()* returns whether |+job|s are correctly implemented
- *lh#has#partials()* returns whether |Partial|s are implemented
- *lh#has#vkey()* returns whether |v:key| can be used in |map()| and |filter()|.
- |lh#has#patch()|
- |lh#has#plugin()|
- |lh#lang#set_message_temporarily()|
- |lh#leader#get()|
- |lh#leader#get_local()|
- |lh#leader#set_local_if_unset()|
- |lh#mark#find_first_unused()|
- |lh#mark#is_unused()|
- |lh#math#abs()|
- |lh#mapping#create_toggable_group()|
- |lh#mapping#define()|
- |lh#mapping#plug()|
- |lh#mapping#reinterpret_escaped_char()|
- |lh#mapping#who_maps()|
- |lh#notify#clear_notifications()|
- |lh#notify#deprecated()|
- |lh#notify#once()|
- |lh#on#exit()|
- |lh#po#context()|
- |lh#position#char_at()|
- |lh#position#char_at_mark()|
- |lh#position#char_at_pos()|
- |lh#position#compare()|
- |lh#position#extract()|
- |lh#position#getcur()|
- |lh#position#is_before()|
- |lh#position#move()|
- |lh#position#move_n()|
- |lh#switch#new()|
- |lh#switch-add_case()|
- |lh#switch-evaluate()|
- |lh#tags#stack#push()|
- |lh#tags#stack#jump()|
- |lh#time#bench()|
- |lh#time#bench_n()|
- |lh#time#date()|
- |lh#type#name()|
- |lh#visual#cut()|
- |lh#visual#selection()|
Option related functions: |lhvl#option| {{{2
- |lh#option#exists_in_buf()|
- |lh#option#get()|
- |lh#option#get_non_empty()|
- |lh#option#get_from_buf()|
- |lh#option#getbufvar()|
- |lh#option#getbufglobvar()|
- |lh#option#is_set()|
- |lh#option#is_unset()|
- |lh#option#update()|
- |lh#ft#option#get()|
- |lh#ft#option#get_postfixed()|
- |lh#ft#option#get_all()|
- |lh#ref#bind()|
- |lh#ref#is_bound()|
Functor related functions: |lhvl#function| {{{2
- |lh#function#bind()|
- |lh#function#execute()|
- |lh#function#prepare()|
- |lh#partial#execute()|
- |lh#partial#make()|
List related functions: |lhvl#list| {{{2
- |lh#list#accumulate()|
- |lh#list#Find_if()|, |lh#list#find_if()|, and |lh#list#find_if_fast()|
- |lh#list#Transform()| and |lh#list#transform()|
- |lh#list#arg_min()|, |lh#list#arg_max()|
- |lh#list#chain_transform()|
- |lh#list#concurrent_for()|
- |lh#list#contain_entity()|
- |lh#list#copy_if()|
- |lh#list#cross()|
- |lh#list#equal_range()|
- |lh#list#find_entity()|
- |lh#list#flat_extend()|
- |lh#list#for_each_call()|
- |lh#list#get()|
- |lh#list#intersect()|
- |lh#list#is_contained_in()|
- |lh#list#lower_bound()| and |lh#list#upper_bound()|
- |lh#list#map_on()|
- |lh#list#mask()|
- |lh#list#match()|
- |lh#list#match_re()|
- |lh#list#matches()|
- |lh#list#not_contain_entity()|
- |lh#list#not_found()|
- |lh#list#possible_values()|
- |lh#list#push_if_new()|
- |lh#list#push_if_new_elements()|
- |lh#list#push_if_new_entity()|
- |lh#list#remove()|
- |lh#list#separate()|
- |lh#list#sort()|
- |lh#list#subset()|
- |lh#list#transform_if()|
- |lh#list#uniq()|
- |lh#list#unique_sort()| and |lh#list#unique_sort2()|
- |lh#list#zip()|, and |lh#list#zip_as_dict()|
Dict related functions: |lhvl#dict| {{{2
- |lh#dict#add_new()|
- |lh#dict#get_composed()|
- |lh#dict#key()|
- |lh#dict#let()|
- |lh#dict#print_as_tree()|
- |lh#dict#need_ref_on()|
- |lh#dict#subset()|
Stack related functions: |lhvl#stack| {{{2
- |lh#stack#push()|
- |lh#stack#pop()|
- |lh#stack#top()|
- |lh#stack#top_or()|
- |lh#stack#new()|, |lh#stack#new_list()|
- |lh#stack-push()|
- |lh#stack-pop()|
- |lh#stack-top()|
- |lh#stack-top_or()|
String related functions: |lhvl#string| {{{2
- |lh#string#as()|
- |lh#string#count()|
- |lh#string#join()|
- |lh#string#matches()|
- |lh#string#matchstrpos()|
- |lh#string#or()|
- |lh#string#substitute_unless()|
- |lh#string#trim()|
Graph related functions: |lhvl#graph| {{{2
- |lh#graph#tsort#depth()|
- |lh#graph#tsort#breadth()|
Path related functions: |lhvl#path| {{{2
- |lh#path#add_path_if_exists()|
- |lh#path#cd_without_sideeffects()|
- |lh#path#common()|
- |lh#path#depth()|
- |lh#path#exe()|
- |lh#path#exists()|
- |lh#path#find()|
- |lh#path#find_in_parents()|
- |lh#path#find_upward()|
- |lh#path#fix()|
- |lh#path#glob_as_list()|
- |lh#path#is_absolute_path()|
- |lh#path#is_distant_or_scratch()|
- |lh#path#is_in()|
- |lh#path#is_up_to_date()|
- |lh#path#is_url()|
- |lh#path#join()|
- |lh#path#munge()|
- |lh#path#new_permission_lists()|
- |lh#path#readlink()|
- |lh#path#relative_to()|
- |lh#path#remove_dir_mark()|
- |lh#path#select_one()|
- |lh#path#simplify()|
- |lh#path#split()|
- |lh#path#strip_common()|
- |lh#path#strip_start()|
- |lh#path#to_dirname()|
- |lh#path#to_regex()|
- |lh#path#to_relative()|
- |lh#path#vimfiles()|
- |lh#path#writable()|
Command related functions: |lhvl#command| {{{2
- |lh#command#analyse_args()|
- |lh#command#matching_variables()|
- |lh#command#matching_askvim()|
- |lh#command#matching_for_command()|
- |lh#command#matching_bash_completion()|
- |lh#command#matching_make_completion()|
- |lh#command#new()| (alpha version)
- |lh#command#Fargs2String()| (alpha version)
- |lh#command#complete()| (alpha version)
Menu related functions: |lhvl#menu| {{{2
- |lh#menu#def_string_item()|
- |lh#menu#def_toggle_item()|
- |lh#menu#text()|
- |lh#menu#make()|
- |lh#menu#IVN_make()|
- |lh#menu#is_in_visual_mode()|
- |lh#menu#map_all()|
- |lh#menu#remove()|
- |lh#askvim#menu()| (beta version)
- |lh#project#menu#def_toggle_item()|
- |lh#project#menu#make()|
- |lh#project#menu#remove()|
Buffer related functions: |lhvl#buffer| {{{2
- |lh#buffer#get_nr()|
- |lh#buffer#list()|
- |lh#buffer#find()|
- |lh#buffer#jump()|
- |lh#buffer#scratch()|
- |lh#buffer#dialog#| functions for building interactive dialogs
- |lh#buffer#dialog#new()|
- |lh#buffer#dialog#add_help()|
- |lh#buffer#dialog#select()|
- |lh#buffer#dialog#quit()|
- |lh#buffer#dialog#update()|
Window related functions: |lhvl#window| {{{2
- |lh#window#create_window_with()|
- |lh#window#getid()|
- |lh#window#gotoid()|
- |lh#window#new()|
- |lh#window#split()|
- |lh#window#text_width()|
Quickfix related functions: |lhvl#quickfix| {{{2
- |lh#qf#get_metrics()|
- |lh#qf#get_title()|
- |lh#qf#get_winnr()|
- |lh#qf#is_displayed()|
- |lh#qf#make_context_map()|
- |lh#qf#set_title()|
Syntax related functions: |lhvl#syntax| {{{2
- |lh#syntax#is_a_comment()|
- |lh#syntax#is_a_comment_at()|
- |lh#syntax#getline_matching()|
- |lh#syntax#getline_not_matching()|
- |lh#syntax#line_filter()|
- |lh#syntax#match_at()|
- |lh#syntax#name_at()|
- |lh#syntax#name_at_mark()|
- |lh#syntax#skip()|
- |lh#syntax#skip_at()|
- |lh#syntax#skip_at_mark()|
- |lh#syntax#list_raw()|
- |lh#syntax#list()|
OS/System related functions: |lhvl#os| {{{2
- |lh#async#get_queue()|
- |:Jobs|
- |:JobUnpause|
- |:StopBGExecution|
- |lh#os#has_unix_layer_installed()|
- |lh#os#system_detected()|
- |lh#os#OnDOSWindows()|
- |lh#os#chomp()|
- |lh#os#system()|
- |lh#os#sys_cd()|
- |lh#os#cpu_number()|
- |lh#os#cpu_cores_number()|
- |lh#os#lcd()|
Python related functions |lhvl#python| {{{2
- |lh#python#best_still_avail()|
- |lh#python#has()|
- |lh#python#can_import()|
- |lh#python#external_can_import()|
Completion related functions |lhvl#completion| {{{2
- |lh#icomplete#new()|
- |lh#icomplete#new_on()|
- |lh#icomplete#run()|
Log related functions |lhvl#log| {{{2
- |:LHLog|, |lh#log#set_logger()|
- |lh#log#new()|
- |lh#log#none()|
- |lh#log#callstack()||
- |lh#log#exception()||
- |lh#log#this()||
- |Warnings|
- |lh#warning#emit()|
- |lh#warning#clear()|
Version Control System functions |lhvl#vcs| {{{2
- |lh#vcs#get_svn_root()|
- |lh#vcs#get_git_root()|
- |lh#vcs#is_svn()|
- |lh#vcs#is_git()|
- |lh#vcs#get_type()|
- |lh#vcs#get_url()|
- |lh#vcs#decode_github_url()|
- |lh#vcs#as_http()|
OO helpers |lhvl#oo| {{{2
- |lh#object#make_top_type()|
- |lh#object#inject()|
- |lh#object#inject_methods()|
- |lh#object#to_string()|
- |lh#object#_to_string()|
Variable helper functions |lhvl#variable| {{{2
- |lh#let#if_undef()|
- |lh#let#to()|
- |lh#let#undef()|
Project related definitions |lhvl#project| {{{2
- |p:| |project-variable|
- |:Project|
- |lh#project#define()|
- |lh#project#new()|
- |lh#project#_get()|
- |lh#project#crt_bufvar_name()|
- |lh#project#_crt_var_name()|
- |lh#project#menu#def_toggle_item()|
- |lh#project#menu#make()|
- |lh#project#menu#remove()|
Design by Contract related functions |lhvl#DbC| {{{2
- |lh#assert#mode()|
- |lh#assert#clear()|
- |lh#assert#errors()|
- Assertions:
- |lh#assert#equal()|
- |lh#assert#false()|
- |lh#assert#is()|
- |lh#assert#false()|
- |lh#assert#match()|
- |lh#assert#not_equal()|
- |lh#assert#true()|
- |lh#assert#value().empty()|
- |lh#assert#value().equal()|
- |lh#assert#value().differ()|
- |lh#assert#value().is_lt()|
- |lh#assert#value().is_le()|
- |lh#assert#value().is_gt()|
- |lh#assert#value().is_ge()|
- |lh#assert#value().is_set()|
- |lh#assert#value().is_unset()|
- |lh#assert#value().get()|
- |lh#assert#value().has_key()|
- |lh#assert#value().match()|
- |lh#assert#value().not()|
- |lh#assert#unexpected()|
------------------------------------------------------------------------------
COMMANDS *lhvl#commands* {{{2
- |:LetIfUndef|
- |:LetTo|
- |:Unlet|
- |:PushOptions|
- |:PopOptions|
}}}2
------------------------------------------------------------------------------
MISCELLANOUS FUNCTIONS *lhvl#misc* {{{2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#common#echomsgMultilines()* {{{3
lh#common#echomsgMultilines()({text}) (*deprecated*)~
*lh#common#echomsg_multilines()*
lh#common#echomsg_multilines()({text})~
@param {text} Message to display on several lines
@return Nothing
This function executes |:echomsg| as many times as required as there are lines
in the original {text}.
This is a workaround |:echomsg| that is unable to handle correctly multi-lines
messages.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#common#ErrorMsg()* {{{3
lh#common#ErrorMsg({text}) (*deprecated*)~
*lh#common#error_msg()*
lh#common#error_msg({text})~
@param {text} Error message to display
@return Nothing
This function displays an error message in a |confirm()| box if gvim is being
used, or as a standard vim error message through |:echoerr| otherwise.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#common#WarningMsg()* {{{3
lh#common#WarningMsg({text}) (*deprecated*)~
*lh#common#warning_msg()*
lh#common#warning_msg({text}, [{highlight}])~
@param {text} Error message to display
@param {hl} Highlight group name, default: `"WarningMsg"`
@return Nothing
This function displays a warning message highlighted with |WarningMsg| syntax,
or in any other highlight group specified.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#common#CheckDeps()* {{{3
lh#common#CheckDeps({symbol},{file},{path},{requester}) (*deprecated*)~
*lh#common#check_deps()*
lh#common#check_deps({symbol},{file},{path},{requester})~
@param {symbol} Symbol required, see |exists()| for symbol format.
@param {file} File in which the symbol is expected to be defined
@param {path} Path where the file can be found
@param {requester} Name of the script in need of this symbol
@return 0/1 whether the {symbol} exists
Checks if {symbol} exists in vim. If not, this function first tries
to |:source| the {file} in which the {symbol} is expected to be defined. If the
{symbol} is still not defined, an error message is issued (with
|lh#common#error_msg()|, and 0 is returned.
Example: >
if
\ !lh#common#check_deps('*Cpp_CurrentScope',
\ 'cpp_FindContextClass.vim', 'ftplugin/cpp/',
\ 'cpp#GotoFunctionImpl.vim')
\ || !lh#common#check_deps(':CheckOptions',
\ 'cpp_options-commands.vim', 'ftplugin/cpp/',
\ 'cpp#GotoFunctionImpl.vim')
let &cpo=s:cpo_save
finish
endif
Note: Since the introduction of |autoload| plugins in Vim 7, this function has
lost most of its interrest.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#common#rand()* {{{3
lh#common#rand({max})~
@return a random number in `[0..max[`.
@requires vim to be compiled with |+python| feature.
*lh#diff#compute()* {{{3
lh#diff#compute({f1}, {f2})~
Computes the difference between two "files", either with `diff` command-line
tool, or with Python difflib
@param[in] {f1} first file, or set of lines, or dictionary
@param[in] {f2} first file, or set of lines, or dictionary
@return a |list| of lines that differ
@since version 5.1.0
The dictionary format is:
- "`file`": filename
- "`lines`": list of lines
- "`name`": test to display when using Python
At least "`file`" or "`lines`" shall be set.
At this time the exact output format is unspecified, and |'diffopt| is
ignored.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#fmt#printf()* {{{3
lh#fmt#printf({format}, {args}...)~
@return a formatted string
Unlike |printf()|, this function takes positional parameters, i.e. >
AssertEquals(lh#fmt#printf("foo bar"), "foo bar")
AssertEquals(lh#fmt#printf("foo %1 bar", 42), "foo 42 bar")
AssertEquals(lh#fmt#printf("foo %1 bar %2", 42, "toto"), "foo 42 bar toto")
AssertEquals(lh#fmt#printf("foo %2 bar %1", 42, "toto"), "foo toto bar 42")
AssertEquals(lh#fmt#printf("foo %{2.toto}-%{1.titi} bar %1", {'a':42, 'titi': 'tutu'}, {'toto': {'foo': 42}}), "foo {'foo': 42}-tutu bar {'a': 42, 'titi': 'tutu'}")
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#mark#find_first_unused()* {{{3
lh#mark#find_first_unused()~
@returns The name of the first |mark| found to be _unused_ (as in
`lh#mark#is_unused()`).
The mark names are searched in `A`..`Z` and `a`..`z`.
@version 4.0.0
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#mark#is_unused()* {{{3
lh#mark#is_unused(mark)~
@returns Whether the given |mark| named {mark} is used. A mark is considered to be unused
from the moment `getpos(mark)[1:]` equals `[0, 0, 0]`
@version 4.0.0
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#math#abs()* {{{3
lh#math#abs(val)~
@returns the absolute value of the number {val}.
@author Troy Curtis Jr
The purpose of the function is to emulate |abs()| on vim version where it
isn't defined.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#mapping#create_toggable_group()* {{{3
lh#mapping#create_toggable_group(group_name)~
@returns a |lhvl#object| that permits to define mappings that can be
deactivated.
@version 5.3.0
It's subservices are:
- *define_map()* -- `(mode, lhs, rhs, isLocal, isExpr)`
Defines a new mapping
- *define_imap()* -- `(lhs, rhs, isLocal, isExpr [, isNore])`
Defines a new insert-mode mapping. In the particular case
*IMAP* is installed, it'll be used to define the mapping.
- *list_mappings()* -- `(isLocal)`
Displays the list of mappings defined through this object
- *clear_mappings()* -- `(isLocal)`
Removes all mappings defined through this object
- *toggle_mappings()*
Toggle the activation state of the mappings defined through
this object.
The activation state is global (multi-buffers), and it'll be
propagated even to mappings local in buffer other than the
current one.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#mapping#define()* {{{3
lh#mapping#define(map_dict)~
Defines a |mapping| from:
- `"mode"` : i, n, ..
- `"nore"` : 1/[0]
- `"silent"`: 1/[0]
- `"expr"` : 1/[0]
- `"buffer"`: 1/[0]
- `"unique"`: 1/[0]
- `"nowait"`: 1/[0]
- `"lhs"` : keybinding
- `"rhs"` : action bound
- `"sid"` : optional number
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#mapping#plug()* {{{3
lh#mapping#plug(keybinding, name, modes [, extra_map_dict])~
lh#mapping#plug(map_dict, modes)~
@param {map-dict} dictionary with the same keys as |maparg()| result.
Helper function to define in one go several default and unique mappings for a
plug mapping.
For all the mode specified, it's equivalent to: >
if !hasmapto(name, mode) && (mapcheck(keybinding, mode) == "")
exe mode.'map <silent> <unique> '.keybinding.' '.name
endif
Example: >
" 1st overload
call lh#mapping#plug('<C-F3>', '<Plug>(search-word)', 'nx')
call lh#mapping#plug('<C-S-F3>', '<Plug>(search-word-interactive)', 'nx', {'silent': 0})
" 2nd overload
call lh#mapping#plug({'lhs': '<C-F3>', 'rhs': '<Plug>(search-word)'}, 'nx')
In case of conflict, |lhvl-warnings| will be emitted. Plugin authors who want
to provide default mappings may not want to see theirs plugins print anything.
In order to do that you can |:call| `lh#mapping#plug()` with |:silent|: >
silent call lh#mapping#plug('if', '<plug>(lhdev-select-function)', 'ox')
The warning will still be recorded to be displayed later (with its stacktrace)
with |:Warnings|.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#mapping#reinterpret_escaped_char()* {{{3
lh#mapping#reinterpret_escaped_char(seq)~
This function transforms `'\<cr\>'`, `'\<esc\>'`, ... `'\<{keys}\>'` into the
interpreted sequences `"\<cr>"`, `"\<esc>"`, ... `"\<{keys}>"`.
It is meant to be used by fonctions like |lh#map#no_context()|,
|lh#map#insert_seq()|, ... as we can not define mappings (/abbreviations) that
contain `"\<{keys}>"` into the sequence to insert.
Note: It accepts sequences containing double-quotes.
@version 4.0.0, moved from |lh-dev|' |lh#dev#reinterpret_escaped_char()|.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#mapping#who_maps()* {{{3
lh#mapping#who_maps(rhs, mode)~
@returns a |List| of mappings (in |maparg()| |dictionary| format) that are
bound to {rhs} in the specified {mode}.
@version 4.6.0
@see also |hasmapto()|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#notify#clear_notifications()* {{{3
lh#notify#clear_notifications()~
Clears previous notifications. Identical notifications will be issued again.
@version 4.0.0
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#notify#deprecated()* {{{3
lh#notify#deprecated(old, new)~
Notifies once that {old} is deprecated and that we should use {new} instead.
@version 4.0.0
>
call lh#notify#deprecated(
\ 'lh#dev#reinterpret_escaped_char',
\ 'lh#mapping#reinterpret_escaped_char')
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#notify#once()* {{{3
lh#notify#once(id [, message])~
Issues a notification once.
@param[in] {id} Identifier of the notification
@param[in] {message} displayed.
Its format is the same as the one taken by |lh#fmt#printf()|
When not provided, no message is displayed, the
notification itself is left to the calling code.
@return whether a notification has/shall be done.
@version 4.0.0
>
" Usage 1
call lh#notify#once('foo', 'Warning: %1 is unexpected %2', what, context)
" Usage 2
if lh#notify#once('shy_dalek')
echomsg "Exterminate"
endif
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#on#exit()* {{{3
lh#on#exit()~
This function will register action to be executed at the end on a scope, and
more precisally in a |:finally| section.
It permits to do the following things:
- *restore()* restores a |variable| or a vim |option|.
- *restore_option()* restores a |lhvl#option.|
- *register()* registers: a |command| , or a |funcref|,
or |lhvl#functor| or an object method, to
execute.
It takes a second facultative argument
`"priority"` to give the highest priority to
the command.
- *restore_buffer_mapping()* restores a |:map-<buffer>|.
- *restore_mapping_and_clear_now()* restores |:map| and |:map-<buffer>| on
`finalize()` and undefine them right away.
- *restore_highlight()* restores highlight definition like
|CursorLine| one.
- *restore_cursor()* restores the cursor to its initial position.
Object methods emulates |Partials| on old vim versions. They are specified
with: `{'object': dictionary, 'method': function_name_or_ref}`
e.g. >
" Here let suppose g:foo exists, but not g:bar
let l:d = {'a': 1}
let cleanup = lh#on#exit()
\ . restore('g:foo')
\ . restore('g:bar')
\ . restore(l:d, 'a')
\ . restore(l:d, 'b')
\ . register('echo "The END"')
" note: |function|s can be registered as well
try
let g:foo = 1 - g:foo
let g:bar = 42
let l:d.a = 12
let l:d.b = 13
other actions that may throw
finally
call cleanup.finalize()
endtry
" Then g:foo and g:bar are restored, "The END" has been echoed
" l:d.a is restored to 1, and l:d.b is removed
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#lang#set_message_temporarily()* {{{3
lh#lang#set_message_temporarily(value)~
Makes sure |:language| `message` equals {value}.
Returns a |lh#on#exit()| object that restores the message locale to what is was.
@since Version 4.6.4
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#leader#get()* {{{3
*lh#leader#get_local()*
lh#leader#get([default='\'])~
lh#leader#get_local([default='\'])~
Returns the value of g:|mapleader| (/resp g:|maplocalleader|), or the default
value otherwise. The default value for the {default} value (sic) for the leader is '\'.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#leader#set_local_if_unset()* {{{3
lh#leader#set_local_is_unset(value)~
Sets g:|maplocalleader| to {value}, if and only if it isn't already set
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#askvim#Exe()* {{{3
lh#askvim#Exe({command}) (*deprecated*)~
*lh#askvim#exe()*
lh#askvim#exe({command})~
@param {command} Command to execute from vim.
@return What the command echoes while executed.
@note This function encapsulates |redir| without altering any
register.
Some information aren't directly accessible (yet) through vim API
(|functions|). However, they can be obtained by executing some commands, and
redirecting the result of these commands.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#askvim#execute()* {{{3
lh#askvim#execute({command})~
Portable (to old vim versions) of |execute()| that returns a |List|.
@param {command} Command to execute from vim.
@return What the command echoes while executed.
@note This function encapsulates |redir| without altering any
register.
If *lh#askvim#_beware_running_through_client_server()* has been called, and if
|execute()| is not supported by your vim version (v < 7.4-2008)
`lh#askvim#execute()` will return an empty list.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#askvim#scriptid()* {{{3
lh#askvim#scriptid(name)~
@return the id of the script associate to {name}.
@internal Lazily updates `s:scripts`.
@since Version 4.0.0
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#askvim#scriptname()* {{{3
lh#askvim#scriptname(id)~
@return the name of the script associate to {id}.
@internal Lazily updates `s:scripts`.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#askvim#scriptnames()* {{{3
lh#askvim#scriptnames()~
@return |:scriptnames| result as a list of [script_id, name] arrays.
@internal `s:scripts` variables is updated
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#askvim#where_is_function_defined()* {{{3
lh#askvim#where_is_function_defined({funcname})~
@return a |dictionary| made of:
- `'script'`: the scriptname where {funcname} has been defined.
- `'line'`: the liner number where {funcname} has been defined in the
script file, iff the information is available.
Requires Vim 8.1.0362+
@since Version 4.0.0
If |lh#askvim#_beware_running_through_client_server()| has been called, and if
|execute()| is not supported by your vim version (v < 7.4-2008)
`lh#askvim#where_is_function_defined` will try to decode the name of an
autoloaded function, or return an empty string otherwise.
@note Before v4.6.4, this function was returning a script.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#askvim#menu()* {{{3
lh#askvim#menu({menuid},{modes})~
@param {menuid} Menu identifier.
@param {modes} List of modes
@return Information related to the {menuid}
@todo Still bugged
This function provides a way to obtain information related to a menu entry in
Vim.
The format of the result being ?to be stabilized?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#async#get_queue()* {{{3
*lh#async#queue()*
lh#async#get_queue(name, policy)~
@since 5.0.0
@warning API changes in v5.0.0
@param[in] {name} Unique identifier the global queue to obtain
@param[in] {policy} Tells what shall be done when a new job is pushed into a
non empty queue. Valid values are:
- `'stack'`: push the new job for later
- `'replace'`: stop the current job, and start the new one
- `'dump'`: ignore the new job
- any else will result in the end user being asked what to
do.
This first function returns a job queue object that implements a few services
like `push_or_start(job)`, `stop()`... End-users are only expected ot use
|lh#async#queue/push_or_start()|.
*lh#async#queue/push_or_start()*
queue.push_or_start(job)~
This function is a wrapper around recent |job_start()| function. As such it
requires a recent version of Vim without any bugs in the |+job| related part.
I've chosen to require v7.4-1980 at least.
This function implements a queue of jobs to run. Only one job can be ran
simultaneously. When a job has finished, the next one is started.
So far it has been designed to register a |close_cb|, and it has been used
also with a |callback|. There is one default callback provided for |close_cb|
that won't do any thing.
All jobs are started through the |'shell'| in order to support
`cd dirname && cmd` and more complex things.
Under Windows it's ran with `[&shell, &shellcmdflag, command]`
Otherwise, it's ran with `&shell .' '. &shellcmdflag .' '. command`
@param {job} |Dict| that contains:
- options for |job_start()|
- `'cmd'`: command to execute
- `'txt'`: optional description of what is executed for |airline|
- `'before_starting_cb'`: optional callback for a function to execute before
starting any new job. Indeed, things that must be executed before a job
starts shall not be executed before the previous job has ended. This
callback helps to delay operations written in vim-script language.
- `'start_fail_cb'`: optional callback executed when starting the job fails.
@todo Support for |job_stop()|
Active queues and background job will be presented in |airline-section|`_b`.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*:Jobs* {{{3
:Jobs {queue-name}~
Opens a dialog scratch window displaying all jobs being executed in background
and programmed to be executed through |lh#async#queue| feature.
For the moment this window will:
- keep the queue displayed up to date
- permit to cancel jobs with `x`, `<del>` or `d`
- permit to un-pause the job queue with `p`. See |:JobUnpause|.
Eventually, it'll permit to reorganize pending jobs.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*:JobUnpause* {{{3
:JobUnpause {queue-name}~
When a process execution fails, if there are pending jobs, the job queue will
be paused if you confirm it.
The only ways to un-pause the queue are through `:JobUnpause` command or
through the |:Jobs| console.
For the moment, the queue cannot be pause voluntarily.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*:StopBGExecution* {{{3
:StopBGExecution <pattern>~
This command will cancel the first job (registered through |lh#async#queue()|)
it founds that matches the {pattern}.
This command supports |command-completion| to help select the right job.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#po#context()* {{{3
lh#po#context([textdomain, textdomaindir])~
@require `&shell == "bash`," otherwise no translation will be performed.
Builds a context that'll permit to translate messages. The default values for
the options will permit to translate Vim messages.
The context permits to request the translation of any messageId from a
.po/.mo file with *lh#po#context().translate()*
For instance, >
:language mes fr_FR.UTF-8
:echo lh#po#context().translate('[readonly]')
will print >
[lecture-seule]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#position#IsBefore()* {{{3
lh#position#IsBefore({lhs_pos},{rhs_pos}) (*deprecated*)~
*lh#position#is_before()*
lh#position#is_before({lhs_pos},{rhs_pos})~
@param[in] Positions as those returned from |getpos()|
@return Whether {lhs_pos} is before {rhs_pos}
@see also |lh#position#compare()| for a result compatible with |sort()|.
*lh#position#compare()* {{{3
lh#position#compare({lhs_pos},{rhs_pos})~
@param[in] Positions as those returned from |getpos()|
@return -1 {lhs_pos} if is before {rhs_pos}
@return +1 {lhs_pos} if is after {rhs_pos}
@return 0 {lhs_pos} is at {rhs_pos}
@see also |lh#position#is_before()| for a boolean result.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#position#char_at()* {{{3
lh#position#char_at({lig}, {col}~
@return The character at a given position.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#position#CharAtMark()* {{{3
lh#position#CharAtMark({mark}) (*deprecated*)~
*lh#position#char_at_mark()*
lh#position#char_at_mark({mark})~
@return The character at a given |mark|.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#position#CharAtPos()* {{{3
lh#position#CharAtPos({pos}) (*deprecated*)~
*lh#position#char_at_pos()* {{{3
lh#position#char_at_pos({pos})~
@return The character at a position (see |getpos()|).
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#position#extract()* {{{3
lh#position#extract({pos1}, {pos2})~
@return The string between the two positions (see |getpos()|).
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#position#getcur()* {{{3
lh#position#extract({pos1}, {pos2})~
@return |getcurpos()| when it exists, |getpos()| otherwise.
@since Version 4.1.0
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#position#move()* {{{3
lh#position#move({direction})~
@param {direction} should be either `"\<right>"` or `"\<left>"`.
@return a string that can be used to move the cursor in the specified direction
If vim version is >= 7.4.849, the movement can be
repeated/redone (see |redo-register|).
@since Version 4.4.0
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#position#move_n()* {{{3
lh#position#move_n({direction}, {count})~
@param {direction} should be either `"\<right>"` or `"\<left>"`.
@param {count} number of positions the cursor shall be moved
@return a string that can be used to move the cursor in the specified direction
If vim version is >= 7.4.849, the movement can be
repeated/redone (see |redo-register|).
@since Version 4.4.0
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#switch#new()* {{{3
lh#switch#new([{cases}...])~
@param {cases} passed to |lh#switch-add_case()|
@return a switch |lhvl#object| with two services: |lh#switch-add_case()| and
|lh#switch-evaluate()|.
@since Version 4.7.1
*lh#switch-add_case()* {{{4
lh#switch-add_case({case})~
@param {case} |Dictionary| made of the two keys
- `'cond'`: predicate taking N parameters
- `'function'`: |function| reference, or |string| that can be |eval()|uated,
taking N parameters.
@return |v:true|/1 or |v:false|/0
@pre The number of parameters N shall match the number of parameters that will
be passed to |lh#switch-evaluate()| method.
If |lambas| are not supported in your version of vim, you can still define
string that'll get evaluated. The parameters can be accessed through |a:000|
... manipulated as a |string.| e.g. >
let switch = lh#switch#new()
call switch.add_case({'cond': {d -> d.conv}, 'func': '"converting constructor from ".a:1.params[0].spelling'})
call switch.add_case({'cond': 'a:1.dtr' , 'func': '"a destructor"'})
call switch.add_case({'cond': 1 , 'func': '"0"'}) " default case...
let ctr = {'name': 'MyClass', 'params': [{'spelling': 'double'}], 'ctr': 1, 'dtr': 0}
AssertEqual (switch.evaluate(extend(copy(ctr), {'conv': 1})), 'converting constructor from double')
AssertEqual (switch.evaluate(extend(copy(ctr), {'conv': 0})), 'a constructor')
AssertEqual (switch.evaluate({'conv': 0, 'ctr':0, 'dtr': 1}), 'a destructor')
AssertEqual (switch.evaluate({'conv': 0, 'ctr':0, 'dtr': 0}), '0')
Never forget to make sure all possible cases are coverred. A "default" case
may be reduired.
*lh#switch-evaluate()* {{{4
lh#switch-evaluate({args}...)~
@param {args} N parameters that'll be passed to the `'cond'` predicate and
`'function'` registered previously with |lh#switch-add_case()|.
@pre The number of parameters N shall match the number of parameters that will
be passed to the predicates and the functions registered.
This method will first check the first case registered (in order), with a
predicate that evaluates to 1/|v:true|.
Then, it will evaluate its associated `'function'` and return its value.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -