-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkeymaps.texi
3168 lines (2837 loc) · 151 KB
/
keymaps.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, 1998 Free Software Foundation, Inc.
@c See the file elisp.texi for copying conditions.
@setfilename ../info/keymaps
@node Keymaps, Modes, Command Loop, Top
@c @chapter Keymaps
@chapter キーマップ
@c @cindex keymap
@cindex キーマップ
@c The bindings between input events and commands are recorded in data
@c structures called @dfn{keymaps}. Each binding in a keymap associates
@c (or @dfn{binds}) an individual event type either to another keymap or to
@c a command. When an event type is bound to a keymap, that keymap is used
@c to look up the next input event; this continues until a command is
@c found. The whole process is called @dfn{key lookup}.
入力イベントとコマンドとのバインディング(対応)は、
@dfn{キーマップ}(keymap)と呼ばれるデータ構造に記録されています。
キーマップの各バインディング(あるいは@dfn{バインド}(bind))は、
個々のイベント型を別のキーマップかコマンドに対応付けます。
イベント型のバインディングがキーマップであると、
後続の入力イベントを探すためにそのキーマップを使います。
コマンドがみつかるまで、これを繰り返します。
この処理全体を@dfn{キー探索}(key lookup)と呼びます。
@menu
* Keymap Terminology:: Definitions of terms pertaining to keymaps.
* Format of Keymaps:: What a keymap looks like as a Lisp object.
* Creating Keymaps:: Functions to create and copy keymaps.
* Inheritance and Keymaps:: How one keymap can inherit the bindings
of another keymap.
* Prefix Keys:: Defining a key with a keymap as its definition.
* Active Keymaps:: Each buffer has a local keymap
to override the standard (global) bindings.
A minor mode can also override them.
* Key Lookup:: How extracting elements from keymaps works.
* Functions for Key Lookup:: How to request key lookup.
* Changing Key Bindings:: Redefining a key in a keymap.
* Key Binding Commands:: Interactive interfaces for redefining keys.
* Scanning Keymaps:: Looking through all keymaps, for printing help.
* Menu Keymaps:: Defining a menu as a keymap.
@end menu
@node Keymap Terminology
@c @section Keymap Terminology
@section キーマップの用語
@c @cindex key
@c @cindex keystroke
@c @cindex key binding
@c @cindex binding of a key
@c @cindex complete key
@c @cindex undefined key
@cindex キー
@cindex 打鍵
@cindex キーバインディング
@cindex キーのバインド
@cindex 完全なキー
@cindex 未定義キー
@c A @dfn{keymap} is a table mapping event types to definitions (which
@c can be any Lisp objects, though only certain types are meaningful for
@c execution by the command loop). Given an event (or an event type) and a
@c keymap, Emacs can get the event's definition. Events include
@c characters, function keys, and mouse actions (@pxref{Input Events}).
@dfn{キーマップ}(keymap)は、イベント型を定義に対応させる表です。
(この定義は任意のLispオブジェクトであるが、
コマンドループによる実行においては、特定の型のみが意味を持つ)。
与えられたイベント(あるいはイベント型)とキーマップから、
Emacsはイベントの定義を得ることができます。
イベントは、文字、ファンクションキー、マウス操作です
(@pxref{Input Events})。
@c A sequence of input events that form a unit is called a
@c @dfn{key sequence}, or @dfn{key} for short. A sequence of one event
@c is always a key sequence, and so are some multi-event sequences.
ある単位を構成する入力イベントの列を@dfn{キー列}(key sequence)、
あるいは、略して@dfn{キー}(key)と呼びます。
単一イベントから成る列はつねにキー列であり、複数イベント列もキー列です。
@c A keymap determines a binding or definition for any key sequence. If
@c the key sequence is a single event, its binding is the definition of the
@c event in the keymap. The binding of a key sequence of more than one
@c event is found by an iterative process: the binding of the first event
@c is found, and must be a keymap; then the second event's binding is found
@c in that keymap, and so on until all the events in the key sequence are
@c used up.
キーマップは、任意のキー列に対するバインディング、
つまり、定義を決定します。
キー列が単一イベントから成るとき、
そのバインディングはキーマップ内の当該イベントの定義です。
複数のイベントから成るキー列のバインディングは、
繰り返し処理で探します。
つまり、最初のイベントのバインディングを探すと、
それはキーマップであるはずです。
続いて、そのキーマップから2番目のイベントのバインディングを探します。
これをキー列のすべてのイベントを使い尽くすまで行います
@c If the binding of a key sequence is a keymap, we call the key sequence
@c a @dfn{prefix key}. Otherwise, we call it a @dfn{complete key} (because
@c no more events can be added to it). If the binding is @code{nil},
@c we call the key @dfn{undefined}. Examples of prefix keys are @kbd{C-c},
@c @kbd{C-x}, and @kbd{C-x 4}. Examples of defined complete keys are
@c @kbd{X}, @key{RET}, and @kbd{C-x 4 C-f}. Examples of undefined complete
@c keys are @kbd{C-x C-g}, and @kbd{C-c 3}. @xref{Prefix Keys}, for more
@c details.
キー列のバインディングがキーマップであると、
そのキー列を@dfn{プレフィックスキー}(prefix key)と呼びます。
さもなければ、(追加できるイベントがないので)
@dfn{完全なキー}(complete key)と呼びます。
バインディングが@code{nil}であると、キーは@dfn{未定義}であるといいます。
プレフィックスキーの例は、@kbd{C-c}、@kbd{C-x}、@kbd{C-x 4}です。
定義されている完全なキーの例は、@kbd{X}、@key{RET}、@kbd{C-x 4 C-f}です。
未定義な完全なキーの例は、@kbd{C-x C-g}と@kbd{C-c 3}です。
詳しくは、@xref{Prefix Keys}。
@c The rule for finding the binding of a key sequence assumes that the
@c intermediate bindings (found for the events before the last) are all
@c keymaps; if this is not so, the sequence of events does not form a
@c unit---it is not really one key sequence. In other words, removing one
@c or more events from the end of any valid key sequence must always yield
@c a prefix key. For example, @kbd{C-f C-n} is not a key sequence;
@c @kbd{C-f} is not a prefix key, so a longer sequence starting with
@c @kbd{C-f} cannot be a key sequence.
キー列のバインディングを探す際の規則では、
(最後のイベントのまえまでにみつかる)途中のバインディングは
すべてキーマップであると仮定します。
これが満たされないと、イベントの列があるまとまりを構成せず、
1つのキー列になりません。
いいかえれば、有効なキー列の末尾からいくつかのイベントを取りさると、
つねにプレフィックスキーになる必要があります。
たとえば、@kbd{C-f C-n}はキー列ではありません。
@kbd{C-f}はプレフィックスキーではないので、
@kbd{C-f}で始まる列はキー列ではありません。
@c The set of possible multi-event key sequences depends on the bindings
@c for prefix keys; therefore, it can be different for different keymaps,
@c and can change when bindings are changed. However, a one-event sequence
@c is always a key sequence, because it does not depend on any prefix keys
@c for its well-formedness.
複数イベントから成るキー列の候補は、
プレフィックスキーのバインディングに依存します。
したがって、キーマップが異なればそれらは異なり、
バインディングを変更するとそれらは変わります。
しかし、単一イベントから成る列は、プレフィックスに依存しないので、
つねにキー列です。
@c At any time, several primary keymaps are @dfn{active}---that is, in
@c use for finding key bindings. These are the @dfn{global map}, which is
@c shared by all buffers; the @dfn{local keymap}, which is usually
@c associated with a specific major mode; and zero or more @dfn{minor mode
@c keymaps}, which belong to currently enabled minor modes. (Not all minor
@c modes have keymaps.) The local keymap bindings shadow (i.e., take
@c precedence over) the corresponding global bindings. The minor mode
@c keymaps shadow both local and global keymaps. @xref{Active Keymaps},
@c for details.
ある時点には、複数個の主キーマップが活性です。
つまり、キーバインディングの探索に使われます。
それらは、
すべてのバッファが共有する@dfn{グローバルマップ}(global map)、
特定のメジャーモードに関連付けられた@dfn{ローカルマップ}(local keymap)、
現在オンにしてあるマイナモードに属する
@dfn{マイナモードキーマップ}(minor mode keymaps)です。
(すべてのマイナモードにキーマップがあるわけではない。)
ローカルキーマップのバインディングは、
対応するグローバルなバインディングを隠します(つまり優先する)。
マイナモードキーマップは、ローカルとグローバルの両方のキーマップを隠します。
詳しくは@xref{Active Keymaps}。
@node Format of Keymaps
@c @section Format of Keymaps
@section キーマップの形式
@c @cindex format of keymaps
@c @cindex keymap format
@c @cindex full keymap
@c @cindex sparse keymap
@cindex キーマップの形式
@cindex 完全なキーマップ
@cindex 疎なキーマップ
@c A keymap is a list whose @sc{car} is the symbol @code{keymap}. The
@c remaining elements of the list define the key bindings of the keymap.
@c Use the function @code{keymapp} (see below) to test whether an object is
@c a keymap.
キーマップは、その@sc{car}がシンボル@code{keymap}であるリストです。
リストの残りの要素がキーマップのキーバインディングを定義します。
オブジェクトがキーマップであるかどうか検査するには、
関数@code{keymapp}(下記参照)を使います。
@c Several kinds of elements may appear in a keymap, after the symbol
@c @code{keymap} that begins it:
キーマップでは、シンボル@code{keymap}のうしろに、
さまざまな種類の要素が現れます。
@table @code
@item (@var{type} .@: @var{binding})
@c This specifies one binding, for events of type @var{type}. Each
@c ordinary binding applies to events of a particular @dfn{event type},
@c which is always a character or a symbol. @xref{Classifying Events}.
イベント型@var{type}に対する1つのバインディングを指定する。
普通の各バインディングは、文字やシンボルである特定の@dfn{イベント型}に
適用される。
@pxref{Classifying Events}。
@item (t .@: @var{binding})
@c @cindex default key binding
@cindex デフォルトのキーバインディング
@c This specifies a @dfn{default key binding}; any event not bound by other
@c elements of the keymap is given @var{binding} as its binding. Default
@c bindings allow a keymap to bind all possible event types without having
@c to enumerate all of them. A keymap that has a default binding
@c completely masks any lower-precedence keymap.
@dfn{デフォルトのキーバインディング}を指定する。
キーマップの他の要素に一致しない任意のイベントには、
そのバインディングとして指定した@var{binding}を与える。
デフォルトのバインディングにより、
すべてを列挙せずに可能なすべてのイベントにバインドできる。
デフォルトのバインディングを有するキーマップは、
任意の低優先順位のキーマップを隠してしまう。
@item @var{vector}
@c If an element of a keymap is a vector, the vector counts as bindings for
@c all the @sc{ASCII} characters, codes 0 through 127; vector element
@c @var{n} is the binding for the character with code @var{n}. This is a
@c compact way to record lots of bindings. A keymap with such a vector is
@c called a @dfn{full keymap}. Other keymaps are called @dfn{sparse
@c keymaps}.
キーマップの要素がベクトルであると、
当該ベクトルを@sc{ASCII}文字全体、つまり、コード0から127に対する
バインディングとみなす。
ベクトルの@var{n}番目の要素は、コード@var{n}の文字に対する
バインディングである。
これは、多くのバインディングを記録するコンパクトな方法である。
このようなベクトルのキーマップを@dfn{完全なキーマップ}(full keymap)と呼ぶ。
それ以外のキーマップを@dfn{疎なキーマップ}(sparse keymaps)と呼ぶ。
@c When a keymap contains a vector, it always defines a binding for each
@c @sc{ASCII} character, even if the vector contains @code{nil} for that
@c character. Such a binding of @code{nil} overrides any default key
@c binding in the keymap, for @sc{ASCII} characters. However, default
@c bindings are still meaningful for events other than @sc{ASCII}
@c characters. A binding of @code{nil} does @emph{not} override
@c lower-precedence keymaps; thus, if the local map gives a binding of
@c @code{nil}, Emacs uses the binding from the global map.
キーマップにベクトルがあると、ベクトルの要素が@code{nil}であっても
ベクトルが各@sc{ASCII}文字のバインディングをつねに定義する。
そのような@code{nil}のバインディングは、
@sc{ASCII}文字に対しては
キーマップのデフォルトのキーバインディングを無効にする。
しかし、@sc{ASCII}文字以外のイベントに対しては、
デフォルトのバインディングが意味を持つ。
@code{nil}のバインディングが
低優先順位のキーマップを隠すことは@emph{ない}。
つまり、ローカルマップが@code{nil}のバインディングを与えると、
Emacsはグローバルマップのバインディングを使う。
@item @var{string}
@c @cindex keymap prompt string
@c @cindex overall prompt string
@c @cindex prompt string of keymap
@cindex キーマップのプロンプト文字列
@cindex 全面プロンプト文字列
@c Aside from bindings, a keymap can also have a string as an element.
@c This is called the @dfn{overall prompt string} and makes it possible to
@c use the keymap as a menu. @xref{Menu Keymaps}.
バインディングに加えて、
キーマップでは、要素として文字列を持つこともできる。
これを@dfn{全面プロンプト文字列}(overall prompt string)と呼び、
キーマップをメニューとして使うことを可能にする。
@pxref{Menu Keymaps}。
@end table
@c @cindex meta characters lookup
@cindex メタ文字の探索
@c Keymaps do not directly record bindings for the meta characters.
@c Instead, meta characters are regarded for
@c purposes of key lookup as sequences of two characters, the first of
@c which is @key{ESC} (or whatever is currently the value of
@c @code{meta-prefix-char}). Thus, the key @kbd{M-a} is really represented
@c as @kbd{@key{ESC} a}, and its global binding is found at the slot for
@c @kbd{a} in @code{esc-map} (@pxref{Prefix Keys}).
キーマップは、メタ文字に対するバインディングを直接には記録していません。
そのかわりに、キー探索においては、メタ文字は2文字から成る列とみなし、
先頭文字は@key{ESC}(あるいは、@code{meta-prefix-char}の現在値)です。
つまり、キー@kbd{M-a}は実際には@kbd{@key{ESC} a}と表現され、
そのグローバルなバインディングは
@code{esc-map}の@kbd{a}でみつかります(@pxref{Prefix Keys})。
@c Here as an example is the local keymap for Lisp mode, a sparse
@c keymap. It defines bindings for @key{DEL} and @key{TAB}, plus @kbd{C-c
@c C-l}, @kbd{M-C-q}, and @kbd{M-C-x}.
Lispモードに対するローカルキーマップの例を示します。
これは疎なキーマップです。
@key{DEL}、@key{TAB}、@kbd{C-c C-l}、@kbd{M-C-q}、@kbd{M-C-x}に対する
バインディングを定義しています。
@example
@group
lisp-mode-map
@result{}
@end group
@group
(keymap
;; @key{TAB}
(9 . lisp-indent-line)
@end group
@group
;; @key{DEL}
(127 . backward-delete-char-untabify)
@end group
@group
(3 keymap
;; @kbd{C-c C-l}
(12 . run-lisp))
@end group
@group
(27 keymap
@c ;; @r{@kbd{M-C-q}, treated as @kbd{@key{ESC} C-q}}
;; @r{@kbd{M-C-q}は@kbd{@key{ESC} C-q}とみなされる}
(17 . indent-sexp)
@c ;; @r{@kbd{M-C-x}, treated as @kbd{@key{ESC} C-x}}
;; @r{@kbd{M-C-x}は@kbd{@key{ESC} C-x}とみなされる}
(24 . lisp-send-defun)))
@end group
@end example
@defun keymapp object
@c This function returns @code{t} if @var{object} is a keymap, @code{nil}
@c otherwise. More precisely, this function tests for a list whose
@c @sc{car} is @code{keymap}.
この関数は、@var{object}がキーマップであれば@code{t}を返し、
さもなければ@code{nil}を返す。
より正確には、この関数は、
その@sc{car}が@code{keymap}であるリストかどうかを検査する。
@example
@group
(keymapp '(keymap))
@result{} t
@end group
@group
(keymapp (current-global-map))
@result{} t
@end group
@end example
@end defun
@node Creating Keymaps
@c @section Creating Keymaps
@section キーマップの作成
@c @cindex creating keymaps
@cindex キーマップの作成
@c Here we describe the functions for creating keymaps.
ここでは、キーマップを作成するための関数について述べます。
@c ??? This should come after make-sparse-keymap
@defun make-keymap &optional prompt
@c This function creates and returns a new full keymap (i.e., one
@c containing a vector of length 128 for defining all the @sc{ASCII}
@c characters). The new keymap initially binds all @sc{ASCII} characters
@c to @code{nil}, and does not bind any other kind of event.
この関数は新たに完全なキーマップ
(つまり、すべての@sc{ASCII}文字に対する定義を収めた
長さ128のベクトル)を作成しそれを返す。
新たなキーマップでは、すべての@sc{ASCII}文字に対するバインディングは
@code{nil}であり、それ以外の種類のイベントに対するバインディングはない。
@example
@group
(make-keymap)
@result{} (keymap [nil nil nil @dots{} nil nil])
@end group
@end example
@c If you specify @var{prompt}, that becomes the overall prompt string for
@c the keymap. The prompt string is useful for menu keymaps (@pxref{Menu
@c Keymaps}).
@var{prompt}を指定すると、
それはキーマップに対する全面プロンプト文字列になる。
全面プロンプト文字列はメニューキーマップ
(@pxref{Menu Keymaps})に有用である。
@end defun
@defun make-sparse-keymap &optional prompt
@c This function creates and returns a new sparse keymap with no entries.
@c The new keymap does not bind any events. The argument @var{prompt}
@c specifies a prompt string, as in @code{make-keymap}.
この関数は、新たに空の疎なキーマップを作成しそれを返す。
新たなキーマップにはイベントに対するバインディングはいっさいない。
引数@var{prompt}は、@code{make-keymap}の場合同様、
プロンプト文字列を指定する。
@example
@group
(make-sparse-keymap)
@result{} (keymap)
@end group
@end example
@end defun
@defun copy-keymap keymap
@c This function returns a copy of @var{keymap}. Any keymaps that
@c appear directly as bindings in @var{keymap} are also copied recursively,
@c and so on to any number of levels. However, recursive copying does not
@c take place when the definition of a character is a symbol whose function
@c definition is a keymap; the same symbol appears in the new copy.
@c @c Emacs 19 feature
この関数は@var{keymap}のコピーを返す。
@var{keymap}にバインディングとして直接現れる任意のキーマップも
任意のレベルまで再帰的にコピーされる。
しかし、文字に対する定義が、その関数定義がキーマップであるような
シンボルに出会うと再帰的なコピーを行わないため、
同じシンボルが新たなコピーにも現れる。
@example
@group
(setq map (copy-keymap (current-local-map)))
@result{} (keymap
@end group
@group
@c ;; @r{(This implements meta characters.)}
;; @r{(これはメタ文字を意味する)}
(27 keymap
(83 . center-paragraph)
(115 . center-line))
(9 . tab-to-tab-stop))
@end group
@group
(eq map (current-local-map))
@result{} nil
@end group
@group
(equal map (current-local-map))
@result{} t
@end group
@end example
@end defun
@node Inheritance and Keymaps
@c @section Inheritance and Keymaps
@section 継承とキーマップ
@c @cindex keymap inheritance
@c @cindex inheriting a keymap's bindings
@cindex キーマップの継承
@cindex 継承、キーマップ
@cindex キーマップのバインディングの継承
@cindex 継承、キーマップのバインディング
@c A keymap can inherit the bindings of another keymap, which we call the
@c @dfn{parent keymap}. Such a keymap looks like this:
キーマップでは、@dfn{親キーマップ}(parent keymap)と呼ぶ別のキーマップの
バインディングを継承できます。
そのようなキーマップはつぎのようになります。
@example
(keymap @var{bindings}@dots{} . @var{parent-keymap})
@end example
@noindent
@c The effect is that this keymap inherits all the bindings of
@c @var{parent-keymap}, whatever they may be at the time a key is looked up,
@c but can add to them or override them with @var{bindings}.
このキーマップは、キーを探索する時点において
@var{parent-keymap}が有するすべてのバインディングを継承しますが、
それらには@var{bindings}が追加されたり優先します。
@c If you change the bindings in @var{parent-keymap} using @code{define-key}
@c or other key-binding functions, these changes are visible in the
@c inheriting keymap unless shadowed by @var{bindings}. The converse is
@c not true: if you use @code{define-key} to change the inheriting keymap,
@c that affects @var{bindings}, but has no effect on @var{parent-keymap}.
@code{define-key}や他のキーバインディング関数で@var{parent-keymap}の
バインディングを変更すると、それらの変更は、
@var{bindings}で隠されない限り継承側のキーマップからも見えます。
その逆は真ではありません。
@code{define-key}で継承側のキーマップを修正すると、
それは@var{bindings}に影響するだけで@var{parent-keymap}には影響しません。
@c The proper way to construct a keymap with a parent is to use
@c @code{set-keymap-parent}; if you have code that directly constructs a
@c keymap with a parent, please convert the program to use
@c @code{set-keymap-parent} instead.
親キーマップを用いたキーマップを作成する正しい方法は、
@code{set-keymap-parent}を使うことです。
親キーマップを用いたキーマップを直接作成するようなコードがある場合には、
@code{set-keymap-parent}を用いるようにプログラムを変更してください。
@defun keymap-parent keymap
@c This returns the parent keymap of @var{keymap}. If @var{keymap}
@c has no parent, @code{keymap-parent} returns @code{nil}.
この関数は、キーマップ@var{keymap}の親キーマップを返す。
@var{keymap}に親がなければ@code{keymap-parent}は@code{nil}を返す。
@end defun
@defun set-keymap-parent keymap parent
@c This sets the parent keymap of @var{keymap} to @var{parent}, and returns
@c @var{parent}. If @var{parent} is @code{nil}, this function gives
@c @var{keymap} no parent at all.
キーマップ@var{keymap}の親キーマップとして@var{parent}を設定し、
@var{parent}を返す。
@var{parent}が@code{nil}であると、
この関数は@var{keymap}に親キーマップをいっさい与えない。
@c If @var{keymap} has submaps (bindings for prefix keys), they too receive
@c new parent keymaps that reflect what @var{parent} specifies for those
@c prefix keys.
@var{keymap}に(プレフィックスキー用のバインディングである)
サブマップがあれば、それらも@var{parent}が指定するプレフィックスキーを
反映する新たな親マップを受け取る。
@end defun
@c Here is an example showing how to make a keymap that inherits
@c from @code{text-mode-map}:
@code{text-mode-map}からキーマップを継承する方法を示します。
@example
(let ((map (make-sparse-keymap)))
(set-keymap-parent map text-mode-map)
map)
@end example
@node Prefix Keys
@c @section Prefix Keys
@section プレフィックスキー
@c @cindex prefix key
@cindex プレフィックスキー
@c A @dfn{prefix key} is a key sequence whose binding is a keymap. The
@c keymap defines what to do with key sequences that extend the prefix key.
@c For example, @kbd{C-x} is a prefix key, and it uses a keymap that is
@c also stored in the variable @code{ctl-x-map}. This keymap defines
@c bindings for key sequences starting with @kbd{C-x}.
@dfn{プレフィックス}(prefix key)とは、
そのバインディングがキーマップであるキー列のことです。
そのキーマップが、プレフィックスキー以降のキーでなにをするかを定義します。
たとえば、@kbd{C-x}はプレフィックスキーであり、
変数@code{ctl-x-map}に保持されたキーマップを使います。
このキーマップは、@kbd{C-x}で始まるキー列に対するバインディングを定義します。
@c Some of the standard Emacs prefix keys use keymaps that are
@c also found in Lisp variables:
Emacsの標準プレフィックスキーのなかには、
Lisp変数にも保持されたキーマップを使うものがあります。
@itemize @bullet
@item
@vindex esc-map
@findex ESC-prefix
@c @code{esc-map} is the global keymap for the @key{ESC} prefix key. Thus,
@c the global definitions of all meta characters are actually found here.
@c This map is also the function definition of @code{ESC-prefix}.
@code{esc-map}は、プレフィックスキー@key{ESC}用のグローバルマップである。
したがって、すべてのメタ文字のグローバルな定義はここにある。
このキーマップは@code{ESC-prefix}の関数定義でもある。
@item
@cindex @kbd{C-h}
@c @code{help-map} is the global keymap for the @kbd{C-h} prefix key.
@code{help-map}は、プレフィックスキー@kbd{C-h}に対する
グローバルキーマップである。
@item
@cindex @kbd{C-c}
@vindex mode-specific-map
@c @code{mode-specific-map} is the global keymap for the prefix key
@c @kbd{C-c}. This map is actually global, not mode-specific, but its name
@c provides useful information about @kbd{C-c} in the output of @kbd{C-h b}
@c (@code{display-bindings}), since the main use of this prefix key is for
@c mode-specific bindings.
@code{mode-specific-map}は、プレフィックスキー@kbd{C-c}に対する
グローバルキーマップである。
このキーマップは実際にはグローバルでありモード固有ではないが、
その名前は、@kbd{C-h b}(@code{display-bindings})の出力において
@kbd{C-c}に関する有用な情報を与える。
というのは、このプレフィックスキーの主な用途は、
モード固有のバインディングのためだからである。
@item
@cindex @kbd{C-x}
@vindex ctl-x-map
@findex Control-X-prefix
@c @code{ctl-x-map} is the global keymap used for the @kbd{C-x} prefix key.
@c This map is found via the function cell of the symbol
@c @code{Control-X-prefix}.
@code{ctl-x-map}は、プレフィックスキー@kbd{C-x}に対して使われる
グローバルキーマップである。
このキーマップは、シンボル@code{Control-X-prefix}の関数セルに現れる。
@item
@cindex @kbd{C-x @key{RET}}
@vindex mule-keymap
@c @code{mule-keymap} is the global keymap used for the @kbd{C-x @key{RET}}
@c prefix key.
@code{mule-keymap}は、プレフィックスキー@kbd{C-x @key{RET}}に対して使われる
グローバルキーマップである。
@item
@cindex @kbd{C-x 4}
@vindex ctl-x-4-map
@c @code{ctl-x-4-map} is the global keymap used for the @kbd{C-x 4} prefix
@c key.
@code{ctl-x-4-map}は、プレフィックスキー@kbd{C-x 4}に対して使われる
グローバルキーマップである。
@c Emacs 19 feature
@item
@cindex @kbd{C-x 5}
@vindex ctl-x-5-map
@c @code{ctl-x-5-map} is the global keymap used for the @kbd{C-x 5} prefix
@c key.
@code{ctl-x-5-map}は、プレフィックスキー@kbd{C-x 5}に対して使われる
グローバルキーマップである。
@c Emacs 19 feature
@item
@cindex @kbd{C-x 6}
@vindex 2C-mode-map
@c @code{2C-mode-map} is the global keymap used for the @kbd{C-x 6} prefix
@c key.
@code{2C-mode-map}は、プレフィックスキー@kbd{C-x 6}に対して使われる
グローバルキーマップである。
@item
@cindex @kbd{C-x v}
@vindex vc-prefix-map
@c @code{vc-prefix-map} is the global keymap used for the @kbd{C-x v} prefix
@c key.
@code{vc-prefix-map}は、プレフィックスキー@kbd{C-x v}に対して使われる
グローバルキーマップである。
@item
@cindex @kbd{M-g}
@vindex facemenu-keymap
@c @code{facemenu-keymap} is the global keymap used for the @kbd{M-g}
@c prefix key.
@code{facemenu-keymap}は、プレフィックスキー@kbd{M-g}に対して使われる
グローバルキーマップである。
@c Emacs 19 feature
@item
@c The other Emacs prefix keys are @kbd{C-x @@}, @kbd{C-x a i}, @kbd{C-x
@c @key{ESC}} and @kbd{@key{ESC} @key{ESC}}. They use keymaps that have no
@c special names.
Emacsには、他にも、@kbd{C-x @@}、@kbd{C-x a i}、@kbd{C-x @key{ESC}}、
@kbd{@key{ESC} @key{ESC}}のプレフィックスキーがある。
これらは、特別な名前を持たないキーマップを使う。
@end itemize
@c The keymap binding of a prefix key is used for looking up the event
@c that follows the prefix key. (It may instead be a symbol whose function
@c definition is a keymap. The effect is the same, but the symbol serves
@c as a name for the prefix key.) Thus, the binding of @kbd{C-x} is the
@c symbol @code{Control-X-prefix}, whose function cell holds the keymap
@c for @kbd{C-x} commands. (The same keymap is also the value of
@c @code{ctl-x-map}.)
プレフィックスキーのキーマップバインディングは、
当該プレフィックスキーに続くイベントを探すために使われます。
(その関数定義がキーマップであるシンボルでもよい。
効果は同じであるが、シンボルはプレフィックスキーに対する名前として働く。)
したがって、@kbd{C-x}のバインディングは
シンボル@code{Control-X-prefix}であり、
その関数セルがコマンド@kbd{C-x}用のキーマップを保持している。
(@code{ctl-x-map}の値も同じキーマップである。)
@c Prefix key definitions can appear in any active keymap. The
@c definitions of @kbd{C-c}, @kbd{C-x}, @kbd{C-h} and @key{ESC} as prefix
@c keys appear in the global map, so these prefix keys are always
@c available. Major and minor modes can redefine a key as a prefix by
@c putting a prefix key definition for it in the local map or the minor
@c mode's map. @xref{Active Keymaps}.
プレフィックスキーの定義は、任意の活性なキーマップにあってかまいません。
プレフィックスキーとしての@kbd{C-c}、@kbd{C-x}、@kbd{C-h}、@key{ESC}の
定義はグローバルマップにあるので、これらのプレフィックスキーは
つねに利用できます。
メジャーモードやマイナモードでは、
プレフィックスキーの定義をローカルキーマップや
マイナモードキーマップに入れることで、
キーをプレフィックスとして再定義できます。
@xref{Active Keymaps}。
@c If a key is defined as a prefix in more than one active map, then its
@c various definitions are in effect merged: the commands defined in the
@c minor mode keymaps come first, followed by those in the local map's
@c prefix definition, and then by those from the global map.
複数の活性なキーマップにおいて、キーがプレフィックスと定義されていると、
さまざまな定義は実質的には併合されます。
マイナモードキーマップで定義されたコマンドが最優先で、
つぎにローカルマップのプレフィックス定義、
そしてグローバルマップのプレフィックス定義が続きます。
@c In the following example, we make @kbd{C-p} a prefix key in the local
@c keymap, in such a way that @kbd{C-p} is identical to @kbd{C-x}. Then
@c the binding for @kbd{C-p C-f} is the function @code{find-file}, just
@c like @kbd{C-x C-f}. The key sequence @kbd{C-p 6} is not found in any
@c active keymap.
以下の例では、ローカルキーマップにおいて、
@kbd{C-p}を@kbd{C-x}に等価なプレフィックスキーにします。
続いて@kbd{C-p C-f}のバインディングを
@kbd{C-x C-f}のように関数@code{find-file}にします。
キー列@kbd{C-p 6}はどの活性なキーマップでもみつかりません。
@example
@group
(use-local-map (make-sparse-keymap))
@result{} nil
@end group
@group
(local-set-key "\C-p" ctl-x-map)
@result{} nil
@end group
@group
(key-binding "\C-p\C-f")
@result{} find-file
@end group
@group
(key-binding "\C-p6")
@result{} nil
@end group
@end example
@defun define-prefix-command symbol
@c @cindex prefix command
@cindex プレフィックスコマンド
@cindex コマンド、プレフィックス
@c This function prepares @var{symbol} for use as a prefix key's binding:
@c it creates a full keymap and stores it as @var{symbol}'s function
@c definition. Subsequently binding a key sequence to @var{symbol} will
@c make that key sequence into a prefix key.
この関数は、@var{symbol}をプレフィックスキーの
バインディングとして使えるように準備する。
つまり、完全なキーマップを作成し、
@var{symbol}の関数定義にそのキーマップを保存する。
以後、@var{symbol}にキー列をバインドすると、
当該キー列をプレフィックスキーに入る。
@c This function also sets @var{symbol} as a variable, with the keymap as
@c its value. It returns @var{symbol}.
この関数は、変数としての@var{symbol}にも値としてキーマップを設定する。
@var{symbol}を返す。
@c In Emacs version 18, only the function definition of @var{symbol} was
@c set, not the value as a variable.
@end defun
@node Active Keymaps
@c @section Active Keymaps
@section 活性なキーマップ
@c @cindex active keymap
@c @cindex global keymap
@c @cindex local keymap
@cindex 活性なキーマップ
@cindex グローバルキーマップ
@cindex ローカルキーマップ
@c Emacs normally contains many keymaps; at any given time, just a few of
@c them are @dfn{active} in that they participate in the interpretation
@c of user input. These are the global keymap, the current buffer's
@c local keymap, and the keymaps of any enabled minor modes.
Emacsには、通常、たくさんのキーマップがあります。
ある時点では、それらの数個が@dfn{活性}になっていて、
ユーザー入力の解釈に関与します。
それらは、グローバルキーマップ、カレントバッファのローカルキーマップ、
オンになっているマイナモードのキーマップです。
@c The @dfn{global keymap} holds the bindings of keys that are defined
@c regardless of the current buffer, such as @kbd{C-f}. The variable
@c @code{global-map} holds this keymap, which is always active.
@dfn{グローバルキーマップ}(global keymap)は、
@kbd{C-f}のようなカレントバッファに依存せずに
定義されたキーのバインディングを保持します。
変数@code{global-map}はこのキーマップを保持していて、
このキーマップはつねに活性です。
@c Each buffer may have another keymap, its @dfn{local keymap}, which may
@c contain new or overriding definitions for keys. The current buffer's
@c local keymap is always active except when @code{overriding-local-map}
@c overrides it. Text properties can specify an alternative local map for
@c certain parts of the buffer; see @ref{Special Properties}.
各バッファには別のキーマップ、つまり、
バッファの@dfn{ローカルキーマップ}(local keymap)があり、
キーに対する新しい定義や無効にする定義を保持しています。
カレントバッファのローカルキーマップは、
@code{overriding-local-map}で無効にしない限り、つねに活性です。
テキスト属性により、バッファの特定部分に対する
代替ローカルマップを指定できます。
@ref{Special Properties}を参照してください。
@c Each minor mode can have a keymap; if it does, the keymap is active
@c when the minor mode is enabled.
各マイナモードもキーマップを持てます。
その場合、マイナモードがオンであると当該キーマップは活性です。
@c The variable @code{overriding-local-map}, if non-@code{nil}, specifies
@c another local keymap that overrides the buffer's local map and all the
@c minor mode keymaps.
変数@code{overriding-local-map}が@code{nil}以外であると、
バッファのローカルキーマップとそのすべてのマイナモードキーマップに
取ってかわるローカルキーマップを指定します。
@c All the active keymaps are used together to determine what command to
@c execute when a key is entered. Emacs searches these maps one by one, in
@c order of decreasing precedence, until it finds a binding in one of the
@c maps. The procedure for searching a single keymap is called @dfn{key
@c lookup}; see @ref{Key Lookup}.
キーが入力されるとどのコマンドを実行するかを決定するために、
すべての活性なキーマップを一緒に使います。
Emacsは、キーマップの1つでバインディングがみつかるまで、
優先順位が高いほうからこれらのキーマップを1つ1つ探索します。
1つのキーマップで探索する処理のことを
@dfn{キー探索}(key lookup)といいます。
@ref{Key Lookup}を参照してください。
@c Normally, Emacs first searches for the key in the minor mode maps, in
@c the order specified by @code{minor-mode-map-alist}; if they do not
@c supply a binding for the key, Emacs searches the local map; if that too
@c has no binding, Emacs then searches the global map. However, if
@c @code{overriding-local-map} is non-@code{nil}, Emacs searches that map
@c first, before the global map.
通常、Emacsはまず@code{minor-mode-map-alist}で指定される順に
マイナモードキーマップでキーを探します。
キーに対するバインディングがなければ、
Emacsはローカルキーマップで探します。
そこにもバインディングがなければ、
Emacsはグローバルキーマップで探します。
しかし、@code{overriding-local-map}が@code{nil}以外であれば、
Emacsはまずそのキーマップで探してから、
グローバルキーマップで探します。
@c @cindex major mode keymap
@cindex メジャーモードのキーマップ
@c Since every buffer that uses the same major mode normally uses the
@c same local keymap, you can think of the keymap as local to the mode. A
@c change to the local keymap of a buffer (using @code{local-set-key}, for
@c example) is seen also in the other buffers that share that keymap.
同じメジャーモードを使う各バッファは、通常、同じローカルキーマップを
使うので、キーマップはモードにローカルであると考えることができます。
(たとえば@code{local-set-key}を使って)バッファのローカルキーマップを
修正すると、当該キーマップを共有している別のバッファでも
その修正が見えます。
@c The local keymaps that are used for Lisp mode and some other major
@c modes exist even if they have not yet been used. These local maps are
@c the values of variables such as @code{lisp-mode-map}. For most major
@c modes, which are less frequently used, the local keymap is constructed
@c only when the mode is used for the first time in a session.
Lispモードや他の数個のメジャーモードで使われるローカルキーマップは、
それらのモードがまだ使われていなくても存在します。
そのようなローカルキーマップは、@code{lisp-mode-map}などの変数の値です。
使用頻度の低いほとんどのメジャーモードでは、
セッションで始めてそのモードを使ったときに
ローカルキーマップを作成します。
@c The minibuffer has local keymaps, too; they contain various completion
@c and exit commands. @xref{Intro to Minibuffers}.
ミニバッファにもローカルキーマップがあります。
それにはさまざまな補完コマンドや脱出コマンドが含まれます。
@xref{Intro to Minibuffers}。
@c Emacs has other keymaps that are used in a different way---translating
@c events within @code{read-key-sequence}. @xref{Translating Input}.
Emacsには、別の用途のキーマップもあります。
@code{read-key-sequence}でイベントを変換するためのものです。
@xref{Translating Input}。
@c @xref{Standard Keymaps}, for a list of standard keymaps.
標準的なキーマップの一覧については@xref{Standard Keymaps}。
@defvar global-map
@c This variable contains the default global keymap that maps Emacs
@c keyboard input to commands. The global keymap is normally this keymap.
@c The default global keymap is a full keymap that binds
@c @code{self-insert-command} to all of the printing characters.
この変数は、Emacsがキーボード入力をコマンドに対応させるための
デフォルトのグローバルキーマップを保持する。
グローバルキーマップは、通常、このキーマップである。
デフォルトのグローバルキーマップは、
すべての印字文字に@code{self-insert-command}をバインドする
完全なキーマップである。
@c It is normal practice to change the bindings in the global map, but you
@c should not assign this variable any value other than the keymap it starts
@c out with.
グローバルマップのバインディングを修正することは実用的ですが、
この変数には、動作開始時のキーマップ以外の値は設定しないこと。
@end defvar
@defun current-global-map
@c This function returns the current global keymap. This is the
@c same as the value of @code{global-map} unless you change one or the
@c other.
この関数は、現在のグローバルキーマップを返す。
@code{global-map}を変更していなければ、
これは@code{global-map}の値と同じである。
@example
@group
(current-global-map)
@result{} (keymap [set-mark-command beginning-of-line @dots{}
delete-backward-char])
@end group
@end example
@end defun
@defun current-local-map
@c This function returns the current buffer's local keymap, or @code{nil}
@c if it has none. In the following example, the keymap for the
@c @samp{*scratch*} buffer (using Lisp Interaction mode) is a sparse keymap
@c in which the entry for @key{ESC}, @sc{ASCII} code 27, is another sparse
@c keymap.
この関数は、カレントバッファのローカルキーマップを返す。
なければ@code{nil}を返す。
つぎの例では、(lisp対話モードを使っている)バッファ@samp{*scratch*}の
キーマップは疎なキーマップであり、
@sc{ASCII}コード27の@key{ESC}に対する指定も別の疎なキーマップである。
@example
@group
(current-local-map)
@result{} (keymap
(10 . eval-print-last-sexp)
(9 . lisp-indent-line)
(127 . backward-delete-char-untabify)
@end group
@group
(27 keymap
(24 . eval-defun)
(17 . indent-sexp)))
@end group
@end example
@end defun
@defun current-minor-mode-maps
@c This function returns a list of the keymaps of currently enabled minor modes.
この関数は、現在オンになっているマイナモードのキーマップのリストを返す。
@end defun
@defun use-global-map keymap
@c This function makes @var{keymap} the new current global keymap. It
@c returns @code{nil}.
この関数は、キーマップ@var{keymap}を新たな現在のグローバルキーマップとする。
これは@code{nil}を返す。
@c It is very unusual to change the global keymap.
グローバルキーマップを変更することは、とうてい普通のことではない。
@end defun
@defun use-local-map keymap
@c This function makes @var{keymap} the new local keymap of the current
@c buffer. If @var{keymap} is @code{nil}, then the buffer has no local
@c keymap. @code{use-local-map} returns @code{nil}. Most major mode
@c commands use this function.
この関数は、キーマップ@var{keymap}をカレントバッファの
新たなローカルキーマップとする。
@var{keymap}が@code{nil}であると、
バッファにはローカルキーマップがなくなる。
@code{use-local-map}は@code{nil}を返す。
ほとんどのメジャーモードコマンドは、この関数を使う。
@end defun
@c Emacs 19 feature
@defvar minor-mode-map-alist
@c This variable is an alist describing keymaps that may or may not be
@c active according to the values of certain variables. Its elements look
@c like this:
この変数は、変数の値に応じて活性になっている/いないキーマップを
記述する連想リストである。
その要素はつぎの形である。
@example
(@var{variable} . @var{keymap})
@end example
@c The keymap @var{keymap} is active whenever @var{variable} has a
@c non-@code{nil} value. Typically @var{variable} is the variable that
@c enables or disables a minor mode. @xref{Keymaps and Minor Modes}.
変数@var{variable}の値が@code{nil}以外であれば、
キーマップ@var{keymap}は活性である。
典型的には、@var{variable}はマイナモードをオン/オフする変数である。
@pxref{Keymaps and Minor Modes}。
@c Note that elements of @code{minor-mode-map-alist} do not have the same
@c structure as elements of @code{minor-mode-alist}. The map must be the
@c @sc{cdr} of the element; a list with the map as the @sc{cadr} will not
@c do. The @sc{cadr} can be either a keymap (a list) or a symbol
@c whose function definition is a keymap.
@code{minor-mode-map-alist}の要素と@code{minor-mode-alist}の要素とは、
異なる構造であることに注意してほしい。
キーマップは要素の@sc{cdr}である必要があり、
要素の@sc{cadr}がキーマップであるようなリストではだめである。
@sc{cadr}は、(リストの)キーマップであるか、
関数定義がキーマップであるシンボルである。
@c When more than one minor mode keymap is active, their order of priority
@c is the order of @code{minor-mode-map-alist}. But you should design
@c minor modes so that they don't interfere with each other. If you do
@c this properly, the order will not matter.
複数のマイナモードキーマップが活性な場合、