Wednesday, May 8, 2019

Re: searching one word containing # with touch *

On 07.05.19 21:19, Mathieu Roux wrote:
> 2) First i wanted to do it with "real tags" (with a tag-file made by
> ctag, and with ctrl-]), but if i understand good, it does not work like
> this.
> But if i understand good, i can press ctrl-] on the title of an article
> voir titre-de-larticle
> , to go to the (UNIQUE) article which has this title, after making tag-
> file with:
>
> !/bin/bash
> /usr/bin/ctags \
> -f ./tags \
> --langdef=diese \
> --language-force=diese \
> --regex-diese="/^Article: ([a-zA-Z0-9_]+)/\1/" \
> ./v
>
> No possibility to use "real tags" for 1). Is that correct?

How that fell short is not clear, but if ctags is unwieldy for
generating custom¹ tags, then there are alternatives. Around twenty
years ago I quickly cobbled this together:

#!/bin/sh

# awktags creates an elementary tags file for awk scripts

nawk '
/^function / {
printf("%s\t'$1'\t/^%s/\n",substr($2,1,index($2,"(")-1), \
substr($0,1,index($0,"(")))
}
' $1 > "tags_file"

That's not an endorsement for nawk - I use the gawk variant of awk
when it's available.

It's only necessary to generate a tags file which vim likes, see
:help tags-file-format

If tags for multiple text objects are desired, then just add another
/regex/ and another {...} action - job done. The awk manpage is very
extensive, but any text processing language would do. Heck, a keen
vimscripter could probably do it within vim, I'd wager. (Sorry, forget I
said that. :)

The format generated by the above one-liner is:

define_signal sdl/old/bin/sdlpp /^function define_signal(/
define_state sdl/old/bin/sdlpp /^function define_state(/
indelta sdl/old/bin/sdlpp /^function indelta(/
deferror sdl/old/bin/sdlpp /^function deferror(/

The fields; tag, file, ex-search; are separated by a single tab.
AFAIR vim was happy with that, and it's consistent with almost current
vim help.

If tags_file is not where vim expects, then its location can be
set in vim:

:set tags=/path/to/tags_file

Erik

¹ I've only used it to generate 'C' tags.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20190508074645.GB3499%40ratatosk.
For more options, visit https://groups.google.com/d/optout.

No comments: