從技術上講,我在vim中使用Tagbar來查看文件的標籤,但這個問題通常適用於繁瑣的ctags,v5.8。我可以將範圍信息添加到用`--regex-<LANG>`在生成的ctags中生成的標籤嗎?
想我已經得到了下面的Python文件,把它foo.py
:
class foo:
def bar(baz):
print(baz)
讓我們在其上運行ctags
:ctags foo.py
。得到的tags
文件是這樣的:
!_ some ctags version/formatting stuff not worth pasting
bar foo.py /^ def bar(baz):$/;" m class:foo
foo foo.py /^class foo:$/;" c
我感興趣的位是第二線,class:foo
的最後一個字段。這是bar()
函數的範圍。如果我在vim中使用tagbar,它會相應地在該類中嵌套函數。
現在假設我在~/.ctags
中添加了對新語言的支持。其實,我加入支持這一傀儡文件:
class foo {
include bar
}
假設我用下面~/.ctags
參數。 「導入」正則表達式是醜陋(errr ...醜陋的人,正則表達式),但它得到足夠的做了這個例子的工作:
--langdef=puppet
--langmap=puppet:.pp
--regex-puppet=/^class[ \t]*([:a-zA-Z0-9_\-]+)[ \t]*/\1/c,class,classes/
--regex-puppet=/^\ \ \ \ include[ \t]*([:a-zA-Z0-9_\-]+)/\1/i,include,includes/
,在我tags
文件中生成以下標籤:
bar foo.pp /^ include bar$/;" i
foo foo.pp /^class foo {$/;" c
注意這兩行都沒有包含範圍信息。我的問題是:無論如何,我一般會構建--regex-puppet
參數或--regex-<LANG>
行來收集有關標籤範圍的信息?或許宣稱符合標準A的標籤總是要符合標準B的標籤的範圍 - 父母?
man ctags
表明沒有明確的方式來添加任意範圍的信息,但我可能俯瞰另一種解決方案(爲了強調稍微剪斷):
--regex-<LANG>=/regexp/replacement/[kind-spec/][flags]
Unless modified by flags, regexp is interpreted as a Posix extended regular expression. The replacement should expand for all matching lines to a non-empty string of
characters, or a warning message will be reported. An optional kind specifier for tags matching regexp may follow replacement, which will determine what kind of tag is
reported in the "kind" extension field (see TAG FILE FORMAT, below). The full form of kind-spec is in the form of a single letter, a comma, a name (without spaces), a
comma, a description, followed by a separator, which specify the short and long forms of the kind value and its textual description (displayed using --list-kinds). Either
the kind name and/or the description may be omitted. If kind-spec is omitted, it defaults to "r,regex". Finally, flags are one or more single-letter characters having the
following effect upon the interpretation of regexp:
b The pattern is interpreted as a Posix basic regular expression.
e The pattern is interpreted as a Posix extended regular expression (default).
i The regular expression is to be applied in a case-insensitive manner.