(before) and (after)2007年01月24日 12時07分03秒


display_line (before aabbc bc)
aab
ready  11:55:53
display_line (before aabbc d)
aabbc
ready  11:55:57
display_line (after aabbc bc)

ready  11:57:09
display_line (after aabbc d)

ready  11:57:12
display_line (after aabbc ab)
bc
ready  11:57:23

マクロ関数の動作に少々戸惑った。(before) や (after) が目的の文字列が、検索文字列中に見つからないときは空文字列が返されるのを期待していたからだ。(after) は空文字列を返し、(before) は全文を返す。

以下の様なコマンドマクロで、目的の文字が含まれている時にのみ動作させたい、コマンドがあった。


vi ss.cm
&begin_parameters
  selection option(selection),string,req,allow(a,b,c,ab,ac,bc,abc),=a
&end_parameters

!display_line &selection&x
!display_line (after &selection&x a) a
!display_line (after &selection&x b) b
!display_line (after &selection&x c) c

!display_line x&selection&
!display_line (before x&selection& a) a
!display_line (before x&selection& b) b
!display_line (before x&selection& c) c

実行結果は、このようになる。


ss -selection ab
abx
bx a
x b
 c
xab
x a
xa b
xab c

(after) の display_line を以下のような if 文に変えて、長さを点検することで、目的の文字列が含まれるかを検査する。


&if (length (after &selection&x a)) ^= 0