extracting tags like vim help

116 views
Skip to first unread message

Javier Mediavilla Vegas

unread,
Jul 10, 2013, 9:33:04 AM7/10/13
to vim...@googlegroups.com
Hi,
I want to extrack tags from files like :helptags does. The problem is that :helptags can only work with .txt and .??x files. I want to do it for a file with any file extension.
I have tried with ctags and defining my own language extension. Nevertheless, when two tags are in the same line, ctags only matches the first one.

Example:
*E101* *E102*

ctags will extract "E101" without extracting E102. I think this should be able to be done with ctags because in C language you can define two functions in the same line

Example:
int add(void){return 5;} void some(void){}

and ctags extract both of them althouth they are in the same line.

The last change I take into account is to modify "helptags" function in the source code, that has ".txt" and "??x" files hardcoded.

Any idea how to achieve this without touching source code?

Thanks in advance,
Javier.

Tony Mechelynck

unread,
Jul 10, 2013, 10:10:16 AM7/10/13
to vim...@googlegroups.com
To use tags, you need to have a tags file containing the proper
information. For C and a number of other languages, Exuberant Ctags can
do it. I notice the following paragraph near the end of the manpage for
that particular ctags program:

Credit is also due Bram Moolenaar <Br...@vim.org>, the author of vim, who
has devoted so much of his time and energy both to developing the editor
as a service to others, and to helping the orphans of Uganda.

Just program as you normally would, then run Exuberant Ctags on your source.

For Vim helpfiles, Vim can also generate the tags file itself (see :help
:helptags). If you want to write documentation in any filetype that
suits your fancy, and still use |bars| and *stars* as in Vim
documentation, you may have to give appropriate options to Exuberant
Ctags to tell it that "these files are Vim helpfiles even though their
names don't end in .txt". If you didn't (yet) succeed at it, maybe
there's a parameter you missed. If you have a Unix-like (including
Linux, Cygwin, and, I think, Mac OSX) version of Exuberant Ctags, check
its manpage (and, first, run "ctags --version": if it is Exuberant
Ctags, it will proudly tell you).


Best regards,
Tony.
--
Reality is a cop-out for people who can't handle drugs.

Message has been deleted

Javier Mediavilla Vegas

unread,
Jul 10, 2013, 11:33:43 AM7/10/13
to vim...@googlegroups.com
Hi,
Maybe I messup things.
I want to extract tags in my documents. Tags are present in the format the vim help files are.

Example
*tag1* *tag2*

Here, there is two options to extract the tags and I have tested both of them.
1. :helptags. It is a vim built-in function to extract the tags but only works for ".txt" and ".??x" file extensions.
My files do not have that extension so I can't use it. I have searched for an option to change but I haven't found it.

2. ctags. It does not have language support for vim help. It does vim language but It is for vim script. I have created an extension to the language with this content (I call my new language MAN)

--langdef=MAN
--language-force=MAN
--regex-MAN=/\*([^\.\*][^\*]*)\*/\1/

This works fine. Extract the tags inside starts. But there is a problem with several tags in the same line. For this issue I put the C example. Not because I want to use ctags to extract C tags but because ctags can extract several C tags in the same line.

I use linux and exuberant ctags 5.9.

Regards,
Javier

Charles Campbell

unread,
Jul 10, 2013, 4:38:53 PM7/10/13
to vim...@googlegroups.com
Javier Mediavilla Vegas wrote:
> Hi,
> Maybe I messup things.
> I want to extract tags in my documents. Tags are present in the format the vim help files are.
>
> Example
> *tag1* *tag2*
>
> Here, there is two options to extract the tags and I have tested both of them.
> 1. :helptags. It is a vim built-in function to extract the tags but only works for ".txt" and ".??x" file extensions.
> My files do not have that extension so I can't use it. I have searched for an option to change but I haven't found it.
>
You can do it with helptags, if you write some script.

* move your help file to same YOURFILE.txt
* apply helptags
* move YOURFILE.txt back to YOURFILE.MAN
* change the resulting <tags> file, using sed: sed -e
's/\.txt/\.MAN/' tags

You could also do the substitute with vim itself if you'd prefer.

Regards,
C Campbell

Javier Mediavilla Vegas

unread,
Jul 11, 2013, 1:39:24 PM7/11/13
to vim...@googlegroups.com, charles.e...@nasa.gov
Hi,
I thought about that but I have files with different file extensions. I.e. .1android, .1androidae so I would have to map each old file name to new file name and rename, create tags, rename backwards and substitute with sed.

Instead, I have modified vim source. I have changed the tags generation so
* any file can be processed, regardless its extension
* tags containing spaces are allowed and extracted.

To do it, modify

ex_cmds.c

file and change
in line 6446 (aprox), in the else branch add this
// add english language when the extension is not recognize
lang[0] = 'e';
lang[1] = 'n';

in line 6532 (aprox), delete the line
STRCAT(NameBuff, ext);

in line 6641 (aprox), delete
*s == ' ' ||
from the if branch inside the loop

make to compile. And now, there it is a vim with :helptags that processes any file in a directory and allows tags with spaces (*tag space*)

Regards.

Tony Mechelynck

unread,
Jul 11, 2013, 2:46:27 PM7/11/13
to vim...@googlegroups.com
On 11/07/13 19:39, Javier Mediavilla Vegas wrote:
> Hi,
> I thought about that but I have files with different file extensions. I.e. .1android, .1androidae so I would have to map each old file name to new file name and rename, create tags, rename backwards and substitute with sed.
[...]

You can add the .txt on top of whatever filename you have (e.g.
Javier.Mediavilla.Vegas.1android →
Javier.Mediavilla.Vegas.1android.txt), then run helptags (for all of
them if within a single directory), then remove the extensions by a
trivial modification of what Dr. Chip had proposed.


Best regards,
Tony.
--
I used to be an agnostic, but now I'm not so sure.


Reply all
Reply to author
Forward
0 new messages