0

I would like to make simple utility that opens tag under cursor in popup window introduced in recent vim version. Assuming I get word under cursor with command let l:word = expand("<cword>"), how would I find if tag with that name exists, in which file and on which line number? I know you can use taglist function, but I don't see line number there.

Thanks, Vjekoslav

2 Answers 2

1

taglist() is not bound to know the line number at all. Rather it's a command to locate the tag stored in cmd field.

As a special case, cmd could also contain line number, as number is a valid Ex command too. But that depends on how the tag list was generated.

5
  • Is there a generic way to extract line number from cmd?
    – Vjekoslav
    Nov 25, 2020 at 8:42
  • @Vjekoslav What do you mean by a "generic way"? It could be a number or not number at all.
    – Matt
    Nov 25, 2020 at 9:12
  • But what happens when cmd its not a number? Vim has to evaluate it and then make a jump to a location (file + line). I'm interested in how to obtain that information. I quess I could always let the vim handle that part, jump to location, record it, then go back and do my thing. But that seems extra work...
    – Vjekoslav
    Nov 25, 2020 at 9:25
  • @Vjekoslav From :h taglist() "The ex-command "cmd" can be either an ex search pattern, a line number or a line number followed by a byte number." Is it a problem to do runtime-checking?
    – Matt
    Nov 25, 2020 at 9:48
  • Its not a problem. I just checked ccomplete.vim and it contains some examples of parsing cmd. But its a lot more code than I expected :(. I might end up using method I mentioned above. Let the vim do the jump, record, jump back. Use recorded info.
    – Vjekoslav
    Nov 25, 2020 at 10:24
0

Could use ex command to extract the line number:

system(printf("ex -u NONE %s <<< 'set nomagic | %s=' ", file, cmd))
1
  • 1
    There's a lot in that one-liner. I would appreciate it very much if you could explain what's going on and how it solves the question. Thanks in advance.
    – Friedrich
    Nov 2, 2023 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.