Tim Bray tweeted a nice bit of elisp to copy the current buffer to the kill ring:
For mac/emacs people:
<<<<
(defun copy-whole-buffer () “Command A stupid” (interactive)
(save-excursion
(mark-whole-buffer)
(copy-region-as-kill 1 (buffer-size))))
(global-set-key [(meta a)] ‘copy-whole-buffer)
<<<<
[Don’t know why I didn’t do this years ago…]— Tim Bray (@timbray) February 15, 2019
The normal method—or at least my normal method—is to mark the buffer with Ctrl+x h and then copy it to the kill ring with Meta+w. That’s pretty simple and it’s burned into my muscle memory but I do that operation a lot so it probably makes sense to get it bound to a single key sequence. In any event, if you often find yourself wanting to capture the buffer so you can paste it somewhere else, Bray’s code is just what you need.
My only quibble is binding it to Meta+a. By default, that’s bound to either backward-sentence
or org-backward-sentence
, which I use all the time. If you use or think you might use the go to beginning and end of sentence functions, you should probably bind Bray’s code to something else.