I use pdf-tools in Emacs to view PDF documents. I would like to be able to select words (mark their region and then copy them to the kill-ring) in the PDF by double-clicking on them. Is there a function in pdf-tools or elsewhere I could use to obtain this functionality?
More specifically, I want to write a function (unless it already exists in some form)
(defun select-word-on-doubleclick (ev) "Set region to the word under the mouse pointer and copy it to the kill-ring" (interactive "@e") ... ;; Set region to the word under the pointer (pdf-view-kill-ring-save) ;; Save region to kill-ring )
and bind it to
<double-mouse-1>. I need help filling out the dots above.
In the pdf-tools package there is a function called
(pdf-info-gettext PAGE EDGES &optional SELECTION-STYLE FILE-OR-BUFFER)
which could be useful for this purpose. Based on the event
ev, the position of the mouse pointer (when double-clicked) can be obtained. If somehow the edges of the word under the pointer could be determined from this position, the function above would do the trick. I greatly appreciate any hints on how to make this computation.