~dcaro/+junk/vim

« back to all changes in this revision

Viewing changes to bundle/gundo/tests/bundled/lh-vim-lib/doc/lh-vim-lib.txt

  • Committer: david.caro.estevez at gmail
  • Date: 2012-01-08 21:14:56 UTC
  • Revision ID: david.caro.estevez@gmail.com-20120108211456-up2cxn4p97ileg38
init commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
*lh-vim-lib.txt*        Vim common libraries (v2.2.1)
 
2
                        For Vim version 7+      Last change: $Date: 2010-09-19 18:40:58 -0400 (Sun, 19 Sep 2010) $
 
3
 
 
4
                        By Luc Hermitte
 
5
                        hermitte {at} free {dot} fr
 
6
 
 
7
 
 
8
==============================================================================
 
9
CONTENTS                                      *lhvl-contents*      {{{1
 
10
|lhvl-presentation|     Presentation
 
11
|lhvl-functions|        Functions
 
12
    
 
13
|add-local-help|        Instructions on installing this help file
 
14
 
 
15
 
 
16
------------------------------------------------------------------------------
 
17
PRESENTATION                                  *lhvl-presentation*  {{{1
 
18
 
 
19
|lh-vim-lib| is a library that defines some common VimL functions I use in my
 
20
various plugins and ftplugins.
 
21
This library has been conceived as a suite of |autoload| plugins, and a few
 
22
|macros| plugins. As such, it requires Vim 7+.
 
23
 
 
24
 
 
25
==============================================================================
 
26
FUNCTIONS                                     *lhvl-functions*     {{{1
 
27
{{{2Functions list~
 
28
Miscellanous functions:                                 |lhvl#misc|
 
29
- |lh#askvim#exe()|
 
30
- |lh#common#check_deps()|
 
31
- |lh#common#error_msg()|
 
32
- |lh#common#warning_msg()|
 
33
- |lh#common#echomsg_multilines()|
 
34
- |lh#encoding#iconv()|
 
35
- |lh#event#register_for_one_execution_at()|
 
36
- |lh#option#get()|
 
37
- |lh#option#get_non_empty()|
 
38
- |lh#position#char_at_mark()|
 
39
- |lh#position#char_at_pos()|
 
40
- |lh#position#is_before()|
 
41
- |lh#visual#selection()|
 
42
Functors related functions:                             |lhvl#function|
 
43
- |lh#function#bind()|
 
44
- |lh#function#execute()|
 
45
- |lh#function#prepare()|
 
46
Lists related functions:                                |lhvl#list|
 
47
- |lh#list#accumulate()|
 
48
- |lh#list#copy_if()|
 
49
- |lh#list#Find_if()| and |lh#list#find_if()|
 
50
- |lh#list#intersect()|
 
51
- |lh#list#match()|
 
52
- |lh#list#subset()|
 
53
- |lh#list#Transform()| and |lh#list#transform()|
 
54
- |lh#list#transform_if()|
 
55
- |lh#list#unique_sort()| and |lh#list#unique_sort2()|
 
56
o |lh#list#equal_range()|, 
 
57
  |lh#list#lower_bound()| and |lh#list#upper_bound()| 
 
58
Graphs related functions:                               |lhvl#graph|
 
59
- |lh#graph#tsort#depth()|
 
60
- |lh#graph#tsort#breadth()|
 
61
Paths related functions:                                |lhvl#path|
 
62
- |lh#path#common()|
 
63
- |lh#path#depth()|
 
64
- |lh#path#glob_as_list()|
 
65
- |lh#path#is_absolute_path()|
 
66
- |lh#path#is_url()|
 
67
- |lh#path#select_one()|
 
68
- |lh#path#simplify()|
 
69
- |lh#path#strip_common()|
 
70
- |lh#path#strip_start()|
 
71
- |lh#path#to_dirname()|
 
72
- |lh#path#to_relative()|
 
73
- |lh#path#relative_to()|
 
74
- |lh#path#to_regex()|
 
75
Commands related functions:                             |lhvl#command|
 
76
- |lh#command#new()| (alpha version)
 
77
- |lh#command#Fargs2String()| (alpha version)
 
78
- |lh#command#complete()| (alpha version)
 
79
Menus related functions:                                |lhvl#menu|
 
80
- |lh#menu#def_toggle_item()|
 
81
- |lh#menu#text()|
 
82
- |lh#menu#make()|
 
83
- |lh#menu#IVN_make()|
 
84
- |lh#menu#is_in_visual_mode()|
 
85
- |lh#menu#map_all()|
 
86
- |lh#askvim#menu()| (beta version)
 
87
Buffers related functions:                              |lhvl#buffer|
 
88
- |lh#buffer#list()|
 
89
- |lh#buffer#find()|
 
90
- |lh#buffer#jump()|
 
91
- |lh#buffer#scratch()|
 
92
- |lh#buffer#dialog#| functions for building interactive dialogs
 
93
    - |lh#buffer#dialog#new()|
 
94
    - |lh#buffer#dialog#add_help()|
 
95
    - |lh#buffer#dialog#select()|
 
96
    - |lh#buffer#dialog#quit()|
 
97
    - |lh#buffer#dialog#update()|
 
98
Syntax related functions:                               |lhvl#syntax|
 
99
- |lh#syntax#name_at()|
 
100
- |lh#syntax#name_at_mark()|
 
101
- |lh#syntax#skip()|
 
102
- |lh#syntax#skip_at()|
 
103
- |lh#syntax#skip_at_mark()|
 
104
- |lh#syntax#list_raw()|
 
105
- |lh#syntax#list()|
 
106
 
 
107
}}}2
 
108
------------------------------------------------------------------------------
 
109
MISCELLANOUS FUNCTIONS                                *lhvl#misc*       {{{2
 
110
 
 
111
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
112
                                       *lh#common#echomsgMultilines()*  {{{3
 
113
lh#common#echomsgMultilines()({text}) (*deprecated*)~
 
114
                                      *lh#common#echomsg_multilines()*
 
115
lh#common#echomsg_multilines()({text})~
 
116
@param  {text}      Message to display on several lines
 
117
@return             Nothing
 
118
 
 
119
This function executes |:echomsg| as many times as required as there are lines
 
120
in the original {text}.
 
121
This is a workaround |:echomsg| that is unable to handle correctly multi-lines
 
122
messages.
 
123
 
 
124
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
125
                                                *lh#common#ErrorMsg()*  {{{3
 
126
lh#common#ErrorMsg({text}) (*deprecated*)~
 
127
                                               *lh#common#error_msg()*
 
128
lh#common#error_msg({text})~
 
129
@param  {text}      Error message to display
 
130
@return             Nothing
 
131
 
 
132
This function displays an error message in a |confirm()| box if gvim is being
 
133
used, or as a standard vim error message through |:echoerr| otherwise. 
 
134
 
 
135
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
136
                                               *lh#common#WarningMsg()* {{{3
 
137
lh#common#WarningMsg({text}) (*deprecated*)~
 
138
                                              *lh#common#warning_msg()*
 
139
lh#common#warning_msg({text})~
 
140
@param  {text}      Error message to display
 
141
@return             Nothing
 
142
 
 
143
This function displays a warning message highlighted with |WarningMsg| syntax.
 
144
 
 
145
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
146
                                                *lh#common#CheckDeps()* {{{3
 
147
lh#common#CheckDeps({symbol},{file},{path},{requester}) (*deprecated*)~
 
148
                                               *lh#common#check_deps()*
 
149
lh#common#check_deps({symbol},{file},{path},{requester})~
 
150
@param  {symbol}    Symbol required, see |exists()| for symbol format.
 
151
@param  {file}      File in which the symbol is expected to be defined
 
152
@param  {path}      Path where the file can be found
 
153
@param  {requester} Name of the script in need of this symbol
 
154
@return 0/1 whether the {symbol} exists
 
155
 
 
156
Checks if {symbol} exists in vim. If not, this function first tries
 
157
to |:source| the {file} in which the {symbol} is expected to be defined. If the
 
158
{symbol} is still not defined, an error message is issued (with
 
159
|lh#common#error_msg()|, and 0 is returned.
 
160
 
 
161
Example: >
 
162
    if   
 
163
          \    !lh#common#check_deps('*Cpp_CurrentScope', 
 
164
          \                     'cpp_FindContextClass.vim', 'ftplugin/cpp/',
 
165
          \                     'cpp#GotoFunctionImpl.vim')
 
166
          \ || !lh#common#check_deps(':CheckOptions',
 
167
          \                     'cpp_options-commands.vim', 'ftplugin/cpp/',
 
168
          \                     'cpp#GotoFunctionImpl.vim')
 
169
      let &cpo=s:cpo_save
 
170
      finish
 
171
    endif
 
172
 
 
173
Note: Since the introduction of |autoload| plugins in Vim 7, this function has
 
174
lost most of its interrest.
 
175
 
 
176
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
177
                                                *lh#option#Get()*       {{{3
 
178
lh#option#Get({name},{default}[,{scopes}])  (*deprecated*)~
 
179
                                                *lh#option#get()*
 
180
lh#option#get({name},{default}[,{scopes}])~
 
181
@param {name}       Name of the option to fetch
 
182
@param {default}    Default value in case the option is not defined
 
183
@param {scopes}     Vim scopes in which the options must be searched,
 
184
                    default="bg".
 
185
@return             b:{name} if it exists, or g:{name} if it exists, or
 
186
                    {default} otherwise.
 
187
@see                For development oriented options, |lh-dev| provides a
 
188
                    dedicated function: |lh#dev#option#get()|.
 
189
 
 
190
This function fetches the value of an user defined option (not Vim |options|).
 
191
The option can be either a |global-variable|, a |buffer-variable|, or even
 
192
a|window-variable|.
 
193
 
 
194
The order of the variables checked can be specified through the optional
 
195
argument {scopes}. By default, buffer-local options have the priority over
 
196
global options.
 
197
 
 
198
 
 
199
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
200
                                              *lh#option#GetNonEmpty()* {{{3
 
201
lh#option#GetNonEmpty({name},{default}[,{scopes}])  (*deprecated*)~
 
202
                                              *lh#option#get_non_empty()*
 
203
lh#option#get_non_empty({name},{default}[,{scopes}])~
 
204
@param {name}       Name of the option to fetch
 
205
@param {default}    Default value in case the option is not defined, nor empty
 
206
@param {scopes}     Vim scopes in which the options must be searched,
 
207
                    default="bg".
 
208
@return b:{name}    If it exists, of g:{name} if it exists, or {default}
 
209
                    otherwise.
 
210
 
 
211
This function works exactly like |lh#option#get()| except that a defined
 
212
variable with an empty value will be ignored as well.
 
213
An |expr-string| will be considered empty if its |strlen()| is 0, an
 
214
|expr-number| when it values 0, |Lists| and |Dictionaries| when their |len()|
 
215
is 0.
 
216
 
 
217
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
218
                                                *lh#askvim#Exe()*       {{{3
 
219
lh#askvim#Exe({command}) (*deprecated*)~
 
220
                                                *lh#askvim#exe()*
 
221
lh#askvim#exe({command})~
 
222
@param {command}    Command to execute from vim.
 
223
@return             What the command echoes while executed.
 
224
@note               This function encapsultates |redir| without altering any
 
225
                    register.
 
226
 
 
227
Some information aren't directly accessible (yet) through vim API
 
228
(|functions|).  However, they can be obtained by executing some commands, and
 
229
redirecting the result of these commands.
 
230
 
 
231
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
232
                                                *lh#askvim#menu()*      {{{3
 
233
lh#askvim#menu({menuid},{modes})~
 
234
@param {menuid}     Menu identifier.
 
235
@param {modes}      List of modes
 
236
@return             Information related to the {menuid}
 
237
@todo               Still bugged
 
238
 
 
239
This function provides a way to obtain information related to a menu entry in
 
240
Vim.
 
241
 
 
242
The format of the result being �to be stabilized�
 
243
 
 
244
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
245
                                               *lh#position#IsBefore()* {{{3
 
246
lh#position#IsBefore({lhs_pos},{rhs_pos})  (*deprecated*)~
 
247
                                               *lh#position#is_before()*
 
248
lh#position#is_before({lhs_pos},{rhs_pos})~
 
249
@param[in]          Positions as those returned from |getpos()|
 
250
@return             Whether {lhs_pos} is before {rhs_pos}
 
251
 
 
252
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
253
                                             *lh#position#CharAtMark()* {{{3
 
254
lh#position#CharAtMark({mark})  (*deprecated*)~
 
255
                                             *lh#position#char_at_mark()*
 
256
lh#position#char_at_mark({mark})~
 
257
@return             The character at a given |mark|.
 
258
 
 
259
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
260
                                              *lh#position#CharAtPos()* {{{3
 
261
lh#position#CharAtPos({pos})  (*deprecated*)~
 
262
                                              *lh#position#char_at_pos()* {{{3
 
263
lh#position#char_at_pos({pos})~
 
264
@return             The character at a position (see |getpos()|).
 
265
 
 
266
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
267
                                                *lh#visual#selection()* {{{3
 
268
lh#visual#selection()~
 
269
@return             The current visual selection
 
270
@post              |registers| are not altered by this function
 
271
 
 
272
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
273
                                 *lh#event#RegisterForOneExecutionAt()* {{{3
 
274
lh#event#RegisterForOneExecutionAt({event}, {cmd}, {group})  (*deprecated*)~
 
275
                                 *lh#event#register_for_one_execution_at()*
 
276
lh#event#register_for_one_execution_at({event}, {cmd}, {group})~
 
277
Registers a command to be executed once (and only once) when {event} is
 
278
triggered on the current file.
 
279
 
 
280
@param {event}  Event that will trigger the execution of {cmd}|autocmd-events|
 
281
@param   {cmd} |expression-command| to execute
 
282
@param {group} |autocmd-groups| under which the internal autocommand will be
 
283
                registered.
 
284
@todo possibility to specify the file pattern
 
285
 
 
286
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
287
                                                *lh#encoding#iconv()*   {{{3
 
288
lh#encoding#iconv({expr}, {from}, {to})~
 
289
This function just calls |iconv()| with the same arguments. The only
 
290
difference is that it return {expr} when we know that |iconv()| will return an
 
291
empty string.
 
292
 
 
293
 
 
294
------------------------------------------------------------------------------
 
295
FUNCTORS RELATED FUNCTIONS                            *lhvl#function*   {{{2
 
296
 
 
297
This sub-library helps defining functors-like variables, and execute them.
 
298
 
 
299
NB: C++ developpers may be already familiar with boost.bind
 
300
(/std(::tr1)::bind) function that inspired by feature.
 
301
 
 
302
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
303
                                                      *lhvl#functor*    {{{3
 
304
A functor is implemented as a |Dictionary| that has the following fields:
 
305
- {execute}  is the |Funcref| that will be actually executed by
 
306
             |lh#function#execute()|. Its only argument is a |List| of
 
307
              arguments for {function}.
 
308
- {function} that identifies the function to execute, 
 
309
              internals: it could be either a |Funcref|or a |expr-string|, or
 
310
              whatever is compatible with the {execute} |FuncRef| field.
 
311
- {args}     will contain the binded arguments as defined by
 
312
             |lh#function#bind()|. If you attach a {execute} function of your
 
313
              own to a functor, you don't need to fill "args".
 
314
 
 
315
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
316
                                                *lh#function#bind()*    {{{3
 
317
lh#function#bind({fn} [, {arguments} ...])~
 
318
This function creates a new |lhvl#functor| based on a given function {fn}, and
 
319
where some arguments are binded to the ones from {arguments}.
 
320
The result is a new function-like data having for parameter v:1_, v:2_, ...
 
321
that were specified in |lh#function#bind()| {arguments} list.
 
322
 
 
323
Examples:~
 
324
   See tests/lh/function.vim
 
325
 
 
326
Let's suppose Print(...) a VimL variadic function that echoes the arguments it
 
327
receives, i.e. >
 
328
   call Print(1,2,"text", ['foo', 'bar'])
 
329
will echo: >
 
330
   1 ## 2 ## 'text' ## ['foo', 'bar']
 
331
 
 
332
* Binding a |FuncRef|:~
 
333
  and reverse the arguments given to it when it will be executed >
 
334
   >:let func = lh#function#bind(function('Print'), 'v:3_', 'v:2_', 'v:1_')
 
335
   >:echo lh#function#execute(func, 1, 'two', [3])
 
336
   [3] ## 'two' ## 1
 
337
 
 
338
* Binding a named function:~
 
339
  the new function has 3 parameters and calls the named function with its 3rd
 
340
  parameter, 42, its second and its first parameters as arguments. >
 
341
   >:let func = lh#function#bind('Print', 'v:3_', 42, 'v:2_', 'v:1_')
 
342
   >:echo lh#function#execute(func, 1, 'two', [3])
 
343
   [3] ## 42 ## 'two' ## 1
 
344
< NB: if exists('*'.func_name) is false, then the string is considered to be
 
345
  an expression that will be evaluated as specified in the next use case.
 
346
 
 
347
* Binding an expression:~
 
348
  This time more complex on-the-fly computations on the |lhvl#functor|
 
349
  parameters can be accomplished >
 
350
   >:let func = lh#function#bind('Print(len(v:3_), 42, v:2_, v:1_)')
 
351
   >:echo lh#function#execute(func, 1, 'two', [1,2,3])
 
352
   3 ## 42 ## 'two' ## 1
 
353
< NB: func["args"] is defined, but empty, and unused.
 
354
 
 
355
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
356
                                                *lh#function#execute()* {{{3
 
357
lh#function#execute({functor} [, {arguments} ...])~
 
358
While |lh#function#bind()| defines a |lhvl#functor| that can be stored and
 
359
used later, |lh#function#execute()| directly executes the {functor} received.
 
360
 
 
361
Different kind of {functors} are accepted:
 
362
- |FuncRef|, and function names, where arguments are |lh#function#execute()|
 
363
  ones ;
 
364
- |expr-string|, where "v:{pos}_" strings are binded on-the-fly to {arguments} ;
 
365
- |lhvl#functor|, that will be given {arguments} as arguments.
 
366
 
 
367
Examples:~
 
368
   See tests/lh/function.vim
 
369
 
 
370
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
371
                                                *lh#function#prepare()* {{{3
 
372
lh#function#prepare({function}, {arguments} ...)~
 
373
This function expands all the elements from the {arguments} |List|, and
 
374
prepares a |expr-string| that once evaluated will call the n-ary {function}
 
375
with the n-{arguments}.
 
376
The evaluation is meant to be done with |eval()|.
 
377
>
 
378
   >:let call = lh#function#prepare('Print', [1,2,"foo"])
 
379
   >:echo eval(call)
 
380
   1 ## 2 ## 'foo'
 
381
 
 
382
 
 
383
------------------------------------------------------------------------------
 
384
LISTS RELATED FUNCTIONS                               *lhvl#list*       {{{2
 
385
 
 
386
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
387
                                                *lh#list#Match()*       {{{3
 
388
lh#list#Match({list},{pattern}[, {start-pos}])  (*deprecated*)~
 
389
                                                *lh#list#match()*
 
390
lh#list#match({list},{pattern}[, {start-pos}])~
 
391
@param      {list} |List| 
 
392
@param   {pattern} |expr-string|
 
393
@param {start-pos}  First index to check
 
394
@return             The lowest index, >= {start-pos}, in |List| {list} where
 
395
                    the item matches {pattern}.
 
396
@return             -1 if no item matches {pattern}.
 
397
@see |index()|, |match()|
 
398
 
 
399
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
400
                            *lh#list#find_if()* *lh#list#Find_if()*     {{{3
 
401
lh#list#Find_if({list},{string-predicate} [, {pred-parameters}][, {start-pos}])~
 
402
lh#list#find_if({list},{functor-predicate} [, {pred-parameters}][, {start-pos}])~
 
403
@param             {list} |List| 
 
404
@param      {*-predicate}  Predicate to evaluate
 
405
@param {pred-parameters}] |List| of Parameters to bind to special arguments in
 
406
                           the {predicate}.
 
407
@param         {start-pos} First index to check
 
408
@return                    The lowest index, >= {start-pos}, in |List| {list}
 
409
                           where the {predicate} evals to true.
 
410
@return                    -1 if no item matches {pattern}.
 
411
@see |index()|, |eval()|
 
412
 
 
413
The {string-predicate} recognizes some special arguments:
 
414
- |v:val| is substituted with the current element being evaluated in the list
 
415
- *v:1_* *v:2_* , ..., are substituted with the i-th elements from
 
416
  {pred-parameters}.
 
417
  NB: the "v:\d\+_" are 1-indexed while {pred-parameters} is indeed seen as
 
418
  0-indexed by Vim. 
 
419
  This particular feature permits to pass any type of variable to the
 
420
  predicate: a |expr-string|, a |List|, a |Dictionary|, ...
 
421
 
 
422
e.g.: >
 
423
    :let b = { 'min': 12, 'max': 42 }
 
424
    :let l = [ 1, 5, 48, 25, 5, 28, 6]
 
425
    :let i = lh#list#Find_if(l, 'v:val>v:1_.min  && v:val<v:1_.max && v:val%v:2_==0', [b, 2] )
 
426
    :echo l[i]
 
427
    28
 
428
 
 
429
The {functor-predicate} is a |lhvl#function|. The same example can be
 
430
rewritten as: >
 
431
    :let l = [ 1, 5, 48, 25, 5, 28, 6]
 
432
    :let i = lh#list#find_if(l, 'v:1_>12  && v:1_<42 && v:1_%2==0')
 
433
    :echo l[i]
 
434
    28
 
435
NB: Expect the Find_if() version to be replaced with the find_if() one.
 
436
 
 
437
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
438
                   *lh#list#unique_sort()* *lh#list#unique_sort2()*     {{{3
 
439
lh#list#unique_sort({list} [, {cmp}])~
 
440
lh#list#unique_sort2({list} [, {cmp}])~
 
441
@param[in] {list} |List| to sort
 
442
@param      {cmp} |Funcref| or function name that acts as a compare predicate.
 
443
                   It seems to be required in order to not compare number with
 
444
                   a lexicographic order (with vim 7.1-156)
 
445
@return            A new |List| sorted with no element repeated
 
446
@todo support an optional {equal} predicate to use in the /unique/ making
 
447
process.
 
448
 
 
449
The difference between the two functions is the following:
 
450
- unique_sort() stores all the elements in a |Dictionary|, then sort the values
 
451
  stored in the dictionary ;
 
452
- unique_sort2() sorts all the elements from the initial |List|, and then
 
453
  keeps only the elements that appear once.
 
454
 
 
455
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
456
                                                *lh#list#Transform()*   {{{3
 
457
lh#list#Transform({input},{output},{action})~
 
458
@param[in]   {input} Input |List| to transform
 
459
@param[out] {output} Output |List| where the transformed elements will be
 
460
                     appended.
 
461
@param      {action} Stringified action to apply on each element from {input}.
 
462
                     The string "v:val" will always be replaced with the
 
463
                     element currently transformed.
 
464
@return {output}
 
465
 
 
466
This function is actually returning >
 
467
    extend(a:output, map(copy(a:input), a:action))
 
468
 
 
469
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
470
                                                *lh#list#transform()*   {{{3
 
471
lh#list#transform({input},{output},{action})~
 
472
@param[in]   {input} Input |List| to transform
 
473
@param[out] {output} Output |List| where the transformed elements will be
 
474
                     appended.
 
475
@param      {action}|lhvl#functor| action to apply on each element from
 
476
                     {input}.
 
477
@return              {output}
 
478
 
 
479
This function is equivalent to (|lh#list#Transform()|) >
 
480
    extend(a:output, map(copy(a:input), a:action))
 
481
except the action is not a string but a |lhvl#functor|.
 
482
 
 
483
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
484
                                               *lh#list#transform_if()* {{{3
 
485
lh#list#transform_if({input},{output},{action},{predicate})~
 
486
@param[in]   {input} Input |List| to transform
 
487
@param[out] {output} Output |List| where the transformed elements will be
 
488
                     appended.
 
489
@param      {action}|lhvl#functor| action to apply on each element from
 
490
                     {input} that verifies the {predicate}.
 
491
@param   {predicate} Boolean |lhvl#functor| tested on each element before
 
492
                     transforming it.
 
493
@return              {output}
 
494
 
 
495
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
496
                                               *lh#list#copy_if()*      {{{3
 
497
lh#list#copy_if({input},{output},{predicate})~
 
498
Appends in {output} the elements from {input} that verifies the {predicate}. 
 
499
 
 
500
@param[in]   {input} Input |List| to transform
 
501
@param[out] {output} Output |List| where the elements that verify the
 
502
                     {predicate} will be appended.
 
503
@param   {predicate} Boolean |lhvl#functor| tested on each element.
 
504
@return              {output}
 
505
 
 
506
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
507
                                               *lh#list#accumulate()*   {{{3
 
508
lh#list#accumulate({input},{transformation},{accumulator})~
 
509
Accumulates the transformed elements from {input}.
 
510
 
 
511
@param[in]      {input} Input |List| to transform
 
512
@param {transformation}|lhvl#functor| applied on each element from {input}.
 
513
@param    {accumulator}|lhvl#functor| taking the list of tranformaed elements
 
514
                        as input
 
515
@return                 the result of {accumulator}
 
516
 
 
517
Examples: >
 
518
   :let strings = [ 'foo', 'bar', 'toto' ]
 
519
   :echo eval(lh#list#accumulate(strings, 'strlen', 'join(v:1_,  "+")'))
 
520
   10
 
521
 
 
522
   :let l = [ 1, 2, 'foo', ['bar']]
 
523
   :echo lh#list#accumulate(l, 'string', 'join(v:1_, "##")')
 
524
 
 
525
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
526
                                               *lh#list#subset()*       {{{3
 
527
lh#list#subset({input},{indices})~
 
528
Returns a subset slice of the {input} list.
 
529
 
 
530
@param[in] {input}   Input |List| from which  element will be extracted
 
531
@param[in] {indices}|List| of indices to extract
 
532
@return a |List| of the elements from {input} indexed by the {indices}
 
533
 
 
534
Example: >
 
535
    :let l = [ 1, 25, 5, 48, 25, 5, 28, 6]
 
536
    :let indices = [ 0, 5, 7, 3 ]
 
537
    :echo lh#list#subset(l, indices) 
 
538
    [ 1, 5, 6, 48 ]
 
539
 
 
540
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
541
                                               *lh#list#intersect()*    {{{3
 
542
lh#list#intersect({list1},{list2})~
 
543
Returns the elements present in both input lists.
 
544
 
 
545
@param[in] {list1}|List| 
 
546
@param[in] {list2}|List| 
 
547
@return a |List| of the elements in both {list1} and {list2}, the elements are
 
548
kepts in the same order as in {list1}
 
549
@note the algorithm is in O(len({list1})*len({list2}))
 
550
 
 
551
Example: >
 
552
    :let l1 = [ 1, 25, 7, 48, 26, 5, 28, 6]
 
553
    :let l2 = [ 3, 8, 7, 25, 6 ]
 
554
    :echo lh#list#intersect(l1, l2) 
 
555
    [ 25, 7, 6 ]
 
556
 
 
557
------------------------------------------------------------------------------
 
558
GRAPHS RELATED FUNCTIONS                              *lhvl#graph*      {{{2
 
559
 
 
560
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
561
                                             *lh#graph#tsort#depth()*   {{{3
 
562
                                             *lh#graph#tsort#breadth()* {{{3
 
563
lh#graph#tsort#depth({dag}, {start-nodes})~
 
564
lh#graph#tsort#breadth({dag}, {start-nodes})~
 
565
These two functions implement a topological sort on the Direct Acyclic Graph.
 
566
- depth() is a recursive implementation of a depth-first search. 
 
567
- breadth() is a non recursive implementation of a breadth-first search.
 
568
 
 
569
@param {dag} is a direct acyclic graph defined either:
 
570
             - as a |Dictionnary| that associates to each node, the |List| of
 
571
               all its successors
 
572
             - or as a /fetch/ |function()| that returns the |List| of the
 
573
               successors of a given node -- works only with depth() which
 
574
               takes care of not calling this function more than once for each
 
575
               given node.
 
576
@param {start-nodes} is a |List| of start nodes with no incoming edge
 
577
@throw "Tsort: cyclic graph detected:" if {dag} is not a DAG.
 
578
@see http://en.wikipedia.org/wiki/Topological_sort
 
579
@since Version 2.1.0
 
580
@test tests/lh/topological-sort.vim
 
581
 
 
582
 
 
583
------------------------------------------------------------------------------
 
584
PATHS RELATED FUNCTIONS                               *lhvl#path*       {{{2
 
585
 
 
586
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
587
                                                   *lh#path#depth()*    {{{3
 
588
lh#path#depth({dirname})~
 
589
Returns the depth of a directory name.
 
590
 
 
591
@param {dirname}  Pathname to simplify
 
592
@return the depth of the simplified directory name, i.e. 
 
593
        lh#path#depth("bar/b2/../../foo/") returns 1
 
594
 
 
595
@todo However, it is not able to return depth of negative paths like
 
596
      "../../foo/". I still need to decide whether the function should return
 
597
      -1 or 3.
 
598
 
 
599
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
600
                                                 *lh#path#dirname()*    {{{3
 
601
lh#path#dirname({dirname})~
 
602
Ensures the returned directory name ends with a '/' or a '\'.
 
603
 
 
604
@todo On windows, it should take 'shellslash' into account to decide the
 
605
      character to append.
 
606
 
 
607
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
608
                                                *lh#path#Simplify()*    {{{3
 
609
lh#path#Simplify({pathname})  (*deprecated*)~
 
610
                                                *lh#path#simplify()*
 
611
lh#path#simplify({pathname})~
 
612
Simplifies a path by getting rid of useless '../' and './'.
 
613
 
 
614
@param {pathname}  Pathname to simplify
 
615
@return the simplified pathname
 
616
 
 
617
This function works like |simplify()|, except that it also strips the leading
 
618
"./".
 
619
 
 
620
Note: when vim is compiled for unix, it seems unable to |simplify()| paths
 
621
containing "..\". (It likelly works this way when vim is compiled without
 
622
'shellslash' support)
 
623
 
 
624
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
625
                                                    *lh#path#common()*  {{{3
 
626
lh#path#common({pathnames})~
 
627
@param[in] {pathnames} |List| of pathnames to analyse
 
628
@return the common leading path between all {pathnames}
 
629
 
 
630
e.g.: >
 
631
 :echo lh#path#common(['foo/bar/file','foo/file', 'foo/foo/file'])
 
632
echoes >
 
633
 foo/
 
634
 
 
635
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
636
                                                *lh#path#StripCommon()* {{{3
 
637
lh#path#StripCommon({pathnames})  (*deprecated*)~
 
638
                                                *lh#path#strip_common()*
 
639
lh#path#strip_common({pathnames})~
 
640
@param[in,out] {pathnames} |List| of pathnames to simplify
 
641
@return the simplified pathnames
 
642
 
 
643
This function strips all pathnames from their common leading part. The
 
644
compuation of the common leading part is ensured by |lh#path#common()|
 
645
thank.
 
646
e.g.: >
 
647
 :echo lh#path#strip_common(['foo/bar/file','foo/file', 'foo/foo/file'])
 
648
echoes >
 
649
 ['bar/file','file', 'foo/file']
 
650
 
 
651
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
652
                                                 *lh#path#StripStart()* {{{3
 
653
lh#path#StripStart({pathname}, {pathslist})  (*deprecated*)~
 
654
                                                 *lh#path#strip_start()*
 
655
lh#path#strip_start({pathname}, {pathslist})~
 
656
@param[in] {pathname}  name to simplify
 
657
@param[in] {pathslist} list of pathname (can be a |string| of pathnames
 
658
                       separated by ",", of a |List|).
 
659
 
 
660
Strips {pathname} from any path from {pathslist}.
 
661
 
 
662
e.g.: >
 
663
 :echo lh#path#strip_start($HOME.'/.vim/template/bar.template',
 
664
   \ ['/home/foo/.vim', '/usr/local/share/vim/'])
 
665
 :echo lh#path#strip_start($HOME.'/.vim/template/bar.template',&rtp)
 
666
echoes >
 
667
 template/bar.template
 
668
 
 
669
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
670
                                                *lh#path#IsAbsolutePath()* {{{3
 
671
lh#path#IsAbsolutePath({path})  (*deprecated*)~
 
672
                                                *lh#path#is_absolute_path()*
 
673
lh#path#is_absolute_path({path})~
 
674
@return {path} Path to test
 
675
@return whether the path is an absolute path
 
676
@note Supports Unix absolute paths, Windows absolute paths, and UNC paths
 
677
 
 
678
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
679
                                                *lh#path#IsURL()*       {{{3
 
680
lh#path#IsURL({path})  (*deprecated*)~
 
681
                                                *lh#path#is_url()*
 
682
lh#path#is_url({path})~
 
683
@return {path} Path to test
 
684
@return whether the path is an URL
 
685
@note Supports http(s)://, (s)ftp://, dav://, fetch://, file://, rcp://,
 
686
rsynch://, scp://
 
687
 
 
688
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
689
                                                *lh#path#SelectOne()*   {{{3
 
690
lh#path#SelectOne({pathnames},{prompt})  (*deprecated*)~
 
691
                                                *lh#path#select_one()*
 
692
lh#path#select_one({pathnames},{prompt})~
 
693
@param[in] {pathnames} |List| of pathname
 
694
@param     {prompt}     Prompt for the dialog box
 
695
 
 
696
@return "" if len({pathnames}) == 0
 
697
@return {pathnames}[0] if len({pathnames}) == 1
 
698
@return the selected pathname otherwise
 
699
 
 
700
Asks the end-user to choose a pathname among a list of pathnames.
 
701
The pathnames displayed will be simplified thanks to |lh#path#strip_common()|
 
702
-- the pathname returned is the "full" original pathname matching the
 
703
simplified pathname selected.
 
704
 
 
705
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
706
                                                *lh#path#ToRelative()*  {{{3
 
707
lh#path#ToRelative({pathname})  (*deprecated*)~
 
708
                                                *lh#path#to_relative()*
 
709
lh#path#to_relative({pathname})~
 
710
@param {pathname} Pathname to convert
 
711
@return the simplified {pathname} in its relative form as it would be seen
 
712
        from the current directory.
 
713
 
 
714
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
715
                                                *lh#path#relative_to()*  {{{3
 
716
lh#path#relative_to({from}, {to})~
 
717
Returns the relative directory that indentifies {to} from {from} location.
 
718
@param {from} origin directory
 
719
@param {to}   destination directory
 
720
@return the simplified pathname {to} in its relative form as it would be seen
 
721
        from the {from} directory.
 
722
 
 
723
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
724
                                                *lh#path#GlobAsList()*  {{{3
 
725
lh#path#GlobAsList({pathslist}, {expr})  (*deprecated*)~
 
726
                                                *lh#path#glob_as_list()*
 
727
lh#path#glob_as_list({pathslist}, {expr})~
 
728
@return |globpath()|'s result, but formatted as a list of matching pathnames.
 
729
In case {expr} is a |List|, |globpath()| is applied on each expression in
 
730
{expr}.
 
731
 
 
732
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
733
                                                    *lh#path#find()*    {{{3
 
734
lh#path#find({pathslist}, {regex})~
 
735
@param[in] {pathslist} List of paths which can be received as a |List| or as a
 
736
                       string made of coma separated paths.
 
737
@return the path that matches the given {regex}
 
738
 
 
739
e.g.: >
 
740
 let expected_win = $HOME . '/vimfiles'
 
741
 let expected_nix = $HOME . '/.vim'
 
742
 let what =  lh#path#to_regex($HOME.'/').'\(vimfiles\|.vim\)'
 
743
 let z = lh#path#find(&rtp,what)
 
744
 if has('win16')||has('win32')||has('win64')
 
745
   Assert z == expected_win
 
746
 else
 
747
   Assert z == expected_nix
 
748
 endif
 
749
 
 
750
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
751
                                                *lh#path#to_regex()*    {{{3
 
752
lh#path#to_regex({pathname})~
 
753
Transforms the {pathname} to separate each node-name by the string '[/\\]' 
 
754
 
 
755
The rationale behind this function is to build system independant regex
 
756
pattern to use on pathnames as sometimes pathnames are built by appending
 
757
'/stuff/like/this' without taking 'shellslash' into account.
 
758
 
 
759
e.g.: >
 
760
 echo lh#path#to_regex('/home/luc/').'\(vimfiles\|.vim\)'
 
761
echoes >
 
762
 [/\\]home[/\\]luc[/\\]\(vimfiles\|.vim\)
 
763
 
 
764
 
 
765
------------------------------------------------------------------------------
 
766
MENUS RELATED FUNCTIONS                               *lhvl#menu*       {{{2
 
767
 
 
768
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
769
                                             *lh#menu#def_toggle_item()*  {{{3
 
770
lh#menu#def_toggle_item({Data})~
 
771
@param[in,out] {Data} Definition of a |menu| item.
 
772
 
 
773
This function defines a |menu| entry that will be associated to a
 
774
|global-variable| whose values can be cycled and explored from the menu. This
 
775
global variable can be seen as an enumerate whose value can be cyclically
 
776
updated through a menu.
 
777
 
 
778
{Data} is a |Dictionary| whose keys are:
 
779
- "variable": name of the |global-variable| to bind to the menu entry
 
780
  Mandatory.
 
781
- "values": associated values of string or integers (|List|)
 
782
  Mandatory.
 
783
- "menu": describes where the menu entry must be placed (|Dictionary|)
 
784
    - "priority": complete priority of the entry (see |sub-menu-priority|)
 
785
    - "name": complete name of the entry -- ampersand (&) can be used to define
 
786
      shortcut keys
 
787
  Mandatory.
 
788
- "idx_crt_value": index of the current value for the option (|expr-number|)
 
789
  This is also an internal variable that will be automatically updated to
 
790
  keep the index of the current value of the "variable" in "values".
 
791
  Optional ; default value is 1, or the associated index of the initial value
 
792
  of the variable (in "values") before the function call.
 
793
- "texts": texts to display according to the variable value (|List|)
 
794
  Optional, "values" will be used by default. This option is to be used to
 
795
  distinguish the short encoded value, from the long self explanatory name.
 
796
 
 
797
Warning:
 
798
    If the variable is changed by hand without using the menu, then the menu
 
799
    and the variable will be out of synch. Unless the command |lhvl-:Toggle|
 
800
    is used to change the value of the options (and keep the menu
 
801
    synchronized).
 
802
 
 
803
Examples:
 
804
   See tests/lh/test-toggle-menu.vim
 
805
 
 
806
                                                            *lhvl-:Toggle*
 
807
:Toggle {variable-name}~
 
808
@param {variable-name} must be a |global-variable| name used as "variable" in
 
809
the definition of a toggable menu item thanks to |lh#menu#def_toggle_item()|.
 
810
 
 
811
This command supports autocompletion on the {variable-name}.
 
812
 
 
813
Todo:
 
814
    Propose a *lhvl-:Set{vaName}* command.
 
815
 
 
816
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
817
                                                      *lh#menu#text()*  {{{3
 
818
lh#menu#text({text})~
 
819
@param[in] {text} Text to send to |:menu| commands
 
820
@return a text to be used in menus where "\" and spaces have been escaped.
 
821
 
 
822
This helper function transforms a regular text into a text that can be
 
823
directly used with |:menu| commands.
 
824
 
 
825
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
826
                                                      *lh#menu#make()*  {{{3
 
827
option: *[gb]:want_buffermenu_or_global_disable*
 
828
If Michael Geddes's |buffer-menu| plugin is installed, this option tells
 
829
whether we want to take advantage of it to define menus or to ignore it.
 
830
 
 
831
lh#menu#make({modes}, {menu-priority}, {menu-text}, {key-binding}, [<buffer>,]  {action})~
 
832
Creates a menu entry and its associated mappings for several modes at once.
 
833
 
 
834
@param[in] {modes} Vim modes the menus and maps will be provided for
 
835
@param[in] {menu-priority} |sub-menu-priority| for the new menu entry
 
836
@param[in] {menu-text}      Name of the new menu entry
 
837
@param[in] {key-binding}    Sequence of keys to execute the associated action
 
838
@param[in] "<buffer>"       If the string "<buffer>" is provided, then the 
 
839
                            associated mapping will be a |map-<buffer>|, and
 
840
                            the menu will be available to the current buffer
 
841
                            only. See |[gb]:want_buffermenu_or_global_disable|
 
842
                            When "<buffer>" is set, the call to lh#menu#make()
 
843
                            must be done in the buffer-zone from a |ftplugin|,
 
844
                            or from a |local_vimrc|.
 
845
@param[in] {action}         Action to execute when {key-binding} is typed, or
 
846
                            when the menu entry is selected.
 
847
@todo support select ('s') and visual-not-select ('x') modes
 
848
 
 
849
First example:~
 
850
The following call will add the menu "LaTeX.Run LaTeX once <C-L><C-O>", with
 
851
the priority (placement) 50.305, for the NORMAL, INSERT and COMMAND modes. The
 
852
action associated first saves all the changed buffers and then invokes LaTeX.
 
853
The same action is also binded to <C-L><C-O> for the same modes, with the
 
854
nuance that the maps will be local to the buffer.
 
855
>
 
856
  call lh#menu#make("nic", '50.305', '&LaTeX.Run LaTeX &once', "<C-L><C-O>",
 
857
          \ '<buffer>', ":wa<CR>:call TKMakeDVIfile(1)<CR>")
 
858
 
 
859
Second example:~
 
860
This example demonstrates an hidden, but useful, behavior: if the mode is the
 
861
visual one, then the register v is filled with the text of the visual area.
 
862
This text can then be used in the function called. Here, it will be proposed
 
863
as a default name for the section to insert:
 
864
>
 
865
  function! TKinsertSec()
 
866
    " ...
 
867
    if (strlen(@v) != 0) && (visualmode() == 'v')
 
868
      let SecName = input("name of ".SecType.": ", @v)
 
869
    else
 
870
      let SecName = input("name of ".SecType.": ")
 
871
    endif
 
872
    " ...
 
873
  endfunction
 
874
  
 
875
  call lh#menu#make("vnic", '50.360.100', '&LaTeX.&Insert.&Section',
 
876
          \ "<C-L><C-S>", '<buffer>', ":call TKinsertSec()<CR>")
 
877
 
 
878
We have to be cautious to one little thing, there is a side effect: the visual
 
879
mode vanishes when we enter the function. If you don't want this to happen,
 
880
use the non-existant command: |:VCall|.
 
881
 
 
882
Third example:~
 
883
If it is known that a function will be called only under |VISUAL-mode|, and
 
884
that we don't want of the previous behavior, we can explicitly invoke the
 
885
function with |:VCall| -- command that doesn't actually exist. Check
 
886
lh-tex/ftplugin/tex/tex-set.vim |s:MapMenu4Env| for such an example.
 
887
 
 
888
Fourth thing: actually, lh#menu#make() is not restricted to commands. The
 
889
action can be anything that could come at the right hand side of any |:map| or
 
890
|:menu| action. But this time, you have to be cautious with the modes you
 
891
dedicate your map to. I won't give any related example ; this is the
 
892
underlying approach in |lh#menu#IVN_make()|. 
 
893
 
 
894
 
 
895
                                                    *lh#menu#make()_modes*
 
896
Implementation details:~
 
897
The actual creation of the mappings is delegated to |lh#menu#map_all()|. 
 
898
If the {action} to execute doesn't start with ':', it is left untransformed,
 
899
otherwise it is adapted depending on each {mode}:
 
900
- INSERT-mode: each recognized |:command| call is prepended with |i_CTRL-O| 
 
901
- NORMAL-mode: the {action} is used as it is
 
902
- VISUAL-mode: ":Vcall" is replaced by "\<cr>gV", otherwise the selection is
 
903
  recorded into @v register, the {action} command is executed after a
 
904
  |v_CTRL-C|, and eventually @v is cleared. 
 
905
  The use is @v is deprecated, rely instead on |lh#menu#is_in_visual_mode()|
 
906
  and on |lh#selection#visual()|.
 
907
- COMMAND-mode: the {action} is prepended with |c_CTRL-C|.
 
908
 
 
909
Examples:
 
910
   See tests/lh/test-menu-map.vim
 
911
 
 
912
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
913
                                                  *lh#menu#IVN_make()*  {{{3
 
914
Mappings & menus inserting text~
 
915
lh#menu#IVN_make(<priority>, {text}, {key}, {IM-action}, {VM-action}, {NM-action} [, {nore-IM}, {nore-VM}, {nore-NM}])~
 
916
 
 
917
lh#menu#IVN_MenuMake() accepts three different actions for the three modes:
 
918
INSERT, VISUAL and NORMAL. The mappings defined will be relative to the
 
919
current buffer -- this function is addressed to ftplugins writers. The last
 
920
arguments specify whether the inner mappings and abbreviations embedded within
 
921
the actions should be expanded or not ; i.e. are we defining
 
922
�noremaps/noremenus� ?
 
923
 
 
924
You will find very simple examples of what could be done at the end of
 
925
menu-map.vim. Instead, I'll show here an extract of my TeX ftplugin: it
 
926
defines complex functions that will help to define very simply the different
 
927
mappings I use. You could find another variation on this theme in
 
928
ftplugin/html/html_set.vim.
 
929
 
 
930
>
 
931
  :MapMenu 50.370.300 &LaTeX.&Fonts.&Emphasize ]em emph
 
932
  call <SID>MapMenu4Env("50.370.200", '&LaTeX.&Environments.&itemize',
 
933
        \ ']ei', 'itemize', '\item ')
 
934
  
 
935
 
 
936
The first command binds ]em to \emph{} for the three different modes. In
 
937
INSERT mode, the cursor is positioned between the curly brackets, and a marker
 
938
is added after the closing bracket -- cf. my bracketing system. In VISUAL
 
939
mode, the curly brackets are added around the visual area. In NORMAL mode, the
 
940
area is considered to be the current word.
 
941
 
 
942
The second call binds for the three modes: ]ei to:
 
943
>
 
944
      \begin{itemize}
 
945
          \item
 
946
      \end{itemize}
 
947
    
 
948
The definition of the different functions and commands involved just follows.
 
949
>
 
950
  command -nargs=1 -buffer MapMenu :call <SID>MapMenu(<f-args>)
 
951
  
 
952
  function! s:MapMenu(code,text,binding, tex_cmd, ...)
 
953
    let _2visual = (a:0 > 0) ? a:1 : "viw"
 
954
    " If the tex_cmd starts with an alphabetic character, then suppose the
 
955
    " command must begin with a '\'.
 
956
    let texc = ((a:tex_cmd[0] =~ '\a') ? '\' : "") . a:tex_cmd
 
957
    call lh#menu#IVN_make(a:code, a:text.'     --  ' . texc .'{}', a:binding,
 
958
          \ texc.'{',
 
959
          \ '<ESC>`>a}<ESC>`<i' . texc . '{<ESC>%l',
 
960
          \ ( (_2visual=='0') ? "" : _2visual.a:binding),
 
961
          \ 0, 1, 0)
 
962
  endfunction
 
963
 
 
964
  " a function and its map to close a "}", and that works whatever the
 
965
  " activation states of the brackets and marking features are.
 
966
  function! s:Close()
 
967
    if strlen(maparg('{')) == 0                    | exe "normal a} \<esc>"
 
968
    elseif exists("b:usemarks") && (b:usemarks==1) | exe "normal �jump! "
 
969
    else                                           | exe "normal a "
 
970
    endif
 
971
  endfunction
 
972
 
 
973
  imap <buffer> �close! <c-o>:call <SID>Close()<cr>
 
974
 
 
975
  function! s:MapMenu4Env(code,text,binding, tex_env, middle, ...)
 
976
    let _2visual = (a:0 > 0) ? a:1 : "vip"
 
977
    let b = "'" . '\begin{' . a:tex_env . '}' . "'"
 
978
    let e = "'" . '\end{' . a:tex_env . '}' . "'"
 
979
    call IVN_MenuMake(a:code, a:text, a:binding,
 
980
          \ '\begin{'.a:tex_env.'�close!<CR>'.a:middle.' <CR>\end{'.a:tex_env.'}<C-F><esc>ks',
 
981
          \ ':VCall MapAroundVisualLines('.b. ',' .e.',1,1)',
 
982
          \ _2visual.a:binding,
 
983
          \ 0, 1, 0)
 
984
  endfunction
 
985
 
 
986
Examples:
 
987
   See tests/lh/test-menu-map.vim
 
988
 
 
989
 
 
990
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
991
                                         *lh#menu#is_in_visual_mode()*  {{{3
 
992
lh#menu#is_in_visual_mode()~
 
993
@return a boolean that tells whether the {action} used in
 
994
|lh#menu#is_in_visual_mode()| has been invoked from the VISUAL-mode.
 
995
 
 
996
NB: this function deprecates the test on @v.
 
997
 
 
998
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
999
                                                   *lh#menu#map_all()*  {{{3
 
1000
lh#menu#map_all({map-type}[, {map-args...}])~
 
1001
This function is a helper function that defines several mappings at once as
 
1002
|:amenu| would do.
 
1003
 
 
1004
@param {map-type}     String of the form "[aincv]*(nore)?map" that tells the
 
1005
                      mode on which mappings should be defined, and whether
 
1006
                      the mappings shall be |:noremap|.
 
1007
@param {map-args...}  Rest of the parameters that defines the mapping
 
1008
 
 
1009
 
 
1010
The action to execute will be corrected depending on the current mode. See
 
1011
|lh#menu#make()_modes| for more details.
 
1012
 
 
1013
 
 
1014
------------------------------------------------------------------------------
 
1015
COMMANDS RELATED FUNCTIONS                            *lhvl#command*    {{{2
 
1016
 
 
1017
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
1018
                                                *lh#command#new()*      {{{3
 
1019
Highly Experimental.
 
1020
 
 
1021
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
1022
                                       *lh#command#Fargs2String()*      {{{3
 
1023
lh#command#Fargs2String({aList})~
 
1024
@param[in,out] aList list of params from <f-args>
 
1025
@see tests/lh/test-Fargs2String.vim
 
1026
 
 
1027
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
1028
                                            *lh#command#complete()*     {{{3
 
1029
lh#command#complete({argLead}, {cmdLine}, {cursorPos})~
 
1030
Under developpement
 
1031
 
 
1032
 
 
1033
------------------------------------------------------------------------------
 
1034
BUFFERS RELATED FUNCTIONS                             *lhvl#buffer*     {{{2
 
1035
 
 
1036
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
1037
                                                *lh#buffer#list()*      {{{3
 
1038
lh#buffer#list()~
 
1039
@return The |List| of |buflisted| buffers.
 
1040
 
 
1041
e.g.: >
 
1042
 echo lh#list#transform(lh#buffer#list(), [], "bufname")
 
1043
 
 
1044
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
1045
                                                *lh#buffer#Find()*      {{{3
 
1046
lh#buffer#Find({filename})  (*deprecated*)~
 
1047
                                                *lh#buffer#find()*
 
1048
lh#buffer#find({filename})~
 
1049
Searchs for a window where the buffer is opened.
 
1050
 
 
1051
@param {filename}
 
1052
@return The number of the first window found, in which {filename} is opened.
 
1053
 
 
1054
If {filename} is opened in a window, jump to this window. Otherwise, return
 
1055
-1.
 
1056
 
 
1057
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
1058
                                                *lh#buffer#Jump()*      {{{3
 
1059
lh#buffer#Jump({filename}, {cmd})  (*deprecated*)~
 
1060
                                                *lh#buffer#jump()*
 
1061
lh#buffer#jump({filename}, {cmd})~
 
1062
Jumps to the window where the buffer is opened, or open the buffer in a new
 
1063
windows if none match.
 
1064
 
 
1065
@param {filename}
 
1066
@param {cmd}
 
1067
@return Nothing.
 
1068
 
 
1069
If {filename} is opened in a window, jump to this window. 
 
1070
Otherwise, execute {cmd} with {filename} as a parameter. Typical values for
 
1071
the command will be "sp" or "vsp". (see |:split|, |:vsplit|).
 
1072
 
 
1073
N.B.: While it is not the rationale behind this function, other commands that
 
1074
does not open the buffer may be used in the {cmd} parameter.
 
1075
 
 
1076
 
 
1077
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
1078
                                                *lh#buffer#Scratch()*   {{{3
 
1079
lh#buffer#Scratch({bname},{where})  (*deprecated*)~
 
1080
                                      *scratch* *lh#buffer#scratch()*
 
1081
lh#buffer#scratch({bname},{where})~
 
1082
Split-opens a new scratch buffer.
 
1083
 
 
1084
@param {bname} Name for the new scratch buffer
 
1085
@param {where} Where the new scratch buffer will be opened ('', or 'v')
 
1086
@post          The buffer has the following properties set: 
 
1087
                   'bt'=nofile, 'bh'=wipe, 'nobl', 'noswf', 'ro'
 
1088
 
 
1089
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
1090
                             *lhvl-dialog*      *lh#buffer#dialog#*     {{{3
 
1091
Functions for building interactive dialogs~
 
1092
Unlike other |lh-vim-lib| functions which can be used independently from each
 
1093
others, all the lh#buffer#dialog#*() functions constitute a coherent framework
 
1094
to define interactive dialogs.
 
1095
 
 
1096
For the moment it only supports the selection of one or several items in a
 
1097
list.
 
1098
 
 
1099
From a end-user point of view, a list of items is displayed in a (|scratch|)
 
1100
buffer. If enabled, the user can select (/tag) one or several items, and then
 
1101
validate its choice. He can always abort and quit the dialog. A few other
 
1102
features are also supported: a help message can be shown, the list may be
 
1103
colored, etc.
 
1104
 
 
1105
 
 
1106
The items displayed can be of any kind (function signatures, email addresses,
 
1107
suggested spellings, ...), as well as the validating action.  The
 
1108
help-header can be customized, as well as colours, other mappings, ...
 
1109
 
 
1110
However the list displaying + selection aspect is almost hardcoded. 
 
1111
 
 
1112
 
 
1113
How it works~
 
1114
------------
 
1115
Scripts have to call the function                    *lh#buffer#dialog#new()*
 
1116
  lh#buffer#dialog#new(bname, title, where, support-tagging, action, choices)~
 
1117
with:
 
1118
- {bname} being the name the |scratch| buffer will receive.
 
1119
- {title} the title that appears at the first line of the scratch buffer.
 
1120
  I usually use it to display the name of the "client" script, its version,
 
1121
  and its purpose/what to do.
 
1122
- {where} are |:split| options (like "bot below") used to open the scratch
 
1123
  buffer.
 
1124
- {support-tagging} is a boolean (0/1) option to enable the multi-selection.
 
1125
- {action} is the name of the callback function (more
 
1126
  advanced calling mechanisms latter may be supported later with
 
1127
  |lhvl-functions|).
 
1128
- {choices} is the |List| of exact strings to display.
 
1129
 
 
1130
The #new function builds and returns a |Dictionary|, it also opens and fills
 
1131
the scratch buffer, and put us within its context -- i.e. any |:map-<buffer>|
 
1132
or other buffer-related definitions will done in the new scratch buffer.
 
1133
 
 
1134
Thus, if we want to add other mappings, and set a syntax highlighting for the
 
1135
new buffer, it is done at this point (see the *s:PostInit()* function in my
 
1136
"client" scripts like |lh-tags|).
 
1137
At this point, I also add all the high level information to the
 
1138
dictionary (for instance, the list of function signatures is nice, but
 
1139
it does not provides enough information (the corresponding file, the
 
1140
command to jump to the definition/declaration, the scope, ...)
 
1141
 
 
1142
The dictionary returned is filled with the following information:
 
1143
- buffer ids,
 
1144
- where was the cursor at the time of the creation of the new scratch buffer,
 
1145
- name of the callback function.
 
1146
 
 
1147
 
 
1148
Regarding the callback function: *lhvl-dialog-select-callback*
 
1149
- It ca not be a |script-local| function, only global and autoload functions
 
1150
  are supported.
 
1151
- When called, we are still within the scratch buffer context.
 
1152
- It must accept a |List| of numbers as its first parameter: the index (+1) of
 
1153
  the items selected.
 
1154
- The number 0, when in the list, means "aborted". In that case, the
 
1155
  callback function is expected to call |lh#buffer#dialog#quit()| that will
 
1156
  terminate the scratch buffer (with |:quit|), and jump back to where we were
 
1157
  when #new was called, and display a little "Abort" message.
 
1158
- We can terminate the dialog with just :quit if we don't need to jump
 
1159
  back anywhere. For instance, lh-tags callback function first
 
1160
  terminates the dialog, then jumps to the file where the selected tag
 
1161
  comes from.
 
1162
 
 
1163
- It's completely asynchronous: the callback function does not return anything
 
1164
  to anyone, but instead applies transformations in other places.
 
1165
  This aspect is very important. I don't see how this kind of feature can work
 
1166
  if not asynchronously in vim.
 
1167
 
 
1168
How to customize it:
 
1169
- *lh#buffer#dialog#quit()* can be explicitly called, from a registered select
 
1170
  callback (|lhvl-dialog-select-callback|), in order to terminate the dialog.
 
1171
- *lh#buffer#dialog#add_help()* can be used to complete the help/usage message
 
1172
  in both its short and long form.
 
1173
- *lh#buffer#dialog#update()* can be called after the list of items has been
 
1174
  altered in order to refresh what is displayed. The rationale behind this
 
1175
  feature is to support sorting, filtering, items expansion, etc. See
 
1176
 |lh-tags| implementation for an example.
 
1177
- *lh#buffer#dialog#select()* can be used in new mappings in order to handle
 
1178
  differently the selected items.
 
1179
 |lh-tags| uses this function to map 'o' to the split-opening of the selected
 
1180
  items.
 
1181
  NB: the way this feature is supported may change in future releases.
 
1182
 
 
1183
Limitations:
 
1184
This script is a little bit experimental (even if it the result of almost 10
 
1185
years of evolution), and it is a little bit cumbersome.
 
1186
- it is defined to support only one callback -- see the hacks in |lh-tags| to
 
1187
  workaround this limitation.
 
1188
- it is defined to display list of items, and to select one or several items
 
1189
  in the end.
 
1190
- and of course, it requires many other functions from |lh-vim-lib|, but
 
1191
  nothing else.
 
1192
 
 
1193
------------------------------------------------------------------------------
 
1194
SYNTAX RELATED FUNCTIONS                              *lhvl#syntax*     {{{2
 
1195
 
 
1196
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
1197
                                                *lh#syntax#NameAt()*    {{{3
 
1198
lh#syntax#NameAt({lnum},{col}[,{trans}])  (*deprecated*)~
 
1199
                                                *lh#syntax#name_at()*
 
1200
lh#syntax#name_at({lnum},{col}[,{trans}])~
 
1201
@param {lnum}  line of the character
 
1202
@param {col}   column of the character
 
1203
@param {trans} see |synID()|, default=0
 
1204
@return the syntax kind of the given character at {lnum}, {col}
 
1205
 
 
1206
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
1207
                                               *lh#syntax#NameAtMark()* {{{3
 
1208
lh#syntax#NameAtMark({mark}[,{trans}])  (*deprecated*)~
 
1209
                                               *lh#syntax#name_at_mark()* {{{3
 
1210
lh#syntax#name_at_mark({mark}[,{trans}])~
 
1211
@param {mark}  position of the character
 
1212
@param {trans} see |synID()|, default=0
 
1213
@return the syntax kind of the character at the given |mark|.
 
1214
 
 
1215
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
1216
       *lh#syntax#Skip()* *lh#syntax#SkipAt()* *lh#syntax#SkipAtMark()* {{{3
 
1217
lh#syntax#Skip()  (*deprecated*)~
 
1218
lh#syntax#SkipAt({lnum},{col})  (*deprecated*)~
 
1219
lh#syntax#SkipAtMark({mark})  (*deprecated*)~
 
1220
       *lh#syntax#skip()* *lh#syntax#skip_at()* *lh#syntax#skip_at_mark()*
 
1221
lh#syntax#skip()~
 
1222
lh#syntax#skip_at({lnum},{col})~
 
1223
lh#syntax#skip_at_mark({mark})~
 
1224
 
 
1225
Functions to be used with |searchpair()| functions in order to search for a
 
1226
pair of elements, without taking comments, strings, characters and doxygen
 
1227
(syntax) contexts into account while searching.
 
1228
 
 
1229
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
1230
                                               *lh#syntax#list_raw()*   {{{3
 
1231
lh#syntax#list_raw({name})~
 
1232
@param {group-name} 
 
1233
@return the result of "syn list {group-name}" as a string
 
1234
 
 
1235
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
1236
                                                *lh#syntax#list()*      {{{3
 
1237
lh#syntax#list()~
 
1238
@param {group-name} 
 
1239
@return the result of "syn list {group-name}" as a list. 
 
1240
 
 
1241
This function tries to interpret the result of the raw list of syntax
 
1242
elements. 
 
1243
 
 
1244
 
 
1245
------------------------------------------------------------------------------
 
1246
                                                                     }}}1
 
1247
==============================================================================
 
1248
 � Luc Hermitte, 2001-2010, <http://code.google.com/p/lh-vim/>       {{{1
 
1249
 $Id: lh-vim-lib.txt 246 2010-09-19 22:40:58Z luc.hermitte $
 
1250
 VIM: let b:VS_language = 'american' 
 
1251
 vim:ts=8:sw=4:tw=80:fo=tcq2:ft=help:
 
1252
 vim600:fdm=marker: