-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuffers.texi
1666 lines (1496 loc) · 83.9 KB
/
buffers.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, 1999
@c Free Software Foundation, Inc.
@c See the file elisp.texi for copying conditions.
@setfilename ../info/buffers
@node Buffers, Windows, Backups and Auto-Saving, Top
@c @chapter Buffers
@chapter バッファ @emph{(2003/10/30)}
@c @cindex buffer
@cindex バッファ
@c A @dfn{buffer} is a Lisp object containing text to be edited. Buffers
@c are used to hold the contents of files that are being visited; there may
@c also be buffers that are not visiting files. While several buffers may
@c exist at one time, only one buffer is designated the @dfn{current
@c buffer} at any time. Most editing commands act on the contents of the
@c current buffer. Each buffer, including the current buffer, may or may
@c not be displayed in any windows.
@dfn{バッファ}(buffer)は、編集するテキストを収めている
Lispオブジェクトです。
バッファは、訪問しているファイルのテキストを保持するために使われますが、
ファイルを訪問していないバッファもあります。
一度に複数のバッファが存在してかまいませんが、
ある時点では1つのバッファだけが@dfn{カレントバッファ}
(current buffer)として区別されます。
ほとんどの編集コマンドは、カレントバッファの内容に作用します。
カレントバッファを含む各バッファは、ウィンドウに表示されることも
されないこともあります。
@menu
* Buffer Basics:: What is a buffer?
* Current Buffer:: Designating a buffer as current
so that primitives will access its contents.
* Buffer Names:: Accessing and changing buffer names.
* Buffer File Name:: The buffer file name indicates which file is visited.
* Buffer Modification:: A buffer is @dfn{modified} if it needs to be saved.
* Modification Time:: Determining whether the visited file was changed
``behind Emacs's back''.
* Read Only Buffers:: Modifying text is not allowed in a read-only buffer.
* The Buffer List:: How to look at all the existing buffers.
* Creating Buffers:: Functions that create buffers.
* Killing Buffers:: Buffers exist until explicitly killed.
* Indirect Buffers:: An indirect buffer shares text with some other buffer.
* Buffer Gap:: The gap in the buffer.
@end menu
@node Buffer Basics
@comment node-name, next, previous, up
@c @section Buffer Basics
@section バッファの基本 @emph{(2003/10/30)}
@ifnottex
@c A @dfn{buffer} is a Lisp object containing text to be edited. Buffers
@c are used to hold the contents of files that are being visited; there may
@c also be buffers that are not visiting files. Although several buffers
@c normally exist, only one buffer is designated the @dfn{current
@c buffer} at any time. Most editing commands act on the contents of the
@c current buffer. Each buffer, including the current buffer, may or may
@c not be displayed in any windows.
@dfn{バッファ}(buffer)は、編集するテキストを収めている
Lispオブジェクトです。
バッファは、訪問しているファイルのテキストを保持するために使われますが、
ファイルを訪問していないバッファもあります。複数のバッファは普通に存在
できますが、常に一つのバッファだけが@dfn{カレントバッファ}(current
buffer)となります。
ほとんどの編集コマンドは、カレントバッファの内容に作用します。
カレントバッファを含む各バッファは、ウィンドウに表示されることも
されないこともあります。
@end ifnottex
@c Buffers in Emacs editing are objects that have distinct names and hold
@c text that can be edited. Buffers appear to Lisp programs as a special
@c data type. You can think of the contents of a buffer as a string that
@c you can extend; insertions and deletions may occur in any part of the
@c buffer. @xref{Text}.
@c Emacsの編集においてバッファとは、
異なる名前を持ち編集可能なテキストを保持するオブジェクトです。
バッファは、Lispプログラムには特別なデータ型として見えます。
バッファの内容は拡張可能な文字列であると考えることができます。
つまり、バッファのどの部分ででも挿入や削除を行えるのです。
@xref{Text}。
@c A Lisp buffer object contains numerous pieces of information. Some of
@c this information is directly accessible to the programmer through
@c variables, while other information is accessible only through
@c special-purpose functions. For example, the visited file name is
@c directly accessible through a variable, while the value of point is
@c accessible only through a primitive function.
Lispのバッファオブジェクトには、さまざまな情報が含まれています。
変数を介してプログラマが直接参照できる情報もあれば、
特別目的の関数のみを介して参照できる情報もあります。
たとえば、訪問しているファイルの名前は、変数を介して直接参照できますが、
ポイントの値は基本関数を介してのみ参照できます。
@c Buffer-specific information that is directly accessible is stored in
@c @dfn{buffer-local} variable bindings, which are variable values that are
@c effective only in a particular buffer. This feature allows each buffer
@c to override the values of certain variables. Most major modes override
@c variables such as @code{fill-column} or @code{comment-column} in this
@c way. For more information about buffer-local variables and functions
@c related to them, see @ref{Buffer-Local Variables}.
直接参照可能なバッファに固有の情報は、
@dfn{バッファローカル}(buffer-local)な変数束縛、
つまり、特定のバッファでのみ有効な変数に保持されています。
この機能により、各バッファでは特定の変数の値を優先できます。
ほとんどのメジャーモードでは、このようにして、
@code{fill-column}や@code{comment-column}などの変数を優先させます。
バッファローカルな変数とそれらに関する関数について詳しくは、
@ref{Buffer-Local Variables}を参照してください。
@c For functions and variables related to visiting files in buffers, see
@c @ref{Visiting Files} and @ref{Saving Buffers}. For functions and
@c variables related to the display of buffers in windows, see
@c @ref{Buffers and Windows}.
バッファで訪問しているファイルに関する関数や変数については、
@ref{Visiting Files}と@ref{Saving Buffers}を参照してください。
ウィンドウにバッファを表示することに関する関数や変数については、
@ref{Buffers and Windows}を参照してください。
@defun bufferp object
@c This function returns @code{t} if @var{object} is a buffer,
@c @code{nil} otherwise.
この関数は、@var{object}がバッファであれば@code{t}を返し、
さもなければ@code{nil}を返す。
@end defun
@node Current Buffer
@c @section The Current Buffer
@section カレントバッファ @emph{(2003/10/30)}
@c @cindex selecting a buffer
@c @cindex changing to another buffer
@c @cindex current buffer
@cindex バッファを選ぶ
@cindex 別のバッファへ切り替える
@cindex 切り替え、バッファ
@cindex カレントバッファ
@c There are, in general, many buffers in an Emacs session. At any time,
@c one of them is designated as the @dfn{current buffer}. This is the
@c buffer in which most editing takes place, because most of the primitives
@c for examining or changing text in a buffer operate implicitly on the
@c current buffer (@pxref{Text}). Normally the buffer that is displayed on
@c the screen in the selected window is the current buffer, but this is not
@c always so: a Lisp program can temporarily designate any buffer as
@c current in order to operate on its contents, without changing what is
@c displayed on the screen.
@c 一般に、Emacsセッションには多くのバッファがあります。
いつの時点でも、それらの1つを@dfn{カレントバッファ}
(current buffer)として区別します。
バッファ内のテキストを検査したり変更する基本関数は
暗黙のうちにカレントバッファに作用するため、
ほとんどの編集はカレントバッファに対して行われます
(@pxref{Text})。
通常、スクリーン上で選択されたウィンドウに表示されているバッファが
カレントバッファですが、つねにそうとは限りません。
Lispプログラムでは、スクリーン上の表示は変えずに、
任意のバッファの内容を操作するために
一時的に当該バッファをカレントバッファにできます。
@c The way to designate a current buffer in a Lisp program is by calling
@c @code{set-buffer}. The specified buffer remains current until a new one
@c is designated.
Lispプログラムでカレントバッファを指定するには、
@code{set-buffer}を呼び出します。
新たに指定し直すまで指定したバッファがカレントバッファであり続けます。
@c When an editing command returns to the editor command loop, the
@c command loop designates the buffer displayed in the selected window as
@c current, to prevent confusion: the buffer that the cursor is in when
@c Emacs reads a command is the buffer that the command will apply to.
@c (@xref{Command Loop}.) Therefore, @code{set-buffer} is not the way to
@c switch visibly to a different buffer so that the user can edit it. For
@c that, you must use the functions described in @ref{Displaying Buffers}.
編集コマンドがエディタコマンドループへ戻ると、
コマンドループは、混乱を避けるために、選択されているウィンドウに
表示されているバッファをカレントバッファとします。
つまり、Emacsがコマンドを読むときにカーソルがあるバッファが
コマンドが適用されるバッファです。
(@xref{Command Loop}。)
したがって、@code{set-buffer}は、
ユーザーが編集できるように別のバッファへ切り替える方法にはなりません。
これには、@ref{Displaying Buffers}で述べている関数を使う必要があります。
@c @strong{Note:} Lisp functions that change to a different current buffer
@c should not depend on the command loop to set it back afterwards.
@c Editing commands written in Emacs Lisp can be called from other programs
@c as well as from the command loop; it is convenient for the caller if
@c the subroutine does not change which buffer is current (unless, of
@c course, that is the subroutine's purpose). Therefore, you should
@c normally use @code{set-buffer} within a @code{save-current-buffer} or
@c @code{save-excursion} (@pxref{Excursions}) form that will restore the
@c current buffer when your function is done. Here is an example, the
@c code for the command @code{append-to-buffer} (with the documentation
@c string abridged):
しかし、別のカレントバッファに替えるLisp関数では、
コマンドループがカレントバッファを
あとで戻すということに依存してはいけません。
Emacs Lispで書かれた編集コマンドは、コマンドループに加えて
別のプログラムからも呼ばれます。
サブルーティンがカレントバッファを替えないほうが
(それがサブルーティンの目的でなければ)、
呼び出し側にとっては便利です。
したがって、関数の実行が終るともとのカレントバッファに戻す
フォーム@code{save-current-buffer}や
@code{save-excursion}(@pxref{Excursions})の内側で、
普通は@code{set-buffer}を使います。
例として、(説明文字列を簡略にして)コマンド@code{append-to-buffer}
のコードを示します。
@example
@group
(defun append-to-buffer (buffer start end)
"Append to specified buffer the text of the region.
@dots{}"
(interactive "BAppend to buffer: \nr")
(let ((oldbuf (current-buffer)))
(save-current-buffer
(set-buffer (get-buffer-create buffer))
(insert-buffer-substring oldbuf start end))))
@end group
@end example
@noindent
@c This function binds a local variable to record the current buffer, and
@c then @code{save-current-buffer} arranges to make it current again.
@c Next, @code{set-buffer} makes the specified buffer current. Finally,
@c @code{insert-buffer-substring} copies the string from the original
@c current buffer to the specified (and now current) buffer.
この関数では、ローカル変数を束縛してカレントバッファを記録し、
@code{save-current-buffer}でそれがカレントバッファに戻るようにしています。
つぎに、@code{set-buffer}で指定したバッファをカレントバッファにします。
最後に、@code{insert-buffer-substring}でもとのカレントバッファから
指定された(いまはカレント)バッファに文字列をコピーします。
@c If the buffer appended to happens to be displayed in some window,
@c the next redisplay will show how its text has changed. Otherwise, you
@c will not see the change immediately on the screen. The buffer becomes
@c current temporarily during the execution of the command, but this does
@c not cause it to be displayed.
内容を付加したバッファがどれかのウィンドウに表示されていると、
つぎに表示を更新したときに変更されたテキストが表示されます。
それ以外では、スクリーン上でただちには変更を見ることはできません。
コマンドの実行中にはバッファが一時的にカレントバッファになりますが、
それによりそのバッファが表示されるわけではありません。
@c If you make local bindings (with @code{let} or function arguments) for
@c a variable that may also have buffer-local bindings, make sure that the
@c same buffer is current at the beginning and at the end of the local
@c binding's scope. Otherwise you might bind it in one buffer and unbind
@c it in another! There are two ways to do this. In simple cases, you may
@c see that nothing ever changes the current buffer within the scope of the
@c binding. Otherwise, use @code{save-current-buffer} or
@c @code{save-excursion} to make sure that the buffer current at the
@c beginning is current again whenever the variable is unbound.
バッファローカルな束縛を持つ変数を(@code{let}や関数の引数で)
ローカルに束縛する場合には、ローカルな束縛の有効範囲の開始時と終了時には、
同じバッファが必ずカレントバッファであるようにします。
さもないと、あるバッファでは変数を束縛し、
別のバッファではその束縛を解除してしまうことがあります。
これには2つの方法があります。
単純な場合には、束縛の有効範囲内で
カレントバッファが替わらないを確認します。
さもなければ、@code{save-current-buffer}や@code{save-excursion}を使って、
始めにカレントバッファであったバッファが、
変数束縛が解除されるときにはつねにカレントバッファであるようにします。
@c Do not rely on using @code{set-buffer} to change the current buffer
@c back, because that won't do the job if a quit happens while the wrong
@c buffer is current. Here is what @emph{not} to do:
@code{set-buffer}でカレントバッファに戻すことを期待してはいけません。
正しくないバッファがカレントバッファであるときに
中断が起きると戻せないからです。
しては@emph{いけない}ことをつぎに示します。
@example
@group
(let (buffer-read-only
(obuf (current-buffer)))
(set-buffer @dots{})
@dots{}
(set-buffer obuf))
@end group
@end example
@noindent
@c Using @code{save-current-buffer}, as shown here, handles quitting,
@c errors, and @code{throw}, as well as ordinary evaluation.
つぎのように@code{save-current-buffer}を使えば、
通常の評価に加えて、中断、エラー、@code{throw}も扱えます。
@example
@group
(let (buffer-read-only)
(save-current-buffer
(set-buffer @dots{})
@dots{}))
@end group
@end example
@defun current-buffer
@c This function returns the current buffer.
この関数はカレントバッファを返す。
@example
@group
(current-buffer)
@result{} #<buffer buffers.texi>
@end group
@end example
@end defun
@defun set-buffer buffer-or-name
@c This function makes @var{buffer-or-name} the current buffer. This does
@c not display the buffer in any window, so the user cannot necessarily see
@c the buffer. But Lisp programs will now operate on it.
この関数は、@var{buffer-or-name}をカレントバッファにする。
この関数はどのウィンドウにも
当該バッファを表示しないので、ユーザーが当該バッファを見られるとは限らない。
しかし、Lispプログラムはいずれにしても当該バッファを操作できる。
@c This function returns the buffer identified by @var{buffer-or-name}.
@c An error is signaled if @var{buffer-or-name} does not identify an
@c existing buffer.
この関数は@var{buffer-or-name}で指定されるバッファを返す。
@var{buffer-or-name}が既存のバッファを指定しなければ、エラーを通知する。
@end defun
@defspec save-current-buffer body...
@c The @code{save-current-buffer} macro saves the identity of the current
@c buffer, evaluates the @var{body} forms, and finally restores that buffer
@c as current. The return value is the value of the last form in
@c @var{body}. The current buffer is restored even in case of an abnormal
@c exit via @code{throw} or error (@pxref{Nonlocal Exits}).
マクロ@code{save-current-buffer}は、
カレントバッファの識別子を保存し、フォーム@var{body}を評価し、
最後にもとのカレントバッファに戻す。
戻り値は、@var{body}の最後のフォームの値である。
@code{throw}やエラー(@pxref{Nonlocal Exits})による異常終了であっても
カレントバッファは戻される。
@c If the buffer that used to be current has been killed by the time of
@c exit from @code{save-current-buffer}, then it is not made current again,
@c of course. Instead, whichever buffer was current just before exit
@c remains current.
@code{save-current-buffer}から抜けるときに、
もとのカレントバッファとして使われていたバッファが削除されていると、
もちろん、カレントバッファにはならない。
そのかわりに、抜けるまえにカレントバッファであったバッファが
カレントバッファであり続ける。
@end defspec
@defmac with-current-buffer buffer body...
@c The @code{with-current-buffer} macro saves the identity of the current
@c buffer, makes @var{buffer} current, evaluates the @var{body} forms, and
@c finally restores the buffer. The return value is the value of the last
@c form in @var{body}. The current buffer is restored even in case of an
@c abnormal exit via @code{throw} or error (@pxref{Nonlocal Exits}).
マクロ@code{with-current-buffer}は、
カレントバッファの識別子を保存し、
@var{buffer}をカレントバッファにし、フォーム@var{body}を評価し、
最後にもとのカレントバッファに戻す。
戻り値は、@var{body}の最後のフォームの値である。
@code{throw}やエラー(@pxref{Nonlocal Exits})による異常終了であっても
カレントバッファは戻される。
@end defmac
@defmac with-temp-buffer body...
@c The @code{with-temp-buffer} macro evaluates the @var{body} forms
@c with a temporary buffer as the current buffer. It saves the identity of
@c the current buffer, creates a temporary buffer and makes it current,
@c evaluates the @var{body} forms, and finally restores the previous
@c current buffer while killing the temporary buffer.
マクロ@code{with-temp-buffer}は、
一時的なバッファをカレントバッファとして
フォーム@var{body}を評価する。
カレントバッファの識別子を保存し、
一時的なバッファを作成してそれをカレントバッファにし、
フォーム@var{body}を評価し、
最後にもとのカレントバッファに戻すとともに一時的なバッファを削除する。
@c The return value is the value of the last form in @var{body}. You can
@c return the contents of the temporary buffer by using
@c @code{(buffer-string)} as the last form.
戻り値は、@var{body}の最後のフォームの値である。
最後のフォームとして@code{(buffer-string)}を使えば、
一時的なバッファの内容を返せる。
@c The current buffer is restored even in case of an abnormal exit via
@c @code{throw} or error (@pxref{Nonlocal Exits}).
@code{throw}やエラー(@pxref{Nonlocal Exits})による異常終了であっても
カレントバッファは戻される。
@end defmac
@c See also @code{with-temp-file} in @ref{Writing to Files}.
@ref{Writing to Files}の@code{with-temp-file}も参照してください。
@node Buffer Names
@c @section Buffer Names
@section バッファ名 @emph{(2003/10/30)}
@c @cindex buffer names
@cindex バッファ名
@c Each buffer has a unique name, which is a string. Many of the
@c functions that work on buffers accept either a buffer or a buffer name
@c as an argument. Any argument called @var{buffer-or-name} is of this
@c sort, and an error is signaled if it is neither a string nor a buffer.
@c Any argument called @var{buffer} must be an actual buffer
@c object, not a name.
各バッファには、文字列で一意な名前があります。
バッファに作用するほとんどの関数は、
引数としてバッファかバッファ名を受け付けます。
@var{buffer-or-name}という名前の引数はこの種のものであり、
当該引数が文字列でもバッファでもないとエラーを通知します。
@var{buffer}という名前の引数は
実際のバッファオブジェクトである必要があり、名前ではだめです。
@c Buffers that are ephemeral and generally uninteresting to the user
@c have names starting with a space, so that the @code{list-buffers} and
@c @code{buffer-menu} commands don't mention them. A name starting with
@c space also initially disables recording undo information; see
@c @ref{Undo}.
短命で一般にはユーザーが関心を示さないバッファの名前は空白で始まり、
コマンド@code{list-buffers}や@code{buffer-menu}はそれらを表示しません。
さらに、空白で始まる名前のバッファでは、
アンドゥ情報の記録も最初は禁止してあります。
@ref{Undo}を参照してください。
@defun buffer-name &optional buffer
@c This function returns the name of @var{buffer} as a string. If
@c @var{buffer} is not supplied, it defaults to the current buffer.
この関数は、@var{buffer}の名前を文字列で返す。
@var{buffer}を指定しないと、デフォルトはカレントバッファである。
@c If @code{buffer-name} returns @code{nil}, it means that @var{buffer}
@c has been killed. @xref{Killing Buffers}.
@code{buffer-name}が@code{nil}を返す場合、
@var{buffer}が削除されたことを意味する。
@pxref{Killing Buffers}。
@example
@group
(buffer-name)
@result{} "buffers.texi"
@end group
@group
(setq foo (get-buffer "temp"))
@result{} #<buffer temp>
@end group
@group
(kill-buffer foo)
@result{} nil
@end group
@group
(buffer-name foo)
@result{} nil
@end group
@group
foo
@result{} #<killed buffer>
@end group
@end example
@end defun
@c @deffn Command rename-buffer newname &optional unique
@deffn コマンド rename-buffer newname &optional unique
@c This function renames the current buffer to @var{newname}. An error
@c is signaled if @var{newname} is not a string, or if there is already a
@c buffer with that name. The function returns @var{newname}.
この関数は、カレントバッファを@var{newname}と改名する。
@var{newname}が文字列でなかったり、
当該名のバッファがすでに存在していると、エラーを通知する。
関数は@var{newname}を返す。
@c @c Emacs 19 feature
@c Ordinarily, @code{rename-buffer} signals an error if @var{newname} is
@c already in use. However, if @var{unique} is non-@code{nil}, it modifies
@c @var{newname} to make a name that is not in use. Interactively, you can
@c make @var{unique} non-@code{nil} with a numeric prefix argument.
@c (This is how the command @code{rename-uniquely} is implemented.)
通常、@var{newname}がすでに使われていると、
@code{rename-buffer}はエラーを通知する。
しかし、@var{unique}が@code{nil}以外であると、
@var{newname}を未使用な名前に修正する。
対話的に呼び出した場合、数値前置引数を指定すると
@var{unique}は@code{nil}以外になる。(このように@code{rename-uniquely}
は実行されるのです)
@c One application of this command is to rename the @samp{*shell*} buffer
@c to some other name, thus making it possible to create a second shell
@c buffer under the name @samp{*shell*}.
このコマンドの1つの用途は、
バッファ@samp{*shell*}を別の名前に改名して、
同じ@samp{*shell*}という名前で別のシェルを作れるようにすることである。
@end deffn
@defun get-buffer buffer-or-name
@c This function returns the buffer specified by @var{buffer-or-name}.
@c If @var{buffer-or-name} is a string and there is no buffer with that
@c name, the value is @code{nil}. If @var{buffer-or-name} is a buffer, it
@c is returned as given; that is not very useful, so the argument is usually
@c a name. For example:
この関数は、@var{buffer-or-name}で指定したバッファを返す。
@var{buffer-or-name}が文字列であり、
そのような名前のバッファが存在しなければ@code{nil}を返す。
@var{buffer-or-name}がバッファであればそれ自身を返す。
これは有用ではないので、普通、引数は名前である。
例を示す。
@example
@group
(setq b (get-buffer "lewis"))
@result{} #<buffer lewis>
@end group
@group
(get-buffer b)
@result{} #<buffer lewis>
@end group
@group
(get-buffer "Frazzle-nots")
@result{} nil
@end group
@end example
@c See also the function @code{get-buffer-create} in @ref{Creating Buffers}.
@ref{Creating Buffers}の関数@code{get-buffer-create}も参照。
@end defun
@c Emacs 19 feature
@defun generate-new-buffer-name starting-name &rest ignore
@c This function returns a name that would be unique for a new buffer---but
@c does not create the buffer. It starts with @var{starting-name}, and
@c produces a name not currently in use for any buffer by appending a
@c number inside of @samp{<@dots{}>}.
この関数は、新たなバッファ向けの一意な名前を返すが、バッファは作成しない。
名前は@var{starting-name}で始まり、
@samp{<@dots{}>}で囲った数を追加することで、
どのバッファでも現在使っていない名前を作成する。
@c If the optional second argument @var{ignore} is non-@code{nil}, it
@c should be a string; it makes a difference if it is a name in the
@c sequence of names to be tried. That name will be considered acceptable,
@c if it is tried, even if a buffer with that name exists. Thus, if
@c buffers named @samp{foo}, @samp{foo<2>}, @samp{foo<3>} and @samp{foo<4>}
@c exist,
2番目のオプション引数@var{ignore}が@code{nil}でなければ、文字列を与え
る必要がある。一意な名前を探す時に、@var{ignore}で設定した名前があると
動作が異なってくる。指定した名前がたとえ既に存在しているバッファの名前
であったとしても、一意な名前と認識するのである。例えば、@samp{foo},
@samp{foo<2>}, @samp{foo<3>} and @samp{foo<4>} という名前のバッファが
あるとすると、
@example
(generate-new-buffer-name "foo")
@result{} "foo<5>"
(generate-new-buffer-name "foo" "foo<3>")
@result{} "foo<3>"
(generate-new-buffer-name "foo" "foo<6>")
@result{} "foo<5>"
@end example
のように、@samp{foo<3>}というバッファが既に存在していても、
@var{ignore} で設定すると、一意なバッファ名として@samp{foo<3>} が返っ
てくるのである。
@c See the related function @code{generate-new-buffer} in @ref{Creating
@c Buffers}.
@ref{Creating Buffers}の関連する関数@code{generate-new-buffer}を参照。
@end defun
@node Buffer File Name
@c @section Buffer File Name
@section バッファファイル名 @emph{(2003/10/30)}
@c @cindex visited file
@c @cindex buffer file name
@c @cindex file name of buffer
@cindex 訪問しているファイル
@cindex バッファファイル名
@cindex バッファのファイル名
@cindex ファイル名、バッファ
@c The @dfn{buffer file name} is the name of the file that is visited in
@c that buffer. When a buffer is not visiting a file, its buffer file name
@c is @code{nil}. Most of the time, the buffer name is the same as the
@c nondirectory part of the buffer file name, but the buffer file name and
@c the buffer name are distinct and can be set independently.
@c @xref{Visiting Files}.
@dfn{バッファファイル名}(buffer file name)とは、
当該バッファで訪問しているファイルの名前です。
バッファでファイルを訪問していないときには、
バッファファイル名は@code{nil}です。
ほとんどの場面で、バッファ名は
バッファファイル名の非ディレクトリ部分と同じですが、
バッファファイル名とバッファ名は別のものであり個別に設定できます。
@xref{Visiting Files}。
@defun buffer-file-name &optional buffer
@c This function returns the absolute file name of the file that
@c @var{buffer} is visiting. If @var{buffer} is not visiting any file,
@c @code{buffer-file-name} returns @code{nil}. If @var{buffer} is not
@c supplied, it defaults to the current buffer.
この関数は、@var{buffer}で訪問しているファイルの
絶対ファイル名を返す。
@var{buffer}がファイルを訪問していなければ、
@code{buffer-file-name}は@code{nil}を返す。
@var{buffer}を指定しないと、
デフォルトはカレントバッファである。
@example
@group
(buffer-file-name (other-buffer))
@result{} "/usr/user/lewis/manual/files.texi"
@end group
@end example
@end defun
@defvar buffer-file-name
@c This buffer-local variable contains the name of the file being visited
@c in the current buffer, or @code{nil} if it is not visiting a file. It
@c is a permanent local variable, unaffected by
@c @code{kill-all-local-variables}.
このバッファローカルな変数は、
カレントバッファで訪問しているファイルの名前を保持する。
あるいは、ファイルを訪問していなければ@code{nil}である。
これは恒久的にバッファローカルな変数であり、
@code{kill-all-local-variables}に影響されない。
@example
@group
buffer-file-name
@result{} "/usr/user/lewis/manual/buffers.texi"
@end group
@end example
@c It is risky to change this variable's value without doing various other
@c things. Normally it is better to use @code{set-visited-file-name} (see
@c below); some of the things done there, such as changing the buffer name,
@c are not strictly necessary, but others are essential to avoid confusing
@c Emacs.
他のさまざまなことを行わずにこの変数の値だけを変更することは危険である。
通常、@code{set-visited-file-name}(下記参照)を使うほうがよい。
バッファ名を変更するなどの重要でないことも行うが、
Emacsを混乱させないように本質的なことも行うからである。
@end defvar
@defvar buffer-file-truename
@c This buffer-local variable holds the truename of the file visited in the
@c current buffer, or @code{nil} if no file is visited. It is a permanent
@c local, unaffected by @code{kill-all-local-variables}. @xref{Truenames}.
このバッファローカルな変数は、
カレントバッファで訪問しているファイルの実名を保持する。
あるいは、ファイルを訪問していなければ@code{nil}である。
これは恒久的にバッファローカルであり、
@code{kill-all-local-variables}に影響されない。
@pxref{Truenames}。
@end defvar
@defvar buffer-file-number
@c This buffer-local variable holds the file number and directory device
@c number of the file visited in the current buffer, or @code{nil} if no
@c file or a nonexistent file is visited. It is a permanent local,
@c unaffected by @code{kill-all-local-variables}.
このバッファローカルな変数は、
カレントバッファで訪問しているファイルの
ファイル番号とディレクトリ装置番号を保持する。
あるいは、ファイルを訪問していなければ@code{nil}である。
これは恒久的にバッファローカルであり、
@code{kill-all-local-variables}に影響されない。
@c The value is normally a list of the form @code{(@var{filenum}
@c @var{devnum})}. This pair of numbers uniquely identifies the file among
@c all files accessible on the system. See the function
@c @code{file-attributes}, in @ref{File Attributes}, for more information
@c about them.
この値は、通常、@code{(@var{filenum} @var{devnum})}の形のリストである。
この数の対により、システム上のすべての参照可能なファイルを一意に識別できる。
これらについてより詳しくは、
@ref{File Attributes}の関数@code{file-attributes}を参照。
@end defvar
@defun get-file-buffer filename
@c This function returns the buffer visiting file @var{filename}. If
@c there is no such buffer, it returns @code{nil}. The argument
@c @var{filename}, which must be a string, is expanded (@pxref{File Name
@c Expansion}), then compared against the visited file names of all live
@c buffers.
この関数は、ファイル@var{filename}を訪問しているバッファを返す。
そのようなバッファが存在しなければ@code{nil}を返す。
引数@var{filename}は文字列であり、
展開(@pxref{File Name Expansion})してから
すべてのバッファの訪問しているファイル名と比較する。
@example
@group
(get-file-buffer "buffers.texi")
@result{} #<buffer buffers.texi>
@end group
@end example
@c In unusual circumstances, there can be more than one buffer visiting
@c the same file name. In such cases, this function returns the first
@c such buffer in the buffer list.
稀れな状況では、複数のバッファが同じ名前のファイルを訪問している場合がある。
そのような場合、この関数はバッファリストで最初にみつかったバッファを返す。
@end defun
@c @deffn Command set-visited-file-name filename &optional no-query along-with-file
@deffn コマンド set-visited-file-name filename &optional no-query along-with-file
@c If @var{filename} is a non-empty string, this function changes the
@c name of the file visited in the current buffer to @var{filename}. (If the
@c buffer had no visited file, this gives it one.) The @emph{next time}
@c the buffer is saved it will go in the newly-specified file. This
@c command marks the buffer as modified, since it does not (as far as Emacs
@c knows) match the contents of @var{filename}, even if it matched the
@c former visited file.
@var{filename}が空でない文字列であると、
この関数はカレントバッファで訪問しているファイルの名前を
@var{filename}に変える。
(ファイルを訪問していないバッファでは、
当該バッファに訪問しているファイル名を指定する。)
バッファを@emph{つぎに}保存すると、指定した新たなファイルに保存される。
このコマンドは、バッファに変更済みと印を付ける。
変更まえの訪問しているファイルの内容とバッファ内容が一致していたとしても
(Emacsにとっては)
バッファ内容は@var{filename}の内容と一致しないからである。
@c If @var{filename} is @code{nil} or the empty string, that stands for
@c ``no visited file''. In this case, @code{set-visited-file-name} marks
@c the buffer as having no visited file.
@var{filename}が@code{nil}だったり空文字列であると、
『ファイルを訪問していない』ことにする。
この場合、@code{set-visited-file-name}は、
当該バッファではファイルを訪問していないと印を付ける。
@c Normally, this function asks the user for confirmation if the specified
@c file already exists. If @var{no-query} is non-@code{nil}, that prevents
@c asking this question.
通常、この関数は、指定したファイルが既存の場合には
ユーザーに確認をとる。
@var{no-query}が@code{nil}以外であると、確認をとらない。
@c If @var{along-with-file} is non-@code{nil}, that means to assume that the
@c former visited file has been renamed to @var{filename}.
@var{along-with-file}が@code{nil}以外であると、
それ以前に訪問していたファイルは@var{filename}と改名してあると仮定する。
@c @c Wordy to avoid overfull hbox. --rjc 16mar92
@c When the function @code{set-visited-file-name} is called interactively, it
@c prompts for @var{filename} in the minibuffer.
関数@code{set-visited-file-name}を対話的に呼び出すと、
ミニバッファで@var{filename}を問い合わせる。
@end deffn
@defvar list-buffers-directory
@c This buffer-local variable specifies a string to display in a buffer
@c listing where the visited file name would go, for buffers that don't
@c have a visited file name. Dired buffers use this variable.
このバッファローカルな変数は、
訪問しているファイル名を持たないバッファに対して、
バッファ一覧において訪問しているファイル名を表示する部分に
表示する文字列を指定する。
diredのバッファはこの変数を使う。
@end defvar
@node Buffer Modification
@c @section Buffer Modification
@section バッファの変更 @emph{(2003/10/30)}
@c @cindex buffer modification
@c @cindex modification flag (of buffer)
@cindex バッファの変更
@cindex 変更フラグ、バッファ
@c Emacs keeps a flag called the @dfn{modified flag} for each buffer, to
@c record whether you have changed the text of the buffer. This flag is
@c set to @code{t} whenever you alter the contents of the buffer, and
@c cleared to @code{nil} when you save it. Thus, the flag shows whether
@c there are unsaved changes. The flag value is normally shown in the mode
@c line (@pxref{Mode Line Variables}), and controls saving (@pxref{Saving
@c Buffers}) and auto-saving (@pxref{Auto-Saving}).
Emacsは、各バッファごとに当該バッファのテキストを変更したかどうかを
記録する@dfn{変更フラグ}(modified flag)と呼ばれるフラグを保持しています。
バッファの内容が変わるたびにこのフラグは@code{t}に設定され、
保存するたびに@code{nil}に設定されます。
つまり、このフラグは未保存の変更があるかどうかを表します。
このフラグの値は通常モード行(@pxref{Mode Line Variables})に表示され、
保存(@pxref{Saving Buffers})と
自動保存(@pxref{Auto-Saving})を制御します。
@c Some Lisp programs set the flag explicitly. For example, the function
@c @code{set-visited-file-name} sets the flag to @code{t}, because the text
@c does not match the newly-visited file, even if it is unchanged from the
@c file formerly visited.
このフラグを明示的に設定するLispプログラムもあります。
たとえば、関数@code{set-visited-file-name}はこのフラグを@code{t}に設定します。
ファイルを訪問してから変更していなくても、
バッファのテキストが新たな訪問しているファイルとは一致しないからです。
@c The functions that modify the contents of buffers are described in
@c @ref{Text}.
バッファの内容を変更する関数については@ref{Text}に述べてあります。
@defun buffer-modified-p &optional buffer
@c This function returns @code{t} if the buffer @var{buffer} has been modified
@c since it was last read in from a file or saved, or @code{nil}
@c otherwise. If @var{buffer} is not supplied, the current buffer
@c is tested.
この関数は、最後にファイルから読み込んだり保存してから
バッファ@var{buffer}が変更されていれば@code{t}を返し、
さもなければ@code{nil}を返す。
@var{buffer}を指定しないとカレントバッファを調べる。
@end defun
@defun set-buffer-modified-p flag
@c This function marks the current buffer as modified if @var{flag} is
@c non-@code{nil}, or as unmodified if the flag is @code{nil}.
この関数は、@var{flag}が@code{nil}以外であれば
カレントバッファは変更されていると印を付け、
@code{nil}ならば未変更であると印を付ける。
@c Another effect of calling this function is to cause unconditional
@c redisplay of the mode line for the current buffer. In fact, the
@c function @code{force-mode-line-update} works by doing this:
この関数を呼び出した別の効果として、
カレントバッファのモード行を無条件に再表示する。
実際、関数@code{force-mode-line-update}はつぎのようにしている。
@example
@group
(set-buffer-modified-p (buffer-modified-p))
@end group
@end example
@end defun
@c @deffn Command not-modified
@deffn コマンド not-modified
@c This command marks the current buffer as unmodified, and not needing to
@c be saved. With prefix arg, it marks the buffer as modified, so that it
@c will be saved at the next suitable occasion.
このコマンドは、カレントバッファを未変更であり
保存する必要がないと印を付ける。
前置引数を指定すると、バッファに変更されていると印を付け、
以降の適当な場面で保存される。
@c Don't use this function in programs, since it prints a message in the
@c echo area; use @code{set-buffer-modified-p} (above) instead.
エコー領域にメッセージを表示するので、
プログラムからこの関数を使わないこと。
かわりに@code{set-buffer-modified-p}を使う(上記)。
@end deffn
@c Emacs 19 feature
@defun buffer-modified-tick &optional buffer
@c This function returns @var{buffer}'s modification-count. This is a
@c counter that increments every time the buffer is modified. If
@c @var{buffer} is @code{nil} (or omitted), the current buffer is used.
この関数は、@var{buffer}の変更回数を返す。
変更回数はバッファを変更するたびに増やされる。
@var{buffer}が@code{nil}であると(あるいは省略すると)、
カレントバッファを使う。
@end defun
@node Modification Time
@comment node-name, next, previous, up
@c @section Comparison of Modification Time
@section 更新時刻の比較 @emph{(2003/10/30)}
@c @cindex comparison of modification time
@c @cindex modification time, comparison of
@cindex 比較、更新時刻
@cindex 更新時刻の比較
@c Suppose that you visit a file and make changes in its buffer, and
@c meanwhile the file itself is changed on disk. At this point, saving the
@c buffer would overwrite the changes in the file. Occasionally this may
@c be what you want, but usually it would lose valuable information. Emacs
@c therefore checks the file's modification time using the functions
@c described below before saving the file.
ファイルを訪問してそのバッファで変更したとします。
そのあいだに、ディスク上の当該ファイル自身も変更されたとします。
ここでバッファを保存すると、ファイルの変更内容を上書きしてしまいます。
たしかにこれを望む場合もあるでしょうが、
普通は重要な情報を失うことになります。
そのため、Emacsは、ファイルに保存するまえに、
以下に述べる関数を用いてファイルの更新時刻を検査します。
@defun verify-visited-file-modtime buffer
@c This function compares what @var{buffer} has recorded for the
@c modification time of its visited file against the actual modification
@c time of the file as recorded by the operating system. The two should be
@c the same unless some other process has written the file since Emacs
@c visited or saved it.
この関数は、@var{buffer}に記録してある
訪問しているファイルの更新時刻と、
オペレーティングシステムが記録している
ファイルの実際の更新時刻を比較する。
Emacsが当該ファイルを訪問したり保存してから
他のプロセスが当該ファイルに書いていない限り、
2つの時刻は同じはずである。
@c The function returns @code{t} if the last actual modification time and
@c Emacs's recorded modification time are the same, @code{nil} otherwise.
実際の更新時刻とEmacsに記録している更新時刻が同じならば@code{t}を返し、
さもなければ@code{nil}を返す。
@end defun
@defun clear-visited-file-modtime
@c This function clears out the record of the last modification time of
@c the file being visited by the current buffer. As a result, the next
@c attempt to save this buffer will not complain of a discrepancy in
@c file modification times.
この関数は、カレントバッファで訪問しているファイルの
最終更新時刻の記録を破棄する。
その結果、つぎにこのバッファを保存しようとしても、
ファイルの更新時刻のと不一致を報告しない。
@c This function is called in @code{set-visited-file-name} and other
@c exceptional places where the usual test to avoid overwriting a changed
@c file should not be done.
この関数は、@code{set-visited-file-name}や
変更されたファイルを上書きしないためのテストを行わない例外的な場面で
呼び出される。
@end defun
@c Emacs 19 feature
@defun visited-file-modtime
@c This function returns the buffer's recorded last file modification time,
@c as a list of the form @code{(@var{high} . @var{low})}. (This is the
@c same format that @code{file-attributes} uses to return time values; see
@c @ref{File Attributes}.)
この関数は、
バッファに記録されているファイルの最終更新時刻を
@code{(@var{high} . @var{low})}の形のリストで返す。
(これは@code{file-attributes}が時刻を返すために使う形と同じである。
@ref{File Attributes}を参照。)
@end defun
@c Emacs 19 feature
@defun set-visited-file-modtime &optional time
@c This function updates the buffer's record of the last modification time
@c of the visited file, to the value specified by @var{time} if @var{time}
@c is not @code{nil}, and otherwise to the last modification time of the
@c visited file.
この関数は、@var{time}が@code{nil}以外であるときには、
バッファに記録してあるファイルの最終更新時刻を
@var{time}で指定された時刻にする。
さもなければ、訪問しているファイルの最終更新時刻にする。
@c If @var{time} is not @code{nil}, it should have the form
@c @code{(@var{high} . @var{low})} or @code{(@var{high} @var{low})}, in
@c either case containing two integers, each of which holds 16 bits of the
@c time.
@var{time}が@code{nil}でないときには、
@code{(@var{high} . @var{low})}か@code{(@var{high} @var{low})}の形であること。
いずれの場合も、2つの整数は時刻の16ビットを保持する。
@c This function is useful if the buffer was not read from the file
@c normally, or if the file itself has been changed for some known benign
@c reason.
この関数は、ファイルから普通に読み込んだのではないバッファや
ファイル自体が明確な理由で変更された場合に有用である。
@end defun
@defun ask-user-about-supersession-threat filename
@c @cindex obsolete buffer
@cindex 廃れたバッファ
@c This function is used to ask a user how to proceed after an attempt to
@c modify an obsolete buffer visiting file @var{filename}. An
@c @dfn{obsolete buffer} is an unmodified buffer for which the associated
@c file on disk is newer than the last save-time of the buffer. This means
@c some other program has probably altered the file.
この関数は、ファイル@var{filename}を訪問している廃れたバッファを
変更しようとしたときにどのように処理すべきかをユーザーに問い合わせる
ために用いる。
@dfn{廃れたバッファ}(obsolete buffer)とは、
未変更のバッファではあるが、対応するディスク上のファイルが
バッファの最終更新時刻よりも新しいものである。
つまり、別のプログラムが当該ファイルを変更した可能性があることを意味する。
@kindex file-supersession
@c Depending on the user's answer, the function may return normally, in
@c which case the modification of the buffer proceeds, or it may signal a
@c @code{file-supersession} error with data @code{(@var{filename})}, in which
@c case the proposed buffer modification is not allowed.
ユーザーの応答に依存して、関数は正常に戻る。
その場合、バッファは変更できる。
あるいは、データ@code{(@var{filename})}を付けて
エラー@code{file-supersession}を通知する。
その場合、バッファの変更は許されない。
@c This function is called automatically by Emacs on the proper
@c occasions. It exists so you can customize Emacs by redefining it.
@c See the file @file{userlock.el} for the standard definition.
この関数は、適切な場面でEmacsが自動的に呼び出す。
これを再定義することでEmacsをカスタマイズできるようにしている。
標準定義についてはファイル@file{userlock.el}を参照。
@c See also the file locking mechanism in @ref{File Locks}.
@ref{File Locks}のファイルロック機構も参照。
@end defun