checking +eval feature
最近 $VIM 以下の script を読んでみてるんだけどそうするとたまに以下のような code を見かける。
if 1 " some codes endif
こりゃ何だと思ってたんだけど何かの拍子で eval の help ( :help eval.txt ) を眺めてたときに一番最初に
Note: Expression evaluation can be disabled at compile time. If this has been done, the features in this document are not available. See |+eval| and |no-eval-feature|.
(テケトー訳)式の評価は compile するときに無効化できるけどこの文書に書かれている機能は使用できなくなる。 |+eval| と |no-eval-feature| も読め。
Vim documentation: eval
と書かれていたのを見かけてとりあえず :help no-eval-feature 。すると
When the |+eval| feature was disabled at compile time, none of the expression evaluation commands are available. To prevent this from causing Vim scripts to generate all kinds of errors, the ":if" and ":endif" commands are still recognized, though the argument of the ":if" and everything between the ":if" and the matching ":endif" is ignored. Nesting of ":if" blocks is allowed, but only if the commands are at the start of the line. The ":else" command is not recognized.
(超訳) |+eval| 機能を compile 時に無効にすると式の評価を行う command は使えない。この場合 Vim script が error をおこさないように ":if" と ":endif" を認識し ":if" の引数と ":endif" までの間にあるものはすべて無視する。 ":if" の入れ子も許可されているが行の最初にあるもののみ適用される。 ":else" は認識されない。
Vim documentation: eval
と書かれていた。んーてことは件の code は +eval 機能が使えるかどうかの check をする code なわけか。確かに +eval が無効なら機能 check の常套句である if has('some feature')
は使えないわけだしな。
でここまで調べて plugin に ( もっというと template に ) これ仕込むべきか迷ったんだけど ( :help write-plugin にはここらへん全然書かれてない ) :help plugin したら普通に |+eval| 機能を無効化して compile した場合 plugin は使用できない
と書かれていたので別に悩むことじゃなかったみたい。うーんここらへんの情報まとまってないと混乱するよ。