├── LICENSE
├── README.md
├── addon-info.json
├── autoload
├── lua.vim
└── lua
│ ├── fold.vim
│ └── omni.vim
├── doc
└── vim-lua.txt
├── ftplugin
└── lua.vim
├── indent
└── lua.vim
├── lib
└── luavi
│ └── luacomplete.lua
├── lua
├── luavi.lua
└── luavi
│ ├── complete.lua
│ ├── fold.lua
│ └── vimutils.lua
├── plugin
└── lua.vim
└── syntax
└── lua.vim
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # vim-lua [](https://spacevim.org)
2 | > lua development plugin for Vim
3 |
4 | 
5 |
6 | #### Features
7 |
8 | - syntax highlight
9 | - indent
10 | - omni complete
11 | - code runner
12 |
--------------------------------------------------------------------------------
/addon-info.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vim-lua",
3 | "description": "lua development plugin for Vim",
4 | "author": "SpaceVim"
5 | }
6 |
--------------------------------------------------------------------------------
/autoload/lua.vim:
--------------------------------------------------------------------------------
1 | " source Lua...
2 | if has('lua')
3 | exe 'luafile ' . fnamemodify(expand(''), ':h:h').'/lua/luavi/complete.lua'
4 | endif
5 |
6 |
7 | ""
8 | " @public
9 | " this function is the omnifunc for lua file. to enable lua complete, add this
10 | " to you vimrc.
11 | " >
12 | " augroup vim-lua
13 | " autocmd!
14 | " autocmd FileType lua setlocal omnifunc=lua#complete
15 | " augroup END
16 | " <
17 | function! lua#complete(findstart, base) abort
18 |
19 | return lua#omni#complete(a:findstart, a:base)
20 |
21 | endfunction
22 |
--------------------------------------------------------------------------------
/autoload/lua/fold.vim:
--------------------------------------------------------------------------------
1 | function! lua#fold#foldlevel(linenum) abort
2 | lua require('luavi').fold(require('luavi.vimutils').eval('a:linenum'))
3 | endfunction
4 |
5 |
6 |
--------------------------------------------------------------------------------
/autoload/lua/omni.vim:
--------------------------------------------------------------------------------
1 | function! lua#omni#complete(findstart, base) abort
2 | lua require('luavi').complete(require('luavi.vimutils').eval('a:findstart'), require('luavi.vimutils').eval('a:base'))
3 | endfunction
4 |
--------------------------------------------------------------------------------
/doc/vim-lua.txt:
--------------------------------------------------------------------------------
1 | *vim-lua.txt* lua development plugin for Vim
2 | SpaceVim *vim-lua*
3 |
4 | ==============================================================================
5 | CONTENTS *vim-lua-contents*
6 | 1. Introduction..............................................|vim-lua-intro|
7 | 2. Configuration............................................|vim-lua-config|
8 | 3. Functions.............................................|vim-lua-functions|
9 | 4. Mappings...............................................|vim-lua-mappings|
10 |
11 | ==============================================================================
12 | INTRODUCTION *vim-lua-intro*
13 |
14 | lua development plugin for vim and neovim.
15 |
16 | ==============================================================================
17 | CONFIGURATION *vim-lua-config*
18 |
19 | *g:lua_default_mappings*
20 | Diable/Enable default mappings in lua buffer.
21 | >
22 | mode key functinon
23 | normal fl print functin list
24 | <
25 |
26 | ==============================================================================
27 | FUNCTIONS *vim-lua-functions*
28 |
29 | lua#complete({findstart}, {base}) *lua#complete()*
30 | this function is the omnifunc for lua file. to enable lua complete, add this
31 | to you vimrc.
32 | >
33 | augroup vim-lua
34 | autocmd!
35 | autocmd FileType lua setlocal omnifunc=lua#complete
36 | augroup END
37 | <
38 |
39 | ==============================================================================
40 | MAPPINGS *vim-lua-mappings*
41 |
42 | luacomplete defined some mappings for lua buffer:
43 | >
44 | PrintFunctionList print functino list
45 | WriteAndLuaFile wirte and luafile
46 | <
47 |
48 |
49 | vim:tw=78:ts=8:ft=help:norl:
50 |
--------------------------------------------------------------------------------
/ftplugin/lua.vim:
--------------------------------------------------------------------------------
1 | setlocal omnifunc=lua#complete
2 |
3 | if &l:foldmethod ==# 'expr'
4 | setlocal foldexpr=lua#fold#foldlevel(v:lnum)
5 | endif
6 | setlocal nofoldenable
7 |
--------------------------------------------------------------------------------
/indent/lua.vim:
--------------------------------------------------------------------------------
1 | " Vim indent file
2 | " Language: Lua
3 | " URL: https://github.com/tbastos/vim-lua
4 |
5 | " Initialization ------------------------------------------{{{1
6 |
7 | if exists("b:did_indent")
8 | finish
9 | endif
10 | let b:did_indent = 1
11 |
12 | setlocal autoindent
13 | setlocal nosmartindent
14 |
15 | setlocal indentexpr=GetLuaIndent()
16 | setlocal indentkeys+=0=end,0=until,0=elseif,0=else
17 |
18 | " Only define the function once.
19 | if exists("*GetLuaIndent")
20 | finish
21 | endif
22 |
23 | " Variables -----------------------------------------------{{{1
24 |
25 | let s:open_patt = '\C\%(\<\%(function\|if\|repeat\|do\)\>\|(\|{\)'
26 | let s:middle_patt = '\C\<\%(else\|elseif\)\>'
27 | let s:close_patt = '\C\%(\<\%(end\|until\)\>\|)\|}\)'
28 |
29 | let s:anon_func_start = '\S\+\s*[({].*\ 0 && contents_prev !~# s:anon_func_end
91 | let i -= 1
92 | endif
93 |
94 | " if this line closed a paren, indent (except with anon funcs)
95 | call cursor(prev_line, col([prev_line, '$']))
96 | let num_cur_closed_parens = searchpair('(', '', ')', 'mr', s:skip_expr, v:lnum)
97 | if num_cur_closed_parens > 0 && contents_cur !~# s:anon_func_end
98 | let i += 1
99 | endif
100 |
101 | " special case: call(with, {anon = function() -- should indent only once
102 | if i > 1 && contents_prev =~# s:anon_func_start
103 | let i = 1
104 | endif
105 |
106 | " special case: end}) -- end of call w/ anon func should outdent only once
107 | if i < -1 && contents_cur =~# s:anon_func_end
108 | let i = -1
109 | endif
110 |
111 | " restore cursor
112 | call setpos(".", original_cursor_pos)
113 |
114 | return indent(prev_line) + (shiftwidth() * i)
115 |
116 | endfunction
117 |
--------------------------------------------------------------------------------
/lib/luavi/luacomplete.lua:
--------------------------------------------------------------------------------
1 | local PATTERN_LUA_IDENTIFIER = '([%a_]+[%a%d_.]*)'
2 |
3 | local vimutil = require("luavi.vimutils")
4 |
5 |
6 | local __p_counter = 0
7 | --- Writes given arguments to temporary file adding counting and "\n" when appropriate. Useful when debugging.
8 | -- @param ... anything that a io.write function could accept
9 | local function __p(...)
10 | __p_counter = __p_counter + 1
11 | local f = io.open("/tmp/lua_omni_out.txt", "a")
12 | if f then
13 | f:write(__p_counter .. ": ")
14 | f:write(...)
15 | local last = select(select("#", ...), ...)
16 | if type(last) == "string" and not string.find(last, "\n$") then
17 | f:write("\n")
18 | end
19 | f:close()
20 | end
21 | end
22 |
23 |
24 | --- Finds all assignments in given buffer and return a table with them with order the closest ones being first.
25 | -- @param buf Vim's buffer to be used as source (current one if absent)
26 | -- @param line line number to be checked for being within function' body
27 | -- @return table with list of assignments
28 | function find_assigments(buf, line)
29 | if not line then
30 | buf = vim.window().buffer
31 | line = vim.window().line
32 | end
33 | buf = buf or vim.buffer()
34 | -- scan from first line
35 | local set = {}
36 | local list = {}
37 | local absidx
38 |
39 | local function add_multi_names(str)
40 | string.gsub(str, '([^, ]+)', function(s)
41 | if not set[s] or (set[s] > absidx) then
42 | set[s] = absidx
43 | table.insert(list, s)
44 | end
45 | end)
46 | end
47 |
48 | for lineidx = 1, #buf do
49 | local sts = string.match(buf[lineidx], PATTERN_LUA_IDENTIFIER .. '%s*=[^=]?.*$')
50 | -- collect assignments with relative line numbers
51 | absidx = math.abs(line - lineidx)
52 | if sts and (not set[sts] or (set[sts] > absidx)) then
53 | -- set new key or replace but only if the new absolute index is smaller
54 | set[sts] = absidx
55 | table.insert(list, sts)
56 | end
57 | -- Check for variables defined without assignments as local. It may
58 | -- generate redundant match but conditions in gsub's argument functions
59 | -- will make it get correct results.
60 | sts = string.match(buf[lineidx], 'local%s+([^=]+)')
61 | if sts then add_multi_names(sts) end
62 | -- matching variables initialized in generic for loop
63 | sts = string.match(buf[lineidx], 'for%s+(.*)%s+in')
64 | if sts then add_multi_names(sts) end
65 | -- function names matching
66 | sts = string.match(buf[lineidx], 'function%s+(' .. PATTERN_LUA_IDENTIFIER .. ')%s*%(')
67 | if sts and (not set[sts] or (set[sts] > absidx)) then
68 | -- set new key or replace but only if the new absolute index is smaller
69 | set[sts] = absidx
70 | table.insert(list, sts)
71 | end
72 | -- check for variables defined in functions statements
73 | sts = string.match(buf[lineidx], 'function%s*[^(]*%(([^)]+)%)')
74 | if sts then add_multi_names(sts) end
75 | end
76 | -- sort list using set's absolute indexes in comparator
77 | table.sort(list, function(v1, v2) return set[v1] < set[v2] end)
78 | return list
79 | end
80 |
81 |
82 | --- Escape Lua pattern magic characters "[().%+-*?[^$]" using escape "%".
83 | -- @param s a string to be escaped
84 | -- @return just an escaped string
85 | function escape_magic_chars(s)
86 | assert(type(s) == "string", "s must be a string!")
87 |
88 | return (string.gsub(s, '([().%+-*?[^$])', '%%%1'))
89 | end
90 |
91 |
92 | --- Replaces "*" and "." characters to more fitting Lua pattern ones.
93 | -- @param s a string
94 | -- @return pattern
95 | function glob_to_pattern(s)
96 | assert(type(s) == "string", "s must be a string!")
97 |
98 | local pat = string.gsub(s, '.', function(c)
99 | if c == "*" then
100 | return '.-'
101 | elseif c == '?' then
102 | return '.'
103 | else return escape_magic_chars(c) end
104 | end)
105 | return pat
106 | end
107 |
108 |
109 | --- Iterator which walks over a Vim buffer.
110 | -- @param buf buffer to be used as source
111 | -- @return next buffer's line
112 | function line_buf_iter(buf)
113 | buf = buf or vim.buffer()
114 | local lineidx = 0
115 | return function()
116 | lineidx = lineidx + 1
117 | if lineidx <= #buf then
118 | return buf[lineidx]
119 | end
120 | end
121 | end
122 |
123 |
124 | -- The completion functionality ------------------------------------------------
125 |
126 |
127 | --- Search for a single part path in _G environment.
128 | -- Nested tables aren't supported.
129 | -- @param pat path to be used in search
130 | -- @return Table with list of k, v pairs.
131 | -- k is function, table, or just variable) name.
132 | -- v is an actual object reference.
133 | function find_completions1(pat)
134 | local comps = {}
135 | for k, v in pairs(_G) do
136 | if string.find(k, "^" .. pat) then
137 | table.insert(comps, {k, v})
138 | end
139 | end
140 | return comps
141 | end
142 |
143 |
144 | --- Search for multi level paths starting from _G environment.
145 | -- @param pat path to be used in search
146 | -- @return Table with list of k, v pairs.
147 | -- k is function, table, or just variable name (however it's absolute path).
148 | -- v is an actual object reference.
149 | function find_completions2(pat)
150 | local results = {}
151 | -- split path pattern into levels
152 | local levels = {}
153 | for lev in string.gmatch(pat, "[^%.]+") do
154 | table.insert(levels, lev)
155 | end
156 | -- if the last character in pat is '.' and matching all level
157 | if string.sub(pat, -1) == "." then
158 | table.insert(levels, ".*")
159 | end
160 |
161 | -- set prepath if there are multiple levels (used for generating absolute paths)
162 | local prepath = #levels > 1 and table.concat(slice(levels, 1, #levels - 1), ".") .. "." or ""
163 | -- find target table namespace
164 | local where = _G
165 | for i, lev in ipairs(levels) do
166 | if i < #levels then -- not last final path's part?
167 | local w = where[lev]
168 | if w and type(w) == "table" then -- going into inner table/namespace?
169 | where = w
170 | else -- not, path is incorrect!
171 | break
172 | end
173 | else -- the last part of path
174 | for k, v in pairs(where) do
175 | if string.find(k, "^" .. lev) then -- final names search...
176 | table.insert(results, {prepath .. k, v})
177 | end
178 | end
179 | end
180 | end
181 | return results
182 | end
183 |
184 |
185 | --- Returns a list with paths to files with additional path for Lua omnicompletion.
186 | function lua_omni_files()
187 | local list = {}
188 | -- first check LUA_OMNI shell variable
189 | string.gsub(vim.eval("$LUA_OMNI") or "", '([^ ;,]+)', function(s) table.insert(list, s) end)
190 | -- Next try b:lua_omni buffer variable or...
191 | if vim.eval('exists("b:lua_omni")') == 1 then
192 | string.gsub(vim.eval("b:lua_omni") or "", '([^ ;,]+)', function(s) table.insert(list, s) end)
193 | -- there isn't buffer's var check for global one.
194 | elseif vim.eval('exists("g:lua_omni")') == 1 then
195 | string.gsub(vim.eval("g:lua_omni") or "", '([^ ;,]+)', function(s) table.insert(list, s) end)
196 | end
197 | return list
198 | end
199 |
200 |
201 | --- Search for paths in _G environment table and returns ones matching given pattern.
202 | -- @param pat a pattern
203 | -- @return list of matching paths from _G
204 | function find_completions3(pat)
205 | local flat = {}
206 | local visited = {}
207 | local count = 0
208 |
209 | function flatten_recursively(t, lvl)
210 | lvl = lvl or ""
211 | -- just to be safe...
212 | if count > 10000 then return end
213 |
214 | for k, v in pairs(t) do
215 | -- for safe measure above
216 | count = count + 1
217 | if type(k) == "string" then
218 | table.insert(flat, #lvl > 0 and lvl .. "." .. k or k)
219 | end
220 | -- Inner table but do it recursively only when this run hasn't found it
221 | -- already.
222 | if type(v) == "table" and not visited[v] then
223 | -- check to avoid in recursive call
224 | visited[v] = true
225 | if type(k) == "string" then
226 | flatten_recursively(v, #lvl > 0 and lvl .. "." .. k or k)
227 | end
228 | -- Uncheck to allow to visit the same table but from different path.
229 | visited[v] = nil
230 | end
231 | end
232 | end
233 |
234 | -- start from _G
235 | flatten_recursively(_G)
236 |
237 | -- add paths from file(s)
238 | local pathfiles = lua_omni_files()
239 | for _, fname in ipairs(pathfiles) do
240 | -- there is chance that filename is invalid so guard for error
241 | local res, err = pcall(function()
242 | for line in io.lines(fname) do
243 | -- trim line
244 | line = string.gsub(line, "^%s-(%S.-)%s-$", "%1")
245 | -- put every line as path
246 | table.insert(flat, line)
247 | end
248 | end)
249 | -- If pcall above did catch error then echo about it.
250 | if not res then vim.command('echoerr "' .. tostring(err) .. '"') end
251 | end
252 |
253 | local res = {}
254 | -- match paths with pattern
255 | for _, v in ipairs(flat) do
256 | if string.match(v, pat) then table.insert(res, v) end
257 | end
258 |
259 | return res
260 | end
261 |
262 |
263 | --- Utility function to be used with Vim's completefunc.
264 | function completion_findstart()
265 | local w = vim.window()
266 | local buf = w.buffer
267 | local line = buf[w.line]
268 | for i = w.col - 1, 1, -1 do
269 | local c = string.sub(line, i, i)
270 | -- "*" and "?" may be used by glob pattern
271 | if string.find(c, "[^a-zA-Z0-9_%.*?]") then
272 | return i
273 | end
274 | end
275 | return 0
276 | end
277 |
278 |
279 | --- Find matching completions.
280 | -- @param base a base to which complete
281 | -- @return list with possible (string) abbreviations
282 | function complete_base_string(base)
283 | local t = {}
284 |
285 | if type(base) == "string" then
286 | -- completion using _G environment
287 | -- obsolete the new version seems better
288 | -- local comps = find_completions2(base)
289 | -- for _, v in pairs(comps) do
290 | -- table.insert(t, v[1])
291 | -- end
292 | -- table.sort(t)
293 |
294 | local sortbylen = false
295 | local pat = string.match(base, '^[%a_][%a%d_]*$')
296 | if pat then -- single word completion
297 | pat = ".*" .. escape_magic_chars(pat) .. ".*"
298 | sortbylen = true
299 | else -- full completion
300 | pat = glob_to_pattern(base)
301 | if not string.match(pat, '%.%*$') then pat = pat .. '.*' end
302 | end
303 | -- try to find something matching...
304 | t = find_completions3("^" .. pat .. "$")
305 | -- in a case no results were found try to expand dots
306 | if #t == 0 then
307 | pat = string.gsub(base, "%.", "[^.]*%%.") .. '.*'
308 | t = find_completions3("^" .. pat .. "$")
309 | end
310 |
311 | -- For single word matches it's more convenient to have results sorted by
312 | -- their string length.
313 | if sortbylen then
314 | table.sort(t, function(o1, o2)
315 | o1 = o1 or ""
316 | o2 = o2 or ""
317 | local l1 = string.len(o1)
318 | local l2 = string.len(o2)
319 | return l1 < l2
320 | end)
321 | else
322 | table.sort(t)
323 | end
324 |
325 | -- Always do variable assignments matching per buffer now as
326 | -- find_assigments will return most close assignments first.
327 | local assigments = {}
328 | for i, v in ipairs(find_assigments()) do
329 | if string.find(v, "^" .. base) then table.insert(assigments, v) end
330 | end
331 | t = merge_list(assigments, t)
332 | end
333 | return t
334 | end
335 |
336 |
337 | --- To be called within CompleteLua Vim function.
338 | function completefunc_luacode()
339 | -- getting arguments from Vim function
340 | local findstart = vim.eval("a:findstart")
341 | local base = vim.eval("a:base")
342 | -- this function is called twice - first for finding range in line to complete
343 | if findstart == 1 then
344 | vim.command("return " .. completion_findstart())
345 | else -- the second run - do proper complete
346 | local comps = complete_base_string(base)
347 | for i = 1, #comps do comps[i] = "'" .. comps[i] .. "'" end
348 | -- returning
349 | vim.command("return [" .. table.concat(comps, ", ") .. "]")
350 | end
351 | end
352 |
353 |
354 | -- The outline window. ---------------------------------------------------------
355 |
356 | --- Get a list of Lua defined functions in a buffer.
357 | -- @param buf a buffer to be used (parsed?) for doing funcs list (optional, if
358 | -- absent then use current one)
359 | -- @return list of {linenumber, linecontent} tables
360 | function function_list(buf)
361 | local funcs = {}
362 | local linenum = 0
363 | for line in line_buf_iter(buf) do
364 | linenum = linenum + 1
365 | if string.find(line, "^%s-function%s+") then
366 | funcs[#funcs + 1] = {linenum, line}
367 | end
368 | -- TODO reuse later
369 | -- local funcname = string.match(buf[lineidx], "function%s+" .. PATTERN_LUA_IDENTIFIER .. "%s*%(")
370 | -- if funcname then
371 | -- table.insert(funcs, funcname)
372 | -- else
373 | -- funcname = string.match(buf[lineidx], PATTERN_LUA_IDENTIFIER .. "%s*=%s*function%s*%(")
374 | -- if funcname then
375 | -- table.insert(funcs, funcname)
376 | -- end
377 | -- end
378 | end
379 | return funcs
380 | end
381 |
382 |
383 | --- Prints list of function within Vim buffer.
384 | -- The output format is line_number: function func_name __spaces__ function's title (if exists)
385 | -- @param buf buffer to be used as source
386 | function print_function_list(buf)
387 | local funclist = function_list(buf)
388 | if #funclist > 0 then
389 | local countsize = #tostring(funclist[#funclist][1])
390 | for i, f in ipairs(funclist) do
391 | if i == 1 then print("line: function definition...") end
392 | -- try to get any doc about function...
393 | local doc = func_doc(f[1])
394 | local title = string.gmatch(doc["---"] or "", "[^\n]+")
395 | title = title and title() or nil
396 | local s = string.format("%" .. countsize .. "d: %-" .. (40 - countsize) .. "s %s", f[1], f[2],
397 | (title or ""))
398 | print(s)
399 | end
400 | else
401 | print "no functions found..."
402 | end
403 | end
404 |
405 |
406 | --- Checks if current line lies in function definition.
407 | -- Depends on usual code formating where "function" and "end" statements start
408 | -- at first column.
409 | -- @param buf Vim's buffer to be used as source (current one if absent)
410 | -- @param line line number to be checked for being within function' body
411 | -- @return funcstart, funcend pair or nil, nil if line is outside a function
412 | function in_func_body(buf, line)
413 | if not line then
414 | buf = vim.window().buffer
415 | line = vim.window().line
416 | end
417 | buf = buf or vim.buffer()
418 | -- search for function definition first
419 | local funcstart
420 | for lineidx = line, 1, -1 do
421 | -- If iterating back end at first column is found, then it's outside
422 | -- function.
423 | if string.find(buf[lineidx], "^end") then break end
424 | if string.find(buf[lineidx], "^function") then
425 | funcstart = lineidx
426 | break
427 | end
428 | end
429 | -- search for the function's closing "end"
430 | -- (depends on an usual formating, doesn't count code chunks)
431 | local funcend
432 | if funcstart then -- search for function's end only when start was found...
433 | for lineidx = line + 1, #buf do
434 | if string.find(buf[lineidx], "^end") then
435 | funcend = lineidx
436 | break
437 | end
438 | end
439 | end
440 | return funcstart, funcend
441 | end
442 |
443 |
444 | --- Search for variable assignments in a Vim buffer within given line range.
445 | -- @param buf Vim buffer to be used
446 | -- @param startline line number from search of assignments will begin
447 | -- @param endline line number to search of assignments will end
448 | -- @return table with list of found variable names
449 | function search_assignments1(buf, startline, endline)
450 | assert(type(buf) == "userdata", "buf must be a Vim buffer!")
451 | assert(type(startline) == "number", "startline must be a number!")
452 | assert(type(endline) == "number", "endline must be a number!")
453 | assert(startline < endline, "startline must precede endline!")
454 |
455 | -- assignment has a forms like:
456 | -- varname = something
457 | -- varname1[, varname2[, varname3]] = something1[, something2[, something3]]
458 | -- lets assume that there is only one "=" per line
459 | -- visibility of closures by dammed (for now...)
460 | local assignments = {}
461 | -- Patterns have list of patterns matching variable definitions. The first
462 | -- must be the usual "varname = something" type.
463 | local patterns = {"([%w,%s_,]-[^=])=([^=].-)", -- check if there is assignment in a line
464 | "for%s+(.-)%s+in%s+(.-)", -- check if there are variable definitions in "for ... in" loop
465 | "function%s%s-[%w-_]-%s-%((.-)%)"} -- check if there are variable set in function definition
466 |
467 | for lineidx = startline, endline - 1 do
468 | -- filter out eventual comments
469 | local line = string.gsub(buf[lineidx], "%s*%-%-.*$", "")
470 | -- Search for assignments, variable definitions in "for in" and in
471 | -- function statements.
472 | for i, pat in ipairs(patterns) do
473 | local s, e, pre, post = string.find(" " .. line .. " ", "%s" .. pat .. "%s")
474 | if pre then
475 | -- if subnum is 1 then assignment is local
476 | local line, subnum
477 | if i == 1 then -- only assignments can have local/not local variety
478 | line, subnum = string.gsub(pre, "local%s+", "")
479 | else
480 | line = pre
481 | end
482 | -- just store variable names in a set
483 | for varname in string.gmatch(line, "[^, \t]+") do assignments[varname] = true end
484 | end
485 | end
486 |
487 | end
488 | -- convert set to a list
489 | local assignmentlist = {}
490 | for k, v in pairs(assignments) do table.insert(assignmentlist, k) end
491 | return assignmentlist
492 | end
493 |
494 |
495 | --- Miscellaneous. -------------------------------------------------------------
496 |
497 | --- Prints keys within a table (or environment). Similar to Python's dir.
498 | -- @param t should be a table or a nil
499 | function dir(t)
500 | if t == nil then
501 | t = _G
502 | assert(type(t) == "table", "t should be a table!")
503 | elseif type(t) == "table" then
504 | for k, v in pairs(t) do
505 | -- TODO commit to main directory
506 | -- if value is a string and it's too long then trim it
507 | if type(v) == "string" and string.len(v) > 150 then
508 | v = string.sub(v, 1, 150) .. "..."
509 | end
510 | -- TODO end
511 | print(k .. ":", v)
512 | end
513 | end
514 | end
515 |
516 |
517 | --- Prints keys of internal Vim's vim Lua module.
518 | function dir_vim()
519 | for k, v in pairs(vim) do
520 | local ty = type(v)
521 | if ty == "function" or ty == "string" or ty == "number" then
522 | print(k)
523 | end
524 | end
525 | end
526 |
527 |
528 | --- Slice function operating on tables.
529 | -- Minus indexes aren't supported (yet...).
530 | -- @param t a table to be sliced
531 | -- @param s the starting index of slice (inclusive)
532 | -- @param s the ending index of slice (inclusive)
533 | -- @return a new table containing a slice from t
534 | function slice(t, s, e)
535 | assert(type(t) == "table", "t should be a table!")
536 | s = s or 1
537 | e = e or #t
538 | local sliced = {}
539 | for idx = s, e do
540 | if t[idx] then table.insert(sliced, t[idx]) end
541 | end
542 | return sliced
543 | end
544 |
545 |
546 | --- Merges multiple tables as lists.
547 | -- @return resulting list have merged arguments from left to right in ascending order
548 | function merge_list(...)
549 | local res = {}
550 | for idx = 1, select("#", ...) do
551 | local t = select(idx, ...)
552 | if type(t) == "table" then
553 | for i, v in ipairs(t) do table.insert(res, v) end
554 | else
555 | table.insert(res, t)
556 | end
557 | end
558 | return res
559 | end
560 |
561 |
562 | --- Returns list of active windows in a current tab.
563 | -- @return vim.window like tables with similar keys
564 | function window_list()
565 | local idx = 1
566 | local winlist = {}
567 | while true do
568 | local w = vim.window(idx)
569 | if not w then break end
570 | winlist[#winlist + 1] = {line = w.line, col = w.col, width = w.width,
571 | height = w.height, firstline = w.buffer[1],
572 | currentline = w.buffer[w.line]}
573 | idx = idx + 1
574 | end
575 | return winlist
576 | end
577 |
578 |
579 | --- Just prints current window list.
580 | function print_window_list()
581 | local wincount
582 | for i, w in ipairs(window_list()) do
583 | if i == 1 then print("win number, line, col, width, height :current line content...") end
584 | print(string.format("%02d: %s", i, w.currentline))
585 | wincount = i
586 | end
587 | if not wincount then print("no windows found (how it's possible?!)...") end
588 | end
589 |
590 |
591 | --- Try to parse function documentation using luadoc format.
592 | -- At first it wasn't easy to write, but after some thought I had it done
593 | -- in quite efficient way (I think :).
594 | -- @param line starting line of function which luadoc to parse
595 | -- @param buf Vim's buffer to be used as source (current one if absent)
596 | -- @return table containing k/v pairs analogous to luadoc's "@" flags
597 | function func_doc(line, buf)
598 | buf = buf or vim.buffer()
599 | assert(type(line) == "number", "line must be a number!")
600 | assert(line >= 1 and line <= #buf, "line should be withing range of buffer's lines!")
601 | local curlines, doc = {}, {}
602 | for l = line - 1, 1, -1 do
603 | local spciter = string.gmatch(buf[l], "%S+")
604 | local pre = spciter()
605 | local flag, fvalue, rest
606 | if pre == "---" then
607 | rest = table.concat(iter_to_table(spciter), " ")
608 | table.insert(curlines, rest)
609 | doc["---"] = curlines
610 | elseif pre == "--" then
611 | flag = spciter()
612 | if string.sub(flag, 1, 1) == "@" then
613 | fvalue = spciter()
614 | rest = table.concat(iter_to_table(spciter), " ")
615 | table.insert(curlines, rest)
616 | doc[flag .. ":" .. fvalue] = curlines
617 | curlines = {}
618 | else
619 | rest = table.concat(iter_to_table(spciter), " ")
620 | table.insert(curlines, rest)
621 | end
622 | else
623 | break
624 | end
625 | end
626 | -- post reverse and concat doc's strings
627 | for k, t in pairs(doc) do
628 | local reversed = {}
629 | for i = 1, #t do reversed[i] = t[#t - i + 1] end -- reverse accumulated lines
630 | doc[k] = table.concat(reversed, "\n")
631 | end
632 | return doc
633 | end
634 |
635 |
636 | --- Translates iterator function into a table.
637 | -- @param iter iterator function
638 | -- @return table populated by iterator
639 | function iter_to_table(iter)
640 | assert(type(iter) == "function", "iter has to be a function!")
641 | local t = {}
642 | local idx = 0
643 | for v in iter do
644 | idx = idx + 1
645 | t[idx] = v
646 | end
647 | return t
648 | end
649 |
650 |
651 | --- Iterator which scans Vim buffer and returns on each call a supposed fold level, line number and line itself. Parsing is simplified but should be good enough for most of the time.
652 | -- @param buf a Vim buffer to scan, nil for current buffer
653 | -- @param fromline a line number from which scanning starts, nil for 1
654 | -- @param toline a line number at which scanning stops, nil for the last buffer's line
655 | -- @return fold level, line number, line's content
656 | function fold_iter(buf, fromline, toline)
657 | assert(fromline == nil or type(fromline) == "number", "fromline must be a number if specified!")
658 | buf = buf or vim.buffer()
659 | toline = toline or #buf
660 | assert(type(toline) == "number", "toline must be a number if specified!")
661 |
662 | local lineidx = fromline and (fromline - 1) or 0
663 | -- to remember consecutive folds
664 | local foldlist = {}
665 | -- closure blocks opening/closing statements
666 | local patterns = {{"do", "end"},
667 | {"repeat", "until%s+.+"},
668 | {"if%s+.+%s+then", "end"},
669 | {"for%s+.+%s+do", "end"},
670 | {"function.+", "end"},
671 | {"return%s+function.+", "end"},
672 | {"local%s+function%s+.+", "end"},
673 | }
674 |
675 | return function()
676 | lineidx = lineidx + 1
677 | if lineidx <= toline then
678 | -- search for one of blocks statements
679 | for i, t in ipairs(patterns) do
680 | -- add whole line anchors
681 | local tagopen = '^%s*' .. t[1] .. '%s*$'
682 | local tagclose = '^%s*' .. t[2] .. '%s*$'
683 | -- try to find opening statement
684 | if string.find(buf[lineidx], tagopen) then
685 | -- just remember it
686 | table.insert(foldlist, t)
687 | elseif string.find(buf[lineidx], tagclose) then -- check for closing statement
688 | -- Proceed only if there is unclosed block in foldlist and its
689 | -- closing statement matches.
690 | if #foldlist > 0 and string.find(buf[lineidx], foldlist[#foldlist][2]) then
691 | table.remove(foldlist)
692 | -- Add 1 to foldlist length (synonymous to fold level) to include
693 | -- closing statement in the fold too.
694 | return #foldlist + 1, lineidx, buf[lineidx]
695 | else
696 | -- An incorrect situation where opening/closing statements didn't
697 | -- match (probably due to malformed formating or erroneous code).
698 | -- Just "reset" foldlist.
699 | foldlist = {}
700 | end
701 | end
702 | end
703 | -- #foldlist is fold level
704 | return #foldlist, lineidx, buf[lineidx]
705 | end
706 | end
707 | end
708 |
709 |
710 | --- A Lua part to be called from Vim script FoldLuaLevel function used by foldexpr option. It returns fold level for given line number.
711 | function foldlevel_luacode()
712 | local linenum = vim.eval("a:linenum")
713 | assert(type(linenum) == "number", "linenum must be a number!")
714 |
715 | -- by default don't make nested folds
716 | local innerfolds = false
717 | -- though a configuration variable can enable it
718 | if vim.eval('exists("b:lua_inner_folds")') == 1 then
719 | innerfolds = vim.eval('b:lua_inner_folds') == 1
720 | elseif vim.eval('exists("g:lua_inner_folds")') == 1 then
721 | innerfolds = vim.eval('g:lua_inner_folds') == 1
722 | end
723 | __p("innerfolds " .. tostring(innerfolds))
724 | -- Iterate over line fold levels to find that one for which Vim is asking.
725 | -- TODO It's repetitively inefficient - perhaps some kind of caching would
726 | -- be beneficial?
727 | for lvl, lineidx in fold_iter() do
728 | if lineidx == linenum then
729 | vim.command("return " .. (innerfolds and lvl or (lvl > 1 and 1 or lvl)))
730 | break
731 | end
732 | end
733 | end
734 |
735 |
--------------------------------------------------------------------------------
/lua/luavi.lua:
--------------------------------------------------------------------------------
1 | luavi = {}
2 |
3 | local complete = require('luavi.complete')
4 |
5 | function luavi.complete(findstart, base)
6 | complete.complete(findstart, base)
7 | end
8 |
9 | local function fold_iter(buf, fromline, toline)
10 | assert(fromline == nil or type(fromline) == "number", "fromline must be a number if specified!")
11 | buf = buf or vimutils.current_buffer()
12 | toline = toline or #buf
13 | assert(type(toline) == "number", "toline must be a number if specified!")
14 |
15 | local lineidx = fromline and (fromline - 1) or 0
16 | -- to remember consecutive folds
17 | local foldlist = {}
18 | -- closure blocks opening/closing statements
19 | local patterns = {{"do", "end"},
20 | {"repeat", "until%s+.+"},
21 | {"if%s+.+%s+then", "end"},
22 | {"for%s+.+%s+do", "end"},
23 | {"function.+", "end"},
24 | {"return%s+function.+", "end"},
25 | {"local%s+function%s+.+", "end"},
26 | }
27 |
28 | return function()
29 | lineidx = lineidx + 1
30 | if lineidx <= toline then
31 | -- search for one of blocks statements
32 | for i, t in ipairs(patterns) do
33 | -- add whole line anchors
34 | local tagopen = '^%s*' .. t[1] .. '%s*$'
35 | local tagclose = '^%s*' .. t[2] .. '%s*$'
36 | -- try to find opening statement
37 | if string.find(buf[lineidx], tagopen) then
38 | -- just remember it
39 | table.insert(foldlist, t)
40 | elseif string.find(buf[lineidx], tagclose) then -- check for closing statement
41 | -- Proceed only if there is unclosed block in foldlist and its
42 | -- closing statement matches.
43 | if #foldlist > 0 and string.find(buf[lineidx], foldlist[#foldlist][2]) then
44 | table.remove(foldlist)
45 | -- Add 1 to foldlist length (synonymous to fold level) to include
46 | -- closing statement in the fold too.
47 | return #foldlist + 1, lineidx, buf[lineidx]
48 | else
49 | -- An incorrect situation where opening/closing statements didn't
50 | -- match (probably due to malformed formating or erroneous code).
51 | -- Just "reset" foldlist.
52 | foldlist = {}
53 | end
54 | end
55 | end
56 | -- #foldlist is fold level
57 | return #foldlist, lineidx, buf[lineidx]
58 | end
59 | end
60 | end
61 |
62 | function luavi.fold(linenum)
63 | assert(type(linenum) == "number", "linenum must be a number!")
64 |
65 | -- by default don't make nested folds
66 | local innerfolds = false
67 | -- though a configuration variable can enable it
68 | if vimutils.eval('exists("b:lua_inner_folds")') == 1 then
69 | innerfolds = vimutils.eval('b:lua_inner_folds') == 1
70 | elseif vimutils.eval('exists("g:lua_inner_folds")') == 1 then
71 | innerfolds = vimutils.eval('g:lua_inner_folds') == 1
72 | end
73 |
74 | for lvl, lineidx in fold_iter() do
75 | if lineidx == linenum then
76 | vim.command("return " .. (innerfolds and lvl or (lvl > 1 and 1 or lvl)))
77 | break
78 | end
79 | end
80 | end
81 |
82 | return luavi
83 |
--------------------------------------------------------------------------------
/lua/luavi/complete.lua:
--------------------------------------------------------------------------------
1 | local PATTERN_LUA_IDENTIFIER = '([%a_]+[%a%d_.]*)'
2 |
3 | complete = {}
4 |
5 | local vimutil = require('luavi.vimutils')
6 |
7 | local function merge_list(...)
8 | local res = {}
9 | for idx = 1, select("#", ...) do
10 | local t = select(idx, ...)
11 | if type(t) == "table" then
12 | for i, v in ipairs(t) do table.insert(res, v) end
13 | else
14 | table.insert(res, t)
15 | end
16 | end
17 | return res
18 | end
19 |
20 | local function find_assigments(buf, line)
21 | if not line then
22 | buf = vimutils.current_buffer()
23 | -- line = current line number
24 | line = vimutils.current_linenr()
25 | end
26 | buf = buf or vimutils.current_buffer()
27 | -- scan from first line
28 | local set = {}
29 | local list = {}
30 | local absidx
31 |
32 | local function add_multi_names(str)
33 | string.gsub(str, '([^, ]+)', function(s)
34 | if not set[s] or (set[s] > absidx) then
35 | set[s] = absidx
36 | table.insert(list, s)
37 | end
38 | end)
39 | end
40 |
41 | for lineidx = 1, #buf do
42 | local sts = string.match(buf[lineidx], PATTERN_LUA_IDENTIFIER .. '%s*=[^=]?.*$')
43 | -- collect assignments with relative line numbers
44 | absidx = math.abs(line - lineidx)
45 | if sts and (not set[sts] or (set[sts] > absidx)) then
46 | -- set new key or replace but only if the new absolute index is smaller
47 | set[sts] = absidx
48 | table.insert(list, sts)
49 | end
50 | -- Check for variables defined without assignments as local. It may
51 | -- generate redundant match but conditions in gsub's argument functions
52 | -- will make it get correct results.
53 | sts = string.match(buf[lineidx], 'local%s+([^=]+)')
54 | if sts then add_multi_names(sts) end
55 | -- matching variables initialized in generic for loop
56 | sts = string.match(buf[lineidx], 'for%s+(.*)%s+in')
57 | if sts then add_multi_names(sts) end
58 | -- function names matching
59 | sts = string.match(buf[lineidx], 'function%s+(' .. PATTERN_LUA_IDENTIFIER .. ')%s*%(')
60 | if sts and (not set[sts] or (set[sts] > absidx)) then
61 | -- set new key or replace but only if the new absolute index is smaller
62 | set[sts] = absidx
63 | table.insert(list, sts)
64 | end
65 | -- check for variables defined in functions statements
66 | sts = string.match(buf[lineidx], 'function%s*[^(]*%(([^)]+)%)')
67 | if sts then add_multi_names(sts) end
68 | end
69 | -- sort list using set's absolute indexes in comparator
70 | table.sort(list, function(v1, v2) return set[v1] < set[v2] end)
71 | return list
72 | end
73 |
74 |
75 | local function lua_omni_files()
76 | local list = {}
77 | -- first check LUA_OMNI shell variable
78 | string.gsub(vimutils.eval("$LUA_OMNI") or "", '([^ ;,]+)', function(s) table.insert(list, s) end)
79 | -- Next try b:lua_omni buffer variable or...
80 | if vimutils.eval('exists("b:lua_omni")') == 1 then
81 | string.gsub(vimutils.eval("b:lua_omni") or "", '([^ ;,]+)', function(s) table.insert(list, s) end)
82 | -- there isn't buffer's var check for global one.
83 | elseif vimutils.eval('exists("g:lua_omni")') == 1 then
84 | string.gsub(vimutils.eval("g:lua_omni") or "", '([^ ;,]+)', function(s) table.insert(list, s) end)
85 | end
86 | return list
87 | end
88 |
89 | local function completion_findstart()
90 | local line = vimutil.get_current_line()
91 | local col = vimutils.eval('col(".")')
92 | for i = col - 1, 1, -1 do
93 | local c = string.sub(line, i, i)
94 | -- "*" and "?" may be used by glob pattern
95 | if string.find(c, "[^a-zA-Z0-9_%.*?]") then
96 | return i
97 | end
98 | end
99 | return 0
100 | end
101 |
102 | local function escape_magic_chars(s)
103 | assert(type(s) == "string", "s must be a string!")
104 |
105 | return (string.gsub(s, '([().%+-*?[^$])', '%%%1'))
106 | end
107 |
108 | local function glob_to_pattern(s)
109 | assert(type(s) == "string", "s must be a string!")
110 |
111 | local pat = string.gsub(s, '.', function(c)
112 | if c == "*" then
113 | return '.-'
114 | elseif c == '?' then
115 | return '.'
116 | else return escape_magic_chars(c) end
117 | end)
118 | return pat
119 | end
120 |
121 | local function find_completions3(pat)
122 | local flat = {}
123 | local visited = {}
124 | local count = 0
125 |
126 | function flatten_recursively(t, lvl)
127 | lvl = lvl or ""
128 | -- just to be safe...
129 | if count > 10000 then return end
130 |
131 | for k, v in pairs(t) do
132 | -- for safe measure above
133 | count = count + 1
134 | if type(k) == "string" then
135 | table.insert(flat, #lvl > 0 and lvl .. "." .. k or k)
136 | end
137 | -- Inner table but do it recursively only when this run hasn't found it
138 | -- already.
139 | if type(v) == "table" and not visited[v] then
140 | -- check to avoid in recursive call
141 | visited[v] = true
142 | if type(k) == "string" then
143 | flatten_recursively(v, #lvl > 0 and lvl .. "." .. k or k)
144 | end
145 | -- Uncheck to allow to visit the same table but from different path.
146 | visited[v] = nil
147 | end
148 | end
149 | end
150 |
151 | -- start from _G
152 | flatten_recursively(_G)
153 |
154 | -- add paths from file(s)
155 | local pathfiles = lua_omni_files()
156 | for _, fname in ipairs(pathfiles) do
157 | -- there is chance that filename is invalid so guard for error
158 | local res, err = pcall(function()
159 | for line in io.lines(fname) do
160 | -- trim line
161 | line = string.gsub(line, "^%s-(%S.-)%s-$", "%1")
162 | -- put every line as path
163 | table.insert(flat, line)
164 | end
165 | end)
166 | -- If pcall above did catch error then echo about it.
167 | if not res then vimutils.command('echoerr "' .. tostring(err) .. '"') end
168 | end
169 |
170 | local res = {}
171 | -- match paths with pattern
172 | for _, v in ipairs(flat) do
173 | if string.match(v, pat) then table.insert(res, v) end
174 | end
175 |
176 | return res
177 | end
178 |
179 | local function complete_base_string(base)
180 | local t = {}
181 |
182 | if type(base) == "string" then
183 | -- completion using _G environment
184 | -- obsolete the new version seems better
185 | -- local comps = find_completions2(base)
186 | -- for _, v in pairs(comps) do
187 | -- table.insert(t, v[1])
188 | -- end
189 | -- table.sort(t)
190 |
191 | local sortbylen = false
192 | local pat = string.match(base, '^[%a_][%a%d_]*$')
193 | if pat then -- single word completion
194 | pat = ".*" .. escape_magic_chars(pat) .. ".*"
195 | sortbylen = true
196 | else -- full completion
197 | pat = glob_to_pattern(base)
198 | if not string.match(pat, '%.%*$') then pat = pat .. '.*' end
199 | end
200 | -- try to find something matching...
201 | t = find_completions3("^" .. pat .. "$")
202 | -- in a case no results were found try to expand dots
203 | if #t == 0 then
204 | pat = string.gsub(base, "%.", "[^.]*%%.") .. '.*'
205 | t = find_completions3("^" .. pat .. "$")
206 | end
207 |
208 | -- For single word matches it's more convenient to have results sorted by
209 | -- their string length.
210 | if sortbylen then
211 | table.sort(t, function(o1, o2)
212 | o1 = o1 or ""
213 | o2 = o2 or ""
214 | local l1 = string.len(o1)
215 | local l2 = string.len(o2)
216 | return l1 < l2
217 | end)
218 | else
219 | table.sort(t)
220 | end
221 |
222 | -- Always do variable assignments matching per buffer now as
223 | -- find_assigments will return most close assignments first.
224 | local assigments = {}
225 | for i, v in ipairs(find_assigments()) do
226 | if string.find(v, "^" .. base) then table.insert(assigments, v) end
227 | end
228 | t = merge_list(assigments, t)
229 | end
230 | return t
231 | end
232 |
233 |
234 |
235 | function complete.complete(findstart, base)
236 | -- this function is called twice - first for finding range in line to complete
237 | if findstart == 1 then
238 | vimutil.command("return " .. completion_findstart())
239 | else -- the second run - do proper complete
240 | local comps = complete_base_string(base)
241 | for i = 1, #comps do comps[i] = "'" .. comps[i] .. "'" end
242 | -- returning
243 | vimutil.command("return [" .. table.concat(comps, ", ") .. "]")
244 | end
245 | end
246 |
247 |
248 | return complete
249 |
--------------------------------------------------------------------------------
/lua/luavi/fold.lua:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wsdjeg/vim-lua/9eecdb726a73e0582fafbb3cde340d61b77b26a9/lua/luavi/fold.lua
--------------------------------------------------------------------------------
/lua/luavi/vimutils.lua:
--------------------------------------------------------------------------------
1 | vimutils = {}
2 |
3 | vimutils.constant = "hello"
4 |
5 | function table.has_key(test_table, test_key)
6 | for key, value in pairs(test_table) do
7 | if key == test_key then
8 | return true
9 | end
10 | end
11 | return false
12 | end
13 |
14 | local is_nvim = table.has_key(vim, 'api')
15 |
16 | function vimutils.command(cmd)
17 | if is_nvim then
18 | vim.api.nvim_command(cmd)
19 | else
20 | vim.command(cmd)
21 | end
22 | end
23 |
24 |
25 | function vimutils.eval(expr)
26 | if is_nvim then
27 | return vim.api.nvim_eval(expr)
28 | else
29 | return vim.eval(expr)
30 | end
31 | end
32 |
33 |
34 | function vimutils.get_current_line()
35 | if is_nvim then
36 | return vim.api.nvim_get_current_line()
37 | else
38 | return vim.window().line
39 | end
40 | end
41 |
42 | local buffer_metatables = {
43 | __index = function (self, line)
44 | return vim.api.nvim_buf_get_lines(self._bufnr, 0, -1, 0)[line]
45 | end,
46 | __len = function (self)
47 | return #vim.api.nvim_buf_get_lines(self._bufnr, 0, -1, 0)
48 | end
49 | }
50 |
51 | function vimutils.current_buffer()
52 | if is_nvim then
53 | local buffer = {}
54 | buffer._bufnr = vim.api.nvim_get_current_buf()
55 | setmetatable(buffer, buffer_metatables)
56 | return buffer
57 | else
58 | return vim.window().buffer
59 | end
60 | end
61 |
62 | function vimutils.current_linenr()
63 | return vimutils.eval('line(".")')
64 | end
65 |
66 | return vimutils
67 |
--------------------------------------------------------------------------------
/plugin/lua.vim:
--------------------------------------------------------------------------------
1 | ""
2 | " @section Introduction, intro
3 | " @order intro mappings
4 | " lua development plugin for vim and neovim.
5 |
6 |
7 | " check if Vim is in correct version and has Lua support
8 | if v:version < 703
9 | finish
10 | endif
11 | if !has('lua') && !has('nvim')
12 | finish
13 | endif
14 |
15 | if !has('nvim') && has('lua')
16 | " add lua path
17 | let s:plugin_dir = fnamemodify(expand(''), ':h:h').'\lua'
18 | let s:str = s:plugin_dir . '\?.lua;' . s:plugin_dir . '\?\init.lua;'
19 | lua package.path=vim.eval("s:str") .. package.path
20 | endif
21 |
22 | " save and reset compatibility options
23 | let s:save_cpo = &cpo
24 | set cpo&vim
25 |
26 | if exists('g:luacomplete_loaded')
27 | finish
28 | else
29 | let g:luacomplete_loaded = 1
30 | endif
31 |
32 | ""
33 | " Diable/Enable default mappings in lua buffer.
34 | " >
35 | " mode key functinon
36 | " normal fl print functin list
37 | " <
38 | let g:lua_default_mappings = 0
39 |
40 | ""
41 | " @section Mappings, mappings
42 | " luacomplete defined some mappings for lua buffer:
43 | " >
44 | " PrintFunctionList print functino list
45 | " WriteAndLuaFile wirte and luafile
46 | " <
47 |
48 | noremap