GNU Emacs 32.0.50 (9008bf64c3) のマニュアルを PLaMo 翻訳で機械翻訳したものです。誤訳を含むことがあります。原文: https://www.gnu.org/software/emacs/manual/html_node/eintr/beginning_002dof_002dbuffer-complete.html ・ emacs-doc.conao3.com

5.3.3 完全な beginning-of-buffer

beginning-of-buffer関数の全文は以下の通りです。


(defun beginning-of-buffer (&optional arg)
  "Move point to the beginning of the buffer;
leave mark at previous position.
With \\[universal-argument] prefix,
do not set mark at previous position.
With numeric arg N,
put point N/10 of the way from the beginning.

If the buffer is narrowed,
this command uses the beginning and size
of the accessible part of the buffer.

Don't use this command in Lisp programs!
\(goto-char (point-min)) is faster
and avoids clobbering the mark."
  (interactive "P")
  (or (consp arg)
      (and transient-mark-mode mark-active)
      (push-mark))
  (let ((size (- (point-max) (point-min))))
    (goto-char (if (and arg (not (consp arg)))
                   (+ (point-min)
                      (if (> size 10000)
                          ;; Avoid overflow for large buffer sizes!
                          (* (prefix-numeric-value arg)
                             (/ size 10))
                        (/ (+ 10 (* size (prefix-numeric-value arg)))
                           10)))
                 (point-min))))
  (if (and arg (not (consp arg))) (forward-line 1)))

2つの些細な点を除けば、これまでの説明でこの関数の仕組みが分かります。1点目はドキュメント文字列の詳細に関するもので、2点目は関数の最終行に関するものです。

ドキュメント文字列に、ある式への参照があります:

\\[universal-argument]

この式の最初の角括弧の前には ‘\\’ が使用されています。この ‘\\’ は、現在 ‘[…]’ にバインドされているキーを代入するようLispインタプリタに指示します。universal-argument の場合、通常は C-u となりますが、異なる場合もあります。(詳細については、The GNU Emacs Lisp Reference Manual の Tips for Documentation Strings を参照してください。)

最後に、beginning-of-bufferコマンドの最後の行では、引数付きでコマンドが呼び出された場合にポイントを次の行の先頭に移動させるよう指定されています:

(if (and arg (not (consp arg))) (forward-line 1))

これにより、バッファ内の適切な10分の1の位置を過ぎた後、カーソルが1行目の先頭に配置されます。これは、カーソルが常にバッファ内の要求された10分の1の位置以上に位置することを保証する工夫であり、おそらく不要とも言える配慮ですが、もしこれがなければ間違いなく不満の声が上がることでしょう。((not (consp arg)) の部分は、C-u を指定して数値を省略した場合、つまり raw プレフィックス引数が単なるコンスセルである場合に、コマンドがカーソルを2行目の先頭に配置しないようにするためのものです。)