Skip to content

Commit 9af9b56

Browse files
authored
Merge pull request #914 from tsuyoshicho/update/map-sign-20210504
Update {map,sign}.{txt.jax}
2 parents f414fe0 + 62791a8 commit 9af9b56

File tree

4 files changed

+78
-13
lines changed

4 files changed

+78
-13
lines changed

doc/map.jax

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*map.txt* For Vim バージョン 8.2. Last change: 2020 Dec 10
1+
*map.txt* For Vim バージョン 8.2. Last change: 2021 Apr 23
22

33

44
VIMリファレンスマニュアル by Bram Moolenaar
@@ -238,9 +238,12 @@ Note: ":map <script>" と ":noremap <script>" の動作は同じです。コマ
238238
マップや短縮入力を定義するときに "<expr>" 引数を指定すると、引数が式 (スクリプ
239239
ト) として扱われます。マップが実行されたときに、式が評価され、その値が {rhs}
240240
として使われます。例: >
241-
:inoremap <expr> . InsertDot()
242-
InsertDot() 関数の戻り値が挿入されます。カーソルの前のテキストをチェックして、
243-
ある条件に一致するなら omni 補完を開始する、というようなことができます。
241+
:inoremap <expr> . <SID>InsertDot()
242+
s:InsertDot() 関数の戻り値が挿入されます。カーソルの前のテキストをチェックし
243+
て、ある条件に一致するなら omni 補完を開始する、というようなことができます。
244+
グローバルな名前空間の汚染を回避するには、スクリプトローカル関数を利用すること
245+
が望しいです。RHS内に <SID> を使ってマッピングが定義されたスクリプトを見付けら
246+
れるようにします。
244247

245248
短縮入力では、入力されて短縮入力展開のトリガーとなった文字が |v:char| にセット
246249
されます。これを使って {lhs} の展開方法を決めることもできます。自分で v:char
@@ -254,7 +257,20 @@ InsertDot() 関数の戻り値が挿入されます。カーソルの前のテ
254257
call popup_create(... arguments ...)
255258
return "\<Ignore>"
256259
endfunc
257-
nnoremap <expr> <F3> <Sid>OpenPopup()
260+
nnoremap <expr> <F3> <SID>OpenPopup()
261+
262+
また、前のコマンドが実行される前に、先行入力を探す時に式が評価されることがある
263+
ことを覚えておいてください。例: >
264+
func StoreColumn()
265+
let g:column = col('.')
266+
return 'x'
267+
endfunc
268+
nnoremap <expr> x StoreColumn()
269+
nmap ! f!x
270+
g:column に "f!" 実行前の値がある、つまり "x" が評価されるのが "f!" の実行前で
271+
あることに気付くでしょう。
272+
これは評価のマッピングの文字の前に <Ignore> を挿入することで解決できます: >
273+
nmap ! f!<Ignore>x
258274
259275
副作用に注意してください。式は文字の取得中に評価されるため、簡単に異常動作を起
260276
こせてしまいます。そのため、次のものは制限されます:

doc/sign.jax

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*sign.txt* For Vim バージョン 8.2. Last change: 2020 Oct 28
1+
*sign.txt* For Vim バージョン 8.2. Last change: 2021 Mar 07
22

33

44
VIMリファレンスマニュアル by Gordon Prieur
@@ -142,6 +142,9 @@
142142
texthl={group}
143143
テキスト部分に使用されるハイライトグループ。
144144

145+
例: >
146+
:sign define MySign text=>> texthl=Search linehl=DiffText
147+
<
145148

146149
(定義した)目印を削除する *:sign-undefine* *E155*
147150

@@ -151,7 +154,9 @@
151154
既に定義された目印を削除する。{name}という名前の目印がまだ設置
152155
されたままの場合はトラブルを引き起こす。
153156

154-
157+
例: >
158+
:sign undefine MySign
159+
<
155160

156161
(定義した)目印を一覧表示する *:sign-list* *E156*
157162

@@ -204,6 +209,10 @@
204209
上に同じ。バッファ番号を使用していることが異なる。buffer引数が
205210
与えられていない場合は、現在のバッファに目印を設置する。
206211

212+
例: >
213+
:sign place 10 line=99 name=sign3
214+
:sign place 10 line=99 name=sign3 buffer=3
215+
<
207216
*E885*
208217
:sign place {id} name={name} file={fname}
209218
ファイル{fname}{id}で設置された目印を、{name}で定義されてい
@@ -216,10 +225,17 @@
216225
ループの目印を選択することができる。任意の "priority={prio}"
217226
属性を使用して、既存の目印の優先順位を変更することができる。
218227

