2012年4月6日金曜日

Emacs Lisp のバッファとミニバッファ, エコーエリア

1. バッファ

テキストファイルを Emacs で開くと、内容はバッファに存在する。

Buffers - GNU Emacs Manual

The text you are editing in Emacs resides in an object called a buffer. …

Each buffer has a unique name, which can be of any length. …

At any time, one and only one buffer is current.

バッファは、Lisp オブジェクト。編集できるテキストを含んでいる。

Buffers - GNU Emacs Lisp Reference Manual

A buffer is a Lisp object containing text to be edited. … While several buffers may exist at one time, only one buffer is designated the current buffer at any time. Most editing commands act on the contents of the current buffer. …

バッファは複数存在する。編集用のコマンドが作用する対象は、カレントバッファと呼ばれる。

*scratch* バッファで

(current-buffer)

を評価すると、

#<buffer *scratch*>

#< … > という形式で表示される理由は、バッファそのものを、人間が読み取れる形式で表す適切な表現がないため。

Printed Representation - GNU Emacs Lisp Reference Manual によると、

In most cases, an object's printed representation is also a read syntax for the object. However, some types have no read syntax, since it does not make sense to enter objects of these types as constants in a Lisp program. These objects are printed in hash notation, which consists of the characters ‘#<’, a descriptive string (typically the type name followed by the name of the object), and a closing ‘>’.

 

バッファの型

Lisp オブジェクトは、Lisp プログラムが操作する対象であるデータ。全てのオブジェクトは、型を持つ。

Lisp Data Types - GNU Emacs Lisp Reference Manual

A Lisp object is a piece of data used and manipulated by Lisp programs. …

Every object belongs to at least one type. Objects of the same type have similar structures and may usually be used in the same contexts.

バッファは、Editing Types の一つに挙げられている。

Editing Types - GNU Emacs Lisp Reference Manual

Buffer Type: The basic object of editing.

バッファの型を確認するには、type-of 関数を用いる。

Type Predicates - GNU Emacs Lisp Reference Manual

The most general way to check the type of an object is to call the function type-of. …

— Function: type-of object

This function returns a symbol naming the primitive type of object.

(type-of (current-buffer))

を評価した結果は、

buffer

と表示される

 

*scratch* バッファ

Emacs を起動すると存在する *scratch* バッファについては、以下を参照。

Startup Summary - GNU Emacs Lisp Reference Manual

  • If the buffer ‘*scratch*’ exists and is still in Fundamental mode (as it should be by default), it sets its major mode according to initial-major-mode.
  • Auto Major Mode - GNU Emacs Lisp Reference Manual

    — User Option: initial-major-mode

    The value of this variable determines the major mode of the initial ‘*scratch*’ buffer. The value should be a symbol that is a major mode command. The default value is lisp-interaction-mode.

     

    2. ミニバッファ

    文字列を置換するときに使う、query-replace コマンドは、ミニバッファを使う。

    query-replace コマンドを実行すると、検索する単語と、置換する単語の入力が促される。その際、入力した内容は、通常のバッファと同じように、編集用のコマンドを適用できる。

    query-replace 関数のプロンプトは、エコーエリアと同じ場所に表示される。ミニバッファは、最後にコロンが表示されることが多い。渡した値は、関数の引数となる。

    Minibuffer - GNU Emacs Manual

    The minibuffer is where Emacs commands read complicated arguments, such as file names, buffer names, Emacs command names, or Lisp expressions. We call it the “minibuffer” because it's a special-purpose buffer with a small amount of screen space. You can use the usual Emacs editing commands in the minibuffer to edit the argument text.

    When the minibuffer is in use, it appears in the echo area, with a cursor. The minibuffer display starts with a prompt in a distinct color, usually ending with a colon. The prompt states what kind of input is expected, and how it will be used.

    エコーエリアは、エラーメッセージや、message 関数による出力内容が表示される。

    The Echo Area - GNU Emacs Lisp Reference Manual

    The echo area is used for displaying error messages (see Errors), for messages made with the message primitive, and for echoing keystrokes. It is not the same as the minibuffer, despite the fact that the minibuffer appears (when active) in the same place on the screen as the echo area.