コメント応答,あーんど Exercise 6.3 改

Plus さん,いつもありがとうございます。
純粋ににうれしいです。好きにならないように気をつけます。


> http://www.gnu.org/software/emacs/emacs-lisp-intro/emacs-lisp-intro.pdf
> 確認しましたが、このファイルってちょっと古いんじゃないかと思います。
> Emacs 23.0.93 に付いてる info だと 6.3 章の最後に以下の文が追加されています。
>
> Additionally, do you really need `goto-char’ or `point-min’? Or can
> you write the function without them?
>
> なので、goto-char/point-min なしの関数を作成することを
> 推奨されているような気がします。
> #これらがなくなると first-60-chars 関数には
> # save-excursion も必要なくなりますね。

みょ。なんと!!
やっぱりそうなんですね。情報ありがとうございます。


> あとは Exercise には言及されてないので蛇足ですが、
> バッファの文字数が60文字よりも少ないと buffer-substring-no-properties が
> エラーを返すので、こんな感じでしょうか。
>
> (buffer-substring-no-properties 1 (min 60 (point-max)))』
ぎょぎょぎょ。
ちくしょー,それは気づかなかった。境界条件として,
当然考慮すべきことですね。腕が鈍ったなぁ。
というか,もともとテクなしだから,鈍るもくそもないんですが(笑)


というわけで,Plus さんのアドバイスをもとに,修正版。

(defun first-60-chars ()
  "Print the first 60 characters even if the buffer is narrowed."
  (interactive)
  (save-restriction
    (widen)
    (message "%s" (buffer-substring-no-properties 1 (min 61 (point-max))))))

最初,(min 60 (point-max)) でいいかと思ったけど,
61 にしないと,60文字にならないということに今気づいた。
point とはなんぞや? と疑問に思ったので,調べてみると・・・

"Point" is the current location of the cursor.
Wherever the cursor is, that is point.
More precisely, on terminals where the cursor appears to be on top of a
character, point is immediately before the character.

なるほど。カーソルの下の文字の直前が point と。
うーん,もひとつしっくりこない。
(buffer-substring 1 61) の場合,61はポイントではないということか?
「START and END are character positions.」とは書いてあるが,
仕様として,END の直前の文字までということかな。


ま,とにかくこれで,空のバッファで,
(first-60-chars) とタイプして C-uC-xC-e すると確かにうまく動作していることを
確認できます。
うんうん。


Plus さん今回もありがとうございました!!