-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommands.texi
4329 lines (3859 loc) · 209 KB
/
commands.texi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@c -*-texinfo-*-
@c This is part of the GNU Emacs Lisp Reference Manual.
@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998 Free Software Foundation, Inc.
@c See the file elisp.texi for copying conditions.
@setfilename ../info/commands
@node Command Loop, Keymaps, Minibuffers, Top
@c @chapter Command Loop
@chapter コマンドループ
@c @cindex editor command loop
@c @cindex command loop
@cindex エディタコマンドループ
@cindex コマンドループ
@c When you run Emacs, it enters the @dfn{editor command loop} almost
@c immediately. This loop reads key sequences, executes their definitions,
@c and displays the results. In this chapter, we describe how these things
@c are done, and the subroutines that allow Lisp programs to do them.
読者がEmacsを起動すると、Emacsはほぼただちに@dfn{エディタコマンドループ}
(editor command loop)に入ります。
このループは、キー列を読み取り、それらの定義を実行し、結果を表示します。
本章では、これがどのように行われるのか、および、
Lispプログラムからこれを行うためのサブルーティンについて述べます。
@menu
* Command Overview:: How the command loop reads commands.
* Defining Commands:: Specifying how a function should read arguments.
* Interactive Call:: Calling a command, so that it will read arguments.
* Command Loop Info:: Variables set by the command loop for you to examine.
* Input Events:: What input looks like when you read it.
* Reading Input:: How to read input events from the keyboard or mouse.
* Special Events:: Events processed immediately and individually.
* Waiting:: Waiting for user input or elapsed time.
* Quitting:: How @kbd{C-g} works. How to catch or defer quitting.
* Prefix Command Arguments:: How the commands to set prefix args work.
* Recursive Editing:: Entering a recursive edit,
and why you usually shouldn't.
* Disabling Commands:: How the command loop handles disabled commands.
* Command History:: How the command history is set up, and how accessed.
* Keyboard Macros:: How keyboard macros are implemented.
@end menu
@node Command Overview
@c @section Command Loop Overview
@section コマンドループの概要
@c The first thing the command loop must do is read a key sequence, which
@c is a sequence of events that translates into a command. It does this by
@c calling the function @code{read-key-sequence}. Your Lisp code can also
@c call this function (@pxref{Key Sequence Input}). Lisp programs can also
@c do input at a lower level with @code{read-event} (@pxref{Reading One
@c Event}) or discard pending input with @code{discard-input}
@c (@pxref{Event Input Misc}).
コマンドループがまず始めに行うことはキー列、
つまり、コマンドへ変換されるイベント列を読むことです。
これには関数@code{read-key-sequence}を呼び出します。
読者のLispコードでもこの関数を呼び出せます(@pxref{Key Sequence Input})。
Lispプログラムでは、@code{read-event}(@pxref{Reading One Event})で
低レベルの入力を行ったり、
@code{discard-input}(@pxref{Event Input Misc})で
処理待ち中の入力を破棄できます。
@c The key sequence is translated into a command through the currently
@c active keymaps. @xref{Key Lookup}, for information on how this is done.
@c The result should be a keyboard macro or an interactively callable
@c function. If the key is @kbd{M-x}, then it reads the name of another
@c command, which it then calls. This is done by the command
@c @code{execute-extended-command} (@pxref{Interactive Call}).
キー列は現在活性なキーマップを介してコマンドに変換されます。
この処理方法については@xref{Key Lookup}。
この結果は、キーボードマクロであるか、
対話的に呼び出し可能な関数であるはずです。
キーが@kbd{M-x}であると、別のコマンドの名前を読み取り、
そのコマンドを呼び出します。
これはコマンド@code{execute-extended-command}(@pxref{Interactive Call})で
処理されます。
@c To execute a command requires first reading the arguments for it.
@c This is done by calling @code{command-execute} (@pxref{Interactive
@c Call}). For commands written in Lisp, the @code{interactive}
@c specification says how to read the arguments. This may use the prefix
@c argument (@pxref{Prefix Command Arguments}) or may read with prompting
@c in the minibuffer (@pxref{Minibuffers}). For example, the command
@c @code{find-file} has an @code{interactive} specification which says to
@c read a file name using the minibuffer. The command's function body does
@c not use the minibuffer; if you call this command from Lisp code as a
@c function, you must supply the file name string as an ordinary Lisp
@c function argument.
コマンドを実行するには、まず、その引数を読む必要があります。
これは、@code{command-execute}(@pxref{Interactive Call})を呼び出して
行います。
Lispで書かれたコマンドでは、
@code{interactive}指定が引数の読み方を指示します。
前置引数(@pxref{Prefix Command Arguments})を使ったり、
プロンプトを表示してミニバッファ(@pxref{Minibuffers})から読みます。
たとえば、コマンド@code{find-file}には、
ミニバッファからファイル名を読むことを指示した
@code{interactive}指定があります。
コマンドの関数本体ではミニバッファを使いません。
このコマンドをLispコードから関数として呼び出す場合、
通常のLisp関数の引数としてファイル名文字列を指定する必要があります。
@c If the command is a string or vector (i.e., a keyboard macro) then
@c @code{execute-kbd-macro} is used to execute it. You can call this
@c function yourself (@pxref{Keyboard Macros}).
コマンドが文字列やベクトル(つまり、キーボードマクロ)である場合、
@code{execute-kbd-macro}を用いてそれらを実行します。
読者自身がこの関数を呼び出してもかまいません(@pxref{Keyboard Macros})。
@c To terminate the execution of a running command, type @kbd{C-g}. This
@c character causes @dfn{quitting} (@pxref{Quitting}).
動作中のコマンドの実行を止めるには、@kbd{C-g}を打ちます。
この文字は@dfn{中断}(quitting)を引き起こします(@pxref{Quitting})。
@defvar pre-command-hook
@c The editor command loop runs this normal hook before each command. At
@c that time, @code{this-command} contains the command that is about to
@c run, and @code{last-command} describes the previous command.
@c @xref{Hooks}.
エディタコマンドループは、各コマンドのまえにこのノーマルフックを実行する。
その際、@code{this-command}にはこれから実行するコマンドが保持され、
@code{last-command}には直前のコマンドがある。
@pxref{Hooks}。
@end defvar
@defvar post-command-hook
@c The editor command loop runs this normal hook after each command
@c (including commands terminated prematurely by quitting or by errors),
@c and also when the command loop is first entered. At that time,
@c @code{this-command} describes the command that just ran, and
@c @code{last-command} describes the command before that. @xref{Hooks}.
エディタコマンドループは、
(中断やエラーのために完了しなかったコマンドを含めて)
各コマンドのあとにこのノーマルフックを実行する。
初めてコマンドループに入ったときにも実行する。
その際、@code{this-command}には実行し終えたばかりのコマンドがあり、
@code{last-command}にはその前のコマンドがある。
@pxref{Hooks}。
@end defvar
@c Quitting is suppressed while running @code{pre-command-hook} and
@c @code{post-command-hook}. If an error happens while executing one of
@c these hooks, it terminates execution of the hook, and clears the hook
@c variable to @code{nil} so as to prevent an infinite loop of errors.
@code{pre-command-hook}や@code{post-command-hook}の実行中は、
中断を禁止します。
これらのフックの1つを実行中にエラーが起きると、
エラーの無限ループを防ぐために、
フックの実行を終了しフック変数を@code{nil}にします。
@node Defining Commands
@c @section Defining Commands
@section コマンドの定義
@c @cindex defining commands
@c @cindex commands, defining
@c @cindex functions, making them interactive
@c @cindex interactive function
@cindex コマンドの定義
@cindex 定義、コマンド
@cindex 関数、対話的にする
@cindex 対話的関数
@c A Lisp function becomes a command when its body contains, at top
@c level, a form that calls the special form @code{interactive}. This
@c form does nothing when actually executed, but its presence serves as a
@c flag to indicate that interactive calling is permitted. Its argument
@c controls the reading of arguments for an interactive call.
Lisp関数の本体に、スペシャルフォーム@code{interactive}を呼び出す
フォームがトップレベルにあると、Lisp関数はコマンドになります。
このフォームは実際に呼び出されてもなにもしませんが、
このフォームがあることで、対話的に呼び出せることを表します。
その引数が、対話的呼び出しにおける引数の読み方を制御します。
@menu
* Using Interactive:: General rules for @code{interactive}.
* Interactive Codes:: The standard letter-codes for reading arguments
in various ways.
* Interactive Examples:: Examples of how to read interactive arguments.
@end menu
@node Using Interactive
@c @subsection Using @code{interactive}
@subsection @code{interactive}の使い方
@c This section describes how to write the @code{interactive} form that
@c makes a Lisp function an interactively-callable command.
本節では、Lisp関数を対話的に呼び出し可能なコマンドにするフォーム
@code{interactive}の書き方について述べます。
@defspec interactive arg-descriptor
@c @cindex argument descriptors
@cindex 引数記述子
@c This special form declares that the function in which it appears is a
@c command, and that it may therefore be called interactively (via
@c @kbd{M-x} or by entering a key sequence bound to it). The argument
@c @var{arg-descriptor} declares how to compute the arguments to the
@c command when the command is called interactively.
このスペシャルフォームは、これを含む関数がコマンドであり、
(@kbd{M-x}や当該関数にバインドしたキー列を入力することで)
対話的に呼び出せることを宣言する。
引数@var{arg-descriptor}は、コマンドを対話的に呼び出したときに
コマンドに対する引数の計算方法を宣言する。
@c A command may be called from Lisp programs like any other function, but
@c then the caller supplies the arguments and @var{arg-descriptor} has no
@c effect.
他の関数と同様に、コマンドはLispプログラムからも呼び出せるが、
その場合、呼び出し側が引数を渡し、@var{arg-descriptor}にはなんの効果もない。
@c The @code{interactive} form has its effect because the command loop
@c (actually, its subroutine @code{call-interactively}) scans through the
@c function definition looking for it, before calling the function. Once
@c the function is called, all its body forms including the
@c @code{interactive} form are executed, but at this time
@c @code{interactive} simply returns @code{nil} without even evaluating its
@c argument.
フォーム@code{interactive}が効果を発揮するのは、
コマンドループ(実際にはサブルーティン@code{call-interactively})が
関数を呼び出すまえに関数定義を走査してこのフォームを探すからである。
関数が呼び出されると、フォーム@code{interactive}を含めて
その本体のフォームが実行されるが、そのとき、
@code{interactive}は引数を評価せずに単に@code{nil}を返す。
@end defspec
@c There are three possibilities for the argument @var{arg-descriptor}:
引数@var{arg-descriptor}には3つの可能性があります。
@itemize @bullet
@item
@c It may be omitted or @code{nil}; then the command is called with no
@c arguments. This leads quickly to an error if the command requires one
@c or more arguments.
省略するか@code{nil}。
この場合、コマンドは引数なしで呼ばれる。
コマンドが1つ以上の引数を必要とする場合、これはただちにエラーになる。
@item
@c It may be a Lisp expression that is not a string; then it should be a
@c form that is evaluated to get a list of arguments to pass to the
@c command.
@c @cindex argument evaluation form
文字列ではないLisp式。
この場合、それはフォームであり、
コマンドに渡す引数リストを得るために評価される。
@cindex 引数評価フォーム
@c If this expression reads keyboard input (this includes using the
@c minibuffer), keep in mind that the integer value of point or the mark
@c before reading input may be incorrect after reading input. This is
@c because the current buffer may be receiving subprocess output;
@c if subprocess output arrives while the command is waiting for input,
@c it could relocate point and the mark.
この式が(ミニバッファを使うことを含めて)キーボード入力を読む場合には、
入力を読むまえのポイントの整数値やマークは、
入力を読んだあとでは正しくない可能性があることに留意すること。
カレントバッファがサブプロセスの出力を受け取る可能性があるからである。
コマンドが入力を待っているあいだにサブプロセスの出力が到着すると、
ポイントやマークを再配置する可能性がある。
@c Here's an example of what @emph{not} to do:
しては@emph{いけない}ことの例を示す。
@smallexample
(interactive
(list (region-beginning) (region-end)
(read-string "Foo: " nil 'my-history)))
@end smallexample
@noindent
@c Here's how to avoid the problem, by examining point and the mark only
@c after reading the keyboard input:
キーボード入力を読み終えてからポイントやマークを調べることで、
問題を回避する。
@smallexample
(interactive
(let ((string (read-string "Foo: " nil 'my-history)))
(list (region-beginning) (region-end) string)))
@end smallexample
@item
@c @cindex argument prompt
@cindex 引数プロンプト
@c It may be a string; then its contents should consist of a code character
@c followed by a prompt (which some code characters use and some ignore).
@c The prompt ends either with the end of the string or with a newline.
@c Here is a simple example:
文字列。
この場合、その内容は、コード文字とそれに続く
(コード文字によっては使ったり無視する)プロンプトから成ること。
プロンプトは、文字列の終りか改行で終る。
簡単な例を示す。
@smallexample
(interactive "bFrobnicate buffer: ")
@end smallexample
@noindent
@c The code letter @samp{b} says to read the name of an existing buffer,
@c with completion. The buffer name is the sole argument passed to the
@c command. The rest of the string is a prompt.
コード文字@samp{b}は、補完を用いて既存のバッファ名を読むことを指示する。
バッファ名は、コマンドに渡される唯一の引数である。
文字列の残りはプロンプトである。
@c If there is a newline character in the string, it terminates the prompt.
@c If the string does not end there, then the rest of the string should
@c contain another code character and prompt, specifying another argument.
@c You can specify any number of arguments in this way.
文字列内に改行文字があると、それはプロンプトを終える。
その部分で文字列が終らないときには、
文字列の残りの部分には、別の引数を指定するコード文字やプロンプトがある。
このようにして、何個の引数でも指定できる。
@c @c Emacs 19 feature
@c The prompt string can use @samp{%} to include previous argument values
@c (starting with the first argument) in the prompt. This is done using
@c @code{format} (@pxref{Formatting Strings}). For example, here is how
@c you could read the name of an existing buffer followed by a new name to
@c give to that buffer:
プロンプトの文字列では、プロンプト内の(第1引数から始まる)
まえの引数値を含めるために@samp{%}を使える。
これは@code{format}(@pxref{Formatting Strings})を用いて行う。
たとえば、既存バッファの名前を読み、
続けてそのバッファに与える新たな名前を読むにはつぎのようにする。
@smallexample
@group
(interactive "bBuffer to rename: \nsRename buffer %s to: ")
@end group
@end smallexample
@c @cindex @samp{*} in interactive
@c @cindex read-only buffers in interactive
@cindex @samp{*}、対話指定
@cindex 読み出し専用バッファ、対話指定
@c If the first character in the string is @samp{*}, then an error is
@c signaled if the buffer is read-only.
文字列の最初の文字が@samp{*}である場合、
バッファが読み出し専用であるとエラーを通知する。
@c @cindex @samp{@@} in interactive
@cindex @samp{@@}、対話指定
@c @c Emacs 19 feature
@c If the first character in the string is @samp{@@}, and if the key
@c sequence used to invoke the command includes any mouse events, then
@c the window associated with the first of those events is selected
@c before the command is run.
文字列の最初の文字が@samp{@@}であり、
コマンドを起動したキー列にマウスイベントが含まれる場合、
コマンドを実行するまえに
それらのイベントの最初のものに関連したウィンドウを選択する。
@c You can use @samp{*} and @samp{@@} together; the order does not matter.
@c Actual reading of arguments is controlled by the rest of the prompt
@c string (starting with the first character that is not @samp{*} or
@c @samp{@@}).
@samp{*}と@samp{@@}は同時に使え、その順序は関係ない。
引数の実際の読み取りはプロンプトの
(@samp{*}でも@samp{@@}でもない最初の文字で始まる)残りの部分で制御される。
@end itemize
@node Interactive Codes
@comment node-name, next, previous, up
@c @subsection Code Characters for @code{interactive}
@subsection @code{interactive}のコード文字
@c @cindex interactive code description
@c @cindex description for interactive codes
@c @cindex codes, interactive, description of
@c @cindex characters for interactive codes
@cindex 対話コード記述子
@cindex 記述子、対話指定のコード
@cindex コード、対話指定、記述子
@cindex 文字、対話指定のコード
@c The code character descriptions below contain a number of key words,
@c defined here as follows:
以下に述べるコード文字の説明では、
つぎに定義するいくつかのキーワードを含みます。
@table @b
@c @item Completion
@item 「補完」
@c @cindex interactive completion
@cindex 補完、対話指定
@c Provide completion. @key{TAB}, @key{SPC}, and @key{RET} perform name
@c completion because the argument is read using @code{completing-read}
@c (@pxref{Completion}). @kbd{?} displays a list of possible completions.
補完を使える。
@code{completing-read}を使って引数を読むため、
@key{TAB}、@key{SPC}、@key{RET}は名前を補完する
(@pxref{Completion})。
@kbd{?}は補完候補のリストを表示する。
@c @item Existing
@item 「既存」
@c Require the name of an existing object. An invalid name is not
@c accepted; the commands to exit the minibuffer do not exit if the current
@c input is not valid.
既存オブジェクトの名前を必要とする。
不正な名前は受け付けない。
現在の入力が正しくないとミニバッファから抜けるコマンドは動作しない。
@c @item Default
@item 「デフォルト」
@c @cindex default argument string
@cindex デフォルト引数文字列
@c A default value of some sort is used if the user enters no text in the
@c minibuffer. The default depends on the code character.
ミニバッファにユーザーがなにもテキストを入力しないときに
使われるなんらかのデフォルト値。
デフォルトはコード文字に依存する。
@c @item No I/O
@item 「入出力なし」
@c This code letter computes an argument without reading any input.
@c Therefore, it does not use a prompt string, and any prompt string you
@c supply is ignored.
このコード文字は、入力をまったく読まずに引数を計算する。
したがって、プロンプト文字列を使わず、
読者が指定したプロンプト文字列は無視する。
@c Even though the code letter doesn't use a prompt string, you must follow
@c it with a newline if it is not the last code character in the string.
コード文字はプロンプト文字列を使わないが、
この文字が文字列の最後の文字でない場合には改行を続けること。
@c @item Prompt
@item 「プロンプト」
@c A prompt immediately follows the code character. The prompt ends either
@c with the end of the string or with a newline.
コード文字の直後にプロンプトが続く。
プロンプトは文字列の終りか改行で終る。
@c @item Special
@item 「スペシャル」
@c This code character is meaningful only at the beginning of the
@c interactive string, and it does not look for a prompt or a newline.
@c It is a single, isolated character.
このコード文字は、対話指定文字列の先頭でのみ意味を持ち、
プロンプトや改行を必要としない。
これは1つの孤立した文字である。
@end table
@c @cindex reading interactive arguments
@cindex 読み取り、対話引数
@c Here are the code character descriptions for use with @code{interactive}:
以下に、@code{interactive}に使うコード文字を説明します。
@table @samp
@item *
@c Signal an error if the current buffer is read-only. Special.
カレントバッファが読み出し専用であるとエラーを通知する。
「スペシャル」。
@item @@
@c Select the window mentioned in the first mouse event in the key
@c sequence that invoked this command. Special.
このコマンドを起動したキー列の最初のマウスイベントが表すウィンドウを選択する。
「スペシャル」。
@item a
@c A function name (i.e., a symbol satisfying @code{fboundp}). Existing,
@c Completion, Prompt.
関数名(つまり、@code{fboundp}を満たすシンボル)。
「既存」、「補完」、「プロンプト」。
@item b
@c The name of an existing buffer. By default, uses the name of the
@c current buffer (@pxref{Buffers}). Existing, Completion, Default,
@c Prompt.
既存バッファの名前。
デフォルトでは、カレントバッファ(@pxref{Buffers})の名前を使う。
「既存」、「補完」、「デフォルト」、「プロンプト」。
@item B
@c A buffer name. The buffer need not exist. By default, uses the name of
@c a recently used buffer other than the current buffer. Completion,
@c Default, Prompt.
バッファ名。
バッファが既存である必要はない。
デフォルトでは、カレントバッファ以外の最近使ったバッファの名前を使う。
「補完」、「デフォルト」、「プロンプト」。
@item c
@c A character. The cursor does not move into the echo area. Prompt.
文字。
カーソルはエコー領域には移動しない。
「プロンプト」。
@item C
@c A command name (i.e., a symbol satisfying @code{commandp}). Existing,
@c Completion, Prompt.
コマンド名(つまり、@code{commandp}を満たすシンボル)。
「既存」、「補完」、「プロンプト」。
@item d
@c @cindex position argument
@cindex 位置引数
@c The position of point, as an integer (@pxref{Point}). No I/O.
整数としてのポイント位置(@pxref{Point})。
「入出力なし」。
@item D
@c A directory name. The default is the current default directory of the
@c current buffer, @code{default-directory} (@pxref{System Environment}).
@c Existing, Completion, Default, Prompt.
ディレクトリ名。
デフォルトは、カレントバッファのカレントデフォルトディレクトリ
@code{default-directory}(@pxref{System Environment})。
「既存」、「補完」、「デフォルト」、「プロンプト」。
@item e
@c The first or next mouse event in the key sequence that invoked the command.
@c More precisely, @samp{e} gets events that are lists, so you can look at
@c the data in the lists. @xref{Input Events}. No I/O.
コマンドを起動したキー列の最初やつぎのマウスイベント。
より正確には、@samp{e}はリストであるイベントを取得するので、
読者はリスト内のデータを調べられる。
@pxref{Input Events}。
「入出力なし」。
@c You can use @samp{e} more than once in a single command's interactive
@c specification. If the key sequence that invoked the command has
@c @var{n} events that are lists, the @var{n}th @samp{e} provides the
@c @var{n}th such event. Events that are not lists, such as function keys
@c and @sc{ASCII} characters, do not count where @samp{e} is concerned.
1つのコマンドの対話指定で複数回@samp{e}を使える。
コマンドを起動したキー列が@var{n}個のリストであるイベントである場合、
@var{n}番目の@samp{e}は、@var{n}番目のそのようなイベントを与える。
@samp{e}では、
ファンクションキーや@sc{ASCII}文字などのリストでないイベントは数えない。
@item f
@c A file name of an existing file (@pxref{File Names}). The default
@c directory is @code{default-directory}. Existing, Completion, Default,
@c Prompt.
既存ファイルの名前(@pxref{File Names})。
デフォルトディレクトリは@code{default-directory}。
「既存」、「補完」、「デフォルト」、「プロンプト」。
@item F
@c A file name. The file need not exist. Completion, Default, Prompt.
ファイル名。
ファイルが既存である必要はない。
「補完」、「デフォルト」、「プロンプト」。
@item i
@c An irrelevant argument. This code always supplies @code{nil} as
@c the argument's value. No I/O.
無関係な引数。
このコードは、引数の値につねに@code{nil}を与える。
「入出力なし」。
@item k
@c A key sequence (@pxref{Keymap Terminology}). This keeps reading events
@c until a command (or undefined command) is found in the current key
@c maps. The key sequence argument is represented as a string or vector.
@c The cursor does not move into the echo area. Prompt.
キー列(@pxref{Keymap Terminology})。
現在のキーマップにおいてコマンドがみつかる(あるいは未定義コマンド)まで
イベントを読み続ける。
キー列引数は、文字列かベクトルとして表現される。
カーソルはエコー領域には移動しない。
「プロンプト」。
@c This kind of input is used by commands such as @code{describe-key} and
@c @code{global-set-key}.
この種の入力は、@code{describe-key}や@code{global-set-key}などの
コマンドで使われる。
@item K
@c A key sequence, whose definition you intend to change. This works like
@c @samp{k}, except that it suppresses, for the last input event in the key
@c sequence, the conversions that are normally used (when necessary) to
@c convert an undefined key into a defined one.
キー列であり、読者がその定義を変更することを意図している。
これは@samp{k}と同様に動作するが、
キー列の最後の入力イベントに対しては、
未定義キーを定義済みのものに変換するために(必要なときに)普通使われる
変換処理を抑制する。
@item m
@c @cindex marker argument
@cindex マーク引数
@c The position of the mark, as an integer. No I/O.
整数としてのマーク位置。
「入出力なし」。
@item M
@c Arbitrary text, read in the minibuffer using the current buffer's input
@c method, and returned as a string (@pxref{Input Methods,,, emacs, The GNU
@c Emacs Manual}). Prompt.
カレントバッファの入力方式を用いてミニバッファで読んだ任意のテキスト。
文字列として返す
(@pxref{Input Methods,, 入力方式, emacs, GNU Emacs マニュアル})。
「プロンプト」。
@item n
@c A number read with the minibuffer. If the input is not a number, the
@c user is asked to try again. The prefix argument, if any, is not used.
@c Prompt.
ミニバッファで読んだ数。
入力が数でないと、ユーザーに再入力を促す。
もし前置引数があってもそれは使わない。
「プロンプト」。
@item N
@c @cindex raw prefix argument usage
@cindex 生の前置引数の使い方
@c The numeric prefix argument; but if there is no prefix argument, read a
@c number as with @kbd{n}. Requires a number. @xref{Prefix Command
@c Arguments}. Prompt.
数値前置引数。
前置引数がなければ、@kbd{n}で数を読む。
数を必要とする。
@pxref{Prefix Command Arguments}。
「プロンプト」。
@item p
@c @cindex numeric prefix argument usage
@cindex 数値前置引数の使い方
@c The numeric prefix argument. (Note that this @samp{p} is lower case.)
@c No I/O.
数値前置引数。
(この@samp{p}は小文字。)
「入出力なし」。
@item P
@c The raw prefix argument. (Note that this @samp{P} is upper case.) No
@c I/O.
生の前置引数。
(この@samp{P}は大文字。)
「入出力なし」。
@item r
@c @cindex region argument
@cindex リージョン引数
@c Point and the mark, as two numeric arguments, smallest first. This is
@c the only code letter that specifies two successive arguments rather than
@c one. No I/O.
2つの数値引数としてのポイントとマーク。
小さいほうが先にくる。
これは、1つではなく2つの連続した引数を指定する唯一のコード文字。
「入出力なし」。
@item s
@c Arbitrary text, read in the minibuffer and returned as a string
@c (@pxref{Text from Minibuffer}). Terminate the input with either
@c @kbd{C-j} or @key{RET}. (@kbd{C-q} may be used to include either of
@c these characters in the input.) Prompt.
ミニバッファで読んだ任意のテキスト。
文字列として返す(@pxref{Text from Minibuffer})。
@kbd{C-j}か@key{RET}で入力を終える。
(これらの文字を入力に含めるには@kbd{C-q}を使う。)
「プロンプト」。
@item S
@c An interned symbol whose name is read in the minibuffer. Any whitespace
@c character terminates the input. (Use @kbd{C-q} to include whitespace in
@c the string.) Other characters that normally terminate a symbol (e.g.,
@c parentheses and brackets) do not do so here. Prompt.
ミニバッファで読んだ名前をインターンしたシンボル。
白文字で入力を終える。
(文字列に白文字を含めるには@kbd{C-q}を使う。)
(丸括弧や角括弧などの)通常はシンボルを終える他の文字は、
ここではシンボルを終端しない。
「プロンプト」。
@item v
@c A variable declared to be a user option (i.e., satisfying the predicate
@c @code{user-variable-p}). @xref{High-Level Completion}. Existing,
@c Completion, Prompt.
ユーザーオプションと宣言された変数
(つまり、述語@code{user-variable-p}を満たす)。
@pxref{High-Level Completion}。
「既存」、「補完」、「プロンプト」。
@item x
@c A Lisp object, specified with its read syntax, terminated with a
@c @kbd{C-j} or @key{RET}. The object is not evaluated. @xref{Object from
@c Minibuffer}. Prompt.
入力構文で表されたLispオブジェクト。
@kbd{C-j}か@key{RET}で終える。
オブジェクトは評価しない。
@pxref{Object from Minibuffer}。
「プロンプト」。
@item X
@c @cindex evaluated expression argument
@cindex 評価済みの式引数
@c A Lisp form is read as with @kbd{x}, but then evaluated so that its
@c value becomes the argument for the command. Prompt.
@kbd{x}のようにLispフォームを読むが、評価しその値がコマンドの引数になる。
「プロンプト」。
@item z
@c A coding system name (a symbol). If the user enters null input, the
@c argument value is @code{nil}. @xref{Coding Systems}. Completion,
@c Existing, Prompt.
コーディングシステム名(シンボル)。
ユーザーの入力が空であると、引数の値は@code{nil}。
@pxref{Coding Systems}。
「補完」、「既存」、「プロンプト」。
@item Z
@c A coding system name (a symbol)---but only if this command has a prefix
@c argument. With no prefix argument, @samp{Z} provides @code{nil} as the
@c argument value. Completion, Existing, Prompt.
このコマンドに前置引数を指定した場合にのみ、
コーディングシステム名(シンボル)。
前置引数がないと、@samp{Z}は引数の値に@code{nil}を与える。
「補完」、「既存」、「プロンプト」。
@end table
@node Interactive Examples
@comment node-name, next, previous, up
@c @subsection Examples of Using @code{interactive}
@subsection @code{interactive}の使用例
@c @cindex examples of using @code{interactive}
@c @cindex @code{interactive}, examples of using
@cindex @code{interactive}の使用例
@cindex 例、@code{interactive}
@c Here are some examples of @code{interactive}:
ここでは@code{interactive}の例を示します。
@example
@group
@c (defun foo1 () ; @r{@code{foo1} takes no arguments,}
@c (interactive) ; @r{just moves forward two words.}
(defun foo1 () ; @r{@code{foo1}は引数なし}
(interactive) ; @r{2単語分先へ進める}
(forward-word 2))
@result{} foo1
@end group
@group
@c (defun foo2 (n) ; @r{@code{foo2} takes one argument,}
@c (interactive "p") ; @r{which is the numeric prefix.}
(defun foo2 (n) ; @r{@code{foo2}は1引数}
(interactive "p") ; @r{数値前置引数}
(forward-word (* 2 n)))
@result{} foo2
@end group
@group
@c (defun foo3 (n) ; @r{@code{foo3} takes one argument,}
@c (interactive "nCount:") ; @r{which is read with the Minibuffer.}
(defun foo3 (n) ; @r{@code{foo3}は1引数}
(interactive "nCount:") ; @r{ミニバッファで読む}
(forward-word (* 2 n)))
@result{} foo3
@end group
@group
(defun three-b (b1 b2 b3)
"Select three existing buffers.
Put them into three windows, selecting the last one."
@end group
(interactive "bBuffer1:\nbBuffer2:\nbBuffer3:")
(delete-other-windows)
(split-window (selected-window) 8)
(switch-to-buffer b1)
(other-window 1)
(split-window (selected-window) 8)
(switch-to-buffer b2)
(other-window 1)
(switch-to-buffer b3))
@result{} three-b
@group
(three-b "*scratch*" "declarations.texi" "*mail*")
@result{} nil
@end group
@end example
@node Interactive Call
@c @section Interactive Call
@section 対話的呼び出し
@c @cindex interactive call
@cindex 対話的呼び出し
@c After the command loop has translated a key sequence into a command it
@c invokes that command using the function @code{command-execute}. If the
@c command is a function, @code{command-execute} calls
@c @code{call-interactively}, which reads the arguments and calls the
@c command. You can also call these functions yourself.
コマンドループでは、キー列をコマンドへ変換し終えると、
関数@code{command-execute}を用いてそのコマンドを起動します。
コマンドが関数であれば、@code{command-execute}は引数を読み取り、
コマンドを呼び出す@code{call-interactively}を呼びます。
読者自身がこれらの関数を呼び出してもかまいません。
@defun commandp object
@c Returns @code{t} if @var{object} is suitable for calling interactively;
@c that is, if @var{object} is a command. Otherwise, returns @code{nil}.
@var{object}が対話的呼び出しに適していれば、
つまり、@var{object}がコマンドであれば@code{t}を返す。
さもなければ@code{nil}を返す。
@c The interactively callable objects include strings and vectors (treated
@c as keyboard macros), lambda expressions that contain a top-level call to
@c @code{interactive}, byte-code function objects made from such lambda
@c expressions, autoload objects that are declared as interactive
@c (non-@code{nil} fourth argument to @code{autoload}), and some of the
@c primitive functions.
対話的呼び出しが可能なオブジェクトには、
(キーボードマクロとして扱われる)文字列やベクトル、
トップレベルで@code{interactive}を呼び出しているラムダ式、
そのようなラムダ式をコンパイルしたバイトコード関数オブジェクト、
対話的(@code{autoload}の4番目の引数が@code{nil}以外)
と宣言された自動ロードオブジェクト、
一部の基本関数が含まれる。
@c A symbol satisfies @code{commandp} if its function definition satisfies
@c @code{commandp}.
シンボルの関数定義が@code{commandp}を満たせば、
シンボルも@code{commandp}を満たす。
@c Keys and keymaps are not commands. Rather, they are used to look up
@c commands (@pxref{Keymaps}).
キーやキーマップはコマンドではない。
それらはコマンドを探すために使われる(@pxref{Keymaps})。
@c See @code{documentation} in @ref{Accessing Documentation}, for a
@c realistic example of using @code{commandp}.
@code{commandp}の実用的な使用例については、
@ref{Accessing Documentation}の@code{documentation}を参照。
@end defun
@defun call-interactively command &optional record-flag keys
@c This function calls the interactively callable function @var{command},
@c reading arguments according to its interactive calling specifications.
@c An error is signaled if @var{command} is not a function or if it cannot
@c be called interactively (i.e., is not a command). Note that keyboard
@c macros (strings and vectors) are not accepted, even though they are
@c considered commands, because they are not functions.
この関数は、対話的呼び出し可能な関数@var{command}を
その対話指定に従って引数を読み取り呼び出す。
@var{command}が関数でなかったり、
対話的に呼び出せない(つまり、コマンドでない)場合には、
エラーを通知する。
キーボードマクロ(文字列やベクトル)はコマンドとみなすが、
それらは関数でないため、この関数はキーボードマクロを受け付けない。
@c @cindex record command history
@cindex コマンド履歴の記録
@c If @var{record-flag} is non-@code{nil}, then this command and its
@c arguments are unconditionally added to the list @code{command-history}.
@c Otherwise, the command is added only if it uses the minibuffer to read
@c an argument. @xref{Command History}.
@var{record-flag}が@code{nil}以外であると、
コマンドとその引数を無条件にリスト@code{command-history}に追加する。
さもなければ、引数を読むために
コマンドがミニバッファを使った場合にのみ追加する。
@pxref{Command History}。
@c The argument @var{keys}, if given, specifies the sequence of events to
@c supply if the command inquires which events were used to invoke it.
もし引数@var{keys}を指定すると、コマンドがそれを起動したイベントを
問い合わせたときに与えるイベント列を指定する。
@end defun
@defun command-execute command &optional record-flag keys
@c @cindex keyboard macro execution
@cindex キーボードマクロの実行
@c This function executes @var{command}. The argument @var{command} must
@c satisfy the @code{commandp} predicate; i.e., it must be an interactively
@c callable function or a keyboard macro.
この関数は@var{command}を実行する。
引数@var{command}は@code{commandp}を満たすこと。
つまり、対話的呼び出し可能な関数かキーボードマクロであること。
@c A string or vector as @var{command} is executed with
@c @code{execute-kbd-macro}. A function is passed to
@c @code{call-interactively}, along with the optional @var{record-flag}.
@code{command}が文字列やベクトルであると、
@code{execute-kbd-macro}で実行される。
関数であると、省略可能な@var{record-flag}とともに関数を
@code{call-interactively}に渡す。
@c A symbol is handled by using its function definition in its place. A
@c symbol with an @code{autoload} definition counts as a command if it was
@c declared to stand for an interactively callable function. Such a
@c definition is handled by loading the specified library and then
@c rechecking the definition of the symbol.
シンボルは、その関数定義を使って処理する。
@code{autoload}で定義されたシンボルは、
対話的呼び出し可能な関数と宣言されていればコマンドとみなす。
そのような定義では、指定されたライブラリをロードしてから
シンボルの定義を再検査して処理する。
@c The argument @var{keys}, if given, specifies the sequence of events to
@c supply if the command inquires which events were used to invoke it.
もし引数@var{keys}を指定すると、コマンドがそれを起動したイベントを
問い合わせたときに与えるイベント列を指定する。
@end defun
@c @deffn Command execute-extended-command prefix-argument
@deffn コマンド execute-extended-command prefix-argument
@c @cindex read command name
@cindex コマンド名の読み取り
@c This function reads a command name from the minibuffer using
@c @code{completing-read} (@pxref{Completion}). Then it uses
@c @code{command-execute} to call the specified command. Whatever that
@c command returns becomes the value of @code{execute-extended-command}.
この関数は@code{completing-read}(@pxref{Completion})を使って
ミニバッファでコマンド名を読む。
そして@code{command-execute}を使って指定されたコマンドを実行する。
コマンドが返した値が@code{execute-extended-command}の値になる。
@c @cindex execute with prefix argument
@cindex 前置引数付きの実行
@c If the command asks for a prefix argument, it receives the value
@c @var{prefix-argument}. If @code{execute-extended-command} is called
@c interactively, the current raw prefix argument is used for
@c @var{prefix-argument}, and thus passed on to whatever command is run.
コマンドが前置引数を必要とする場合、@var{prefix-argument}の値を受け取る。
@code{execute-extended-command}が対話的に呼ばれた場合、
現在の生の前置引数が@var{prefix-argument}として使われ、
それが実行するコマンドへ渡される。
@c !!! Should this be @kindex?
@cindex @kbd{M-x}
@c @code{execute-extended-command} is the normal definition of @kbd{M-x},
@c so it uses the string @w{@samp{M-x }} as a prompt. (It would be better
@c to take the prompt from the events used to invoke
@c @code{execute-extended-command}, but that is painful to implement.) A
@c description of the value of the prefix argument, if any, also becomes
@c part of the prompt.
@code{execute-extended-command}は通常@kbd{M-x}に定義付けられ、
そのため、プロンプトとして文字列@w{@samp{M-x }}を使う。
(@code{execute-extended-command}を起動するために使われた
イベントをプロンプトにするべきであるが、
それを実装するのは手間がかかる。)
もし前置引数を指定すると、その内容もプロンプトの一部になる。
@example
@group
(execute-extended-command 1)
---------- Buffer: Minibuffer ----------
1 M-x forward-word RET
---------- Buffer: Minibuffer ----------
@result{} t
@end group
@end example
@end deffn
@defun interactive-p
@c This function returns @code{t} if the containing function (the one whose
@c code includes the call to @code{interactive-p}) was called
@c interactively, with the function @code{call-interactively}. (It makes
@c no difference whether @code{call-interactively} was called from Lisp or
@c directly from the editor command loop.) If the containing function was
@c called by Lisp evaluation (or with @code{apply} or @code{funcall}), then
@c it was not called interactively.
この関数は、これ(@code{interactive-p}の呼び出し)を含んだ関数が
@code{call-interactively}で対話的に呼び出されると@code{t}を返す。
(Lispから@code{call-interactively}が呼び出されても、
エディタコマンドループが直接呼び出しても違いはない。)
これを含んだ関数がLispの評価(あるいは@code{apply}や@code{funcall})で
呼び出された場合は、対話的呼び出しではない。
@end defun
@c The most common use of @code{interactive-p} is for deciding whether to
@c print an informative message. As a special exception,
@c @code{interactive-p} returns @code{nil} whenever a keyboard macro is
@c being run. This is to suppress the informative messages and speed
@c execution of the macro.
@code{interactive-p}のもっとも一般的な用途は、
情報メッセージを表示するかどうか決めることです。
特別な例外として、キーボードマクロを実行中にはいつでも、
@code{interactive-p}は@code{nil}を返します。
これは情報メッセージを省いてマクロの実行を速くするためです。
@c For example:
つぎのように使います。
@example
@group
(defun foo ()
(interactive)
(when (interactive-p)
(message "foo")))
@result{} foo
@end group
@group
(defun bar ()
(interactive)
(setq foobar (list (foo) (interactive-p))))
@result{} bar
@end group
@group
@c ;; @r{Type @kbd{M-x foo}.}
;; @r{@kbd{M-x foo}と打つ}
@print{} foo
@end group
@group