228+
例: >
229+
:sign place 23 name=sign1 file=/path/to/edit.py
230+
<
219231
:sign place {id} name={name} buffer={nr}
220232
上に同じ。バッファ番号を使用していることが異なる。buffer引数が
221233
与えられていない場合は、現在のバッファを使用する。
222234

235+
例: >
236+
:sign place 23 name=sign1
237+
:sign place 23 name=sign1 buffer=7
238+
<
223239

224240
(設置した)目印を解除する *:sign-unplace* *E159*
225241

en/map.txt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*map.txt* For Vim version 8.2. Last change: 2020 Dec 10
1+
*map.txt* For Vim version 8.2. Last change: 2021 Apr 23
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -244,9 +244,12 @@ have a look at |maparg()|.
244244
If the first argument to one of these commands is "<expr>" and it is used to
245245
define a new mapping or abbreviation, the argument is an expression. The
246246
expression is evaluated to obtain the {rhs} that is used. Example: >
247-
:inoremap <expr> . InsertDot()
248-
The result of the InsertDot() function will be inserted. It could check the
247+
:inoremap <expr> . <SID>InsertDot()
248+
The result of the s:InsertDot() function will be inserted. It could check the
249249
text before the cursor and start omni completion when some condition is met.
250+
Using a script-local function is preferred, to avoid polluting the global
251+
namespace. Use <SID> in the RHS so that the script that the mapping was
252+
defined in can be found.
250253

251254
For abbreviations |v:char| is set to the character that was typed to trigger
252255
the abbreviation. You can use this to decide how to expand the {lhs}. You
@@ -261,7 +264,21 @@ input. Example: >
261264
call popup_create(... arguments ...)
262265
return "\<Ignore>"
263266
endfunc
264-
nnoremap <expr> <F3> <Sid>OpenPopup()
267+
nnoremap <expr> <F3> <SID>OpenPopup()
268+
269+
Also, keep in mind that the expression may be evaluated when looking for
270+
typeahead, before the previous command has been executed. For example: >
271+
func StoreColumn()
272+
let g:column = col('.')
273+
return 'x'
274+
endfunc
275+
nnoremap <expr> x StoreColumn()
276+
nmap ! f!x
277+
You will notice that g:column has the value from before executing "f!",
278+
because "x" is evaluated before "f!" is executed.
279+
This can be solved by inserting <Ignore> before the character that is
280+
expression-mapped: >
281+
nmap ! f!<Ignore>x
265282
266283
Be very careful about side effects! The expression is evaluated while
267284
obtaining characters, you may very well make the command dysfunctional.

en/sign.txt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*sign.txt* For Vim version 8.2. Last change: 2020 Oct 28
1+
*sign.txt* For Vim version 8.2. Last change: 2021 Mar 07
22

33

44
VIM REFERENCE MANUAL by Gordon Prieur
@@ -146,6 +146,9 @@ See |sign_define()| for the equivalent Vim script function.
146146
texthl={group}
147147
Highlighting group used for the text item.
148148

149+
Example: >
150+
:sign define MySign text=>> texthl=Search linehl=DiffText
151+
<
149152

150153
DELETING A SIGN *:sign-undefine* *E155*
151154

@@ -155,7 +158,9 @@ See |sign_undefine()| for the equivalent Vim script function.
155158
Deletes a previously defined sign. If signs with this {name}
156159
are still placed this will cause trouble.
157160

158-
161+
Example: >
162+
:sign undefine MySign
163+
<
159164

160165
LISTING SIGNS *:sign-list* *E156*
161166

@@ -209,6 +214,10 @@ See |sign_place()| for the equivalent Vim script function.
209214
Same, but use buffer {nr}. If the buffer argument is not
210215
given, place the sign in the current buffer.
211216

217+
Example: >
218+
:sign place 10 line=99 name=sign3
219+
:sign place 10 line=99 name=sign3 buffer=3
220+
<
212221
*E885*
213222
:sign place {id} name={name} file={fname}
214223
Change the placed sign {id} in file {fname} to use the defined
@@ -221,10 +230,17 @@ See |sign_place()| for the equivalent Vim script function.
221230
"priority={prio}" attribute can be used to change the priority
222231
of an existing sign.
223232

233+
Example: >
234+
:sign place 23 name=sign1 file=/path/to/edit.py
235+
<
224236
:sign place {id} name={name} [buffer={nr}]
225237
Same, but use buffer {nr}. If the buffer argument is not
226238
given, use the current buffer.
227239

240+
Example: >
241+
:sign place 23 name=sign1
242+
:sign place 23 name=sign1 buffer=7
243+
<
228244

229245
REMOVING SIGNS *:sign-unplace* *E159*
230246

0 commit comments

Comments
 (0)