Made an effort with Elisp, but didn't work - says incorrect number of arguments. If you know Elips, probably this could be done elegantly with zero effort. But I include my heavy-handed stuff so you immediately will understand what I'm trying to do.
(defun copy-all ()
"Copy entire buffer to clipboard"
(interactive)
(let ((pos (point)))
(progn
(mark-whole-buffer)
(clipboard-kill-ring-save)
(keyboard-quit)
(goto-char pos)
(message "Copy done."))))
Instead of saving the point and restoring it later, use save-excursion
. It's more robust and will restore the buffer as well. There's no need for an explicit progn
either.
That said, in this case simply pass the ranges to clipboard-kill-ring-save
instead of trying to mess around with the region. For example:
(defun copy-all ()
"Copy entire buffer to clipboard"
(interactive)
(clipboard-kill-ring-save (point-min) (point-max)))
Remember, elisp help is always available inside emacs with describe-function
(C-h f) if you're unsure about what arguments a function requires.
You're making it tougher than you have to.
(defun copy-whole-buffer ()
"Copy entire buffer to clipboard"
(interactive)
(clipboard-kill-ring-save (point-min) (point-max)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With