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

B.2 yank

current-killについて学んだ後なら、yank関数のコードはほぼ簡単だ。

yank 関数は kill-ring-yank-pointer 変数を直接使用しません。insert-for-yank を呼び出し、それが current-kill を呼び出し、最終的に kill-ring-yank-pointer 変数を設定します。

コードはこんな感じです:

(defun yank (&optional arg)
  "Reinsert (\"paste\") the last stretch of killed text.
More precisely, reinsert the stretch of killed text most recently
killed OR yanked.  Put point at end, and set mark at beginning.
With just \\[universal-argument] as argument, same but put point at beginning (and mark at end).
With argument N, reinsert the Nth most recently killed stretch of killed
text.

When this command inserts killed text into the buffer, it honors
`yank-excluded-properties' and `yank-handler' as described in the
doc string for `insert-for-yank-1', which see.

See also the command `yank-pop' (\\[yank-pop])."
  (interactive "*P")
  (setq yank-window-start (window-start))
  ;; If we don't get all the way thru, make last-command indicate that
  ;; for the following command.
  (setq this-command t)
  (push-mark (point))
  (insert-for-yank (current-kill (cond
                                  ((listp arg) 0)
                                  ((eq arg '-) -2)
                                  (t (1- arg)))))
  (if (consp arg)
      ;; This is like exchange-point-and-mark, but doesn't activate the mark.
      ;; It is cleaner to avoid activation, even though the command
      ;; loop would deactivate the mark because we inserted text.
      (goto-char (prog1 (mark t)
                   (set-marker (mark-marker) (point) (current-buffer)))))
  ;; If we do get all the way thru, make this-command indicate that.
  (if (eq this-command t)
      (setq this-command 'yank))
  nil)

重要な式は insert-for-yank で、これは current-kill が返す文字列を挿入しつつ、そこから一部のテキストプロパティを削除します。

ただし、その式に至る前に、この関数はyank-window-startの値を、(window-start)式が返す位置、すなわち現在表示が始まる位置に設定します。また、yank関数はthis-commandを設定し、マークをプッシュします。

該当する要素をヤンクした後、オプション引数が数値や未指定ではなく CONS である場合、point をヤンクしたテキストの先頭に、mark をその末尾に配置します。

(prog1 関数は progn と同様ですが、最後の引数ではなく最初の引数の値を返します。最初の引数は、バッファのマークを整数として返すように強制されています。これらの関数のドキュメントを確認するには、このバッファ内でポイントを置き、C-h f (describe-function) と入力した後に RET と入力してください。デフォルトは関数です。)

関数の最後の部分は、成功したときに何をすべきかを記述しています。