本節では、Lispプログラムでバッファ内の任意の部分のテキストを文字列に変換する ための2つの関数について述べます。
この関数は、カレントバッファのstartとendの位置で定義される 領域のテキストのコピーを含んだ文字列を返す。 引数がバッファの参照可能部分の内側の位置でないと、
buffer-substring
はエラーargs-out-of-range
を通知する。startがendより小さい必要はなく、引数の順番はどちらでもよい。 しかし、ほとんどの場合、小さい引数を先に書く。
コピーされるテキストにテキスト属性がある場合、 テキスト属性もそれが属する文字とともに文字列へコピーされる。 see Text Properties。 しかし、バッファのオーバレイ(see Overlays)とそれらの属性は 無視されコピーされない。
---------- Buffer: foo ---------- This is the contents of buffer foo ---------- Buffer: foo ---------- (buffer-substring 1 10) ⇒ "This is t" (buffer-substring (point-max) 10) ⇒ "he contents of buffer foo "
この関数は
buffer-substring
と同様であるが、 テキスト属性をコピーせずに文字だけをコピーする点が異なる。 see Text Properties。
この関数は、カレントバッファの参照可能部分全体の内容を文字列として返す。 これは、つぎと等価である。
(buffer-substring (point-min) (point-max))---------- Buffer: foo ---------- This is the contents of buffer foo ---------- Buffer: foo ---------- (buffer-string) ⇒ "This is the contents of buffer foo "
ポイントの周りやそのうしろにあるthingを文字列として返す。
引数thingは、構文上の要素の種類を指定するシンボルである。 可能な値は、
symbol
、list
、sexp
、defun
、filename
、url
、word
、sentence
、whitespace
、line
、page
などである。---------- Buffer: foo ---------- Gentlemen may cry ``Pea-!-ce! Peace!,'' but there is no peace. ---------- Buffer: foo ---------- (thing-at-point 'word) ⇒ "Peace" (thing-at-point 'line) ⇒ "Gentlemen may cry ``Peace! Peace!,''\n" (thing-at-point 'whitespace) ⇒ nil