I use clipboard-kill-region
to copy contents from Emacs to other programs. But sometimes, it copies the same content twice into the clipboard.
It looks like,
/home/user/.emacs/home/user/.emacs
when I copy the filename
/home/user/.emacs
Is there a way I can empty the clipboard contents before calling clipboard-kill-region
?
My complete function is shown here; it is a utility function to copy the absolute path of currently opened file in Emacs buffer:
(defun sk-copy-file-name ()
"Put the current file name on the clipboard"
(interactive)
(let ((filename (if (equal major-mode 'dired-mode)
default-directory
(buffer-file-name))))
(when filename
(with-temp-buffer
(insert filename)
(clipboard-kill-region (point-min) (point-max)))
(message filename))))