Recently I used Vim to write Lua code. I found that many Lua symbols cannot jump because of the unfriendly Lua support of ctags.
1) by default, the support for Lua by ctags is limited to the recognition function and does not support the definition of recognition constants.
2) if the function is defined by class: member_fun (...) and Class. member_fun (), the generated tags is in the following format:
Class: member_fun... omitted
Class. member_fun... omitted
Such a tags file cannot jump directly through member_fun. For example, the corresponding tag cannot be found through: tselect member_fun,
Unless you use tselect/^. * member_fun, but the regular expression is too inefficient, and many irrelevant matches will be found.
Therefore, this article studies how to generate the tags of Lua by other means. It mainly needs to solve two problems,
1) supports generating tags for constants/variables defined in Lua. to place too many variables indexed, the variable value must be a number. because almost all enumerated values/constant values are numbers.
2) The generated tags removes the class name prefix, such as "class:" and "class.", so that member_fun can directly jump to the past.
Solution:
Use the custom generation rules of ctags to generate the tags of The Lua file. At present, the requirements are basically met.
Ctags -- langdef = mylua -- langmap = mylua :. lua -- RegEx-mylua = "/^. * \ s * function \ s * (\ W +) :( \ W + ). * $/\ 2/F/"-- RegEx-mylua ="/^ \ s * (\ W +) \ s * = \ s * [0-9] +. * $/\ 1/e/"-- RegEx-mylu
A = "/^. * \ s * function \ s * (\ W + )\. (\ W + ). * $/\ 2/F/"-- RegEx-mylua ="/^. * \ s * function \ s * (\ W +) \ s *\(. * $/\ 1/f/"-- RegEx-mylua ="/^ \ s * (\ W +) \ s * = \ s *\{. * $/\ 1/e/"-- RegEx-mylua ="/^ \ s * module \ s +
\ "(\ W + )\". * $/\ 1/m, module/"-- RegEx-mylua ="/^ \ s * module \ s + \ "[a-zA-Z0-9. _] + \. (\ W + )\". * $/\ 1/m, module/"-- ages = mylua -- excmd = Number-R.
For more information about the rules of the tags generator in the ctags custom language, see the following article:
Http://www.cnblogs.com/jianyungsun/archive/2011/01/20/1940262.html
Http://helloxchen.itpub.net/category/42725/66614
Here is a brief description.
1) The preceding statement defines a new language, mylua. The file suffix supported by this language is *. Lua. It defines several regular expression replacement rules for generating tags from the source file,
Three of them are used to identify the function,
Two are used to identify constants.
Two modules
During processing, the ctags Scan each row of the Lua file and apply the above rules. If any rule matches, the matching results are added to the tags file.
2) Regular syntax uses Perl-Compatible Regular syntax by default, which is equivalent to grep-E or egrep.
3) -- excmd indicates the format of the generated tags file. number indicates the row number of the file where the tag is directly written. The best jump efficiency is that the generated tags file is also relatively small.
However, when the source file is changed, the row number does not match. You can change it to -- excmd = pattern to generate a jump point for regular matching. This is not affected by the modification of the source file.
4)-R. Generate tags for all Lua files in the current directory and recursive subdirectories
Example:
1. Lua file:
[Plain]View plaincopy
- Module "modules. submodule. mymodule1"
- Module "modules. mymodule2"
- Module "mymodule3"
- Object_ids = {
- Xx = 1,
- YY = 2,
- Msg_login= 8001,
- Msg_login2 = 8001, -- Logon
- }
- Function Hello ()
- Return Nil
- End
- Function XXX. Hello ()
- Return Nil
- End
- Function XXX: Hello ()
- Return Nil
- End
[Plain]View plaincopy
!_TAG_FILE_FORMAT2/extended format; --format=1 will not append ;" to lines/!_TAG_FILE_SORTED1/0=unsorted, 1=sorted, 2=foldcase/!_TAG_PROGRAM_AUTHORDarren Hiebert/[email protected]/!_TAG_PROGRAM_NAMEExuberant Ctags//!_TAG_PROGRAM_URLhttp://ctags.sourceforge.net/official site/!_TAG_PROGRAM_VERSION5.9~svn20110310//OBJECT_IDS1.lua4;"eXX1.lua5;"eYY1.lua6;"ehello1.lua11;"fhello1.lua14;"fhello1.lua17;"fmsg_login1.lua7;"emsg_login21.lua8;"emymodule11.lua1;"mmymodule21.lua2;"mmymodule31.lua3;"m
Note: The test passes in the following environment:
Linux:
Linux Ubuntu 2.6.32-21-generic
Ctags:
Exuberant ctags 5.8, copyright (c) 1996-2009 Darren Hiebert
Compiled: Mar 6 2010 15:35:10
Addresses: <[email protected]>, http://ctags.sourceforge.net
Optional compiled features: + wildcards, + RegEx
Convert to ctags-LUA-Modify