summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorAugusto Stoffel <arstoffel@gmail.com>2023-02-11 11:31:58 +0100
committerVedang Manerikar <ved.manerikar@gmail.com>2023-06-11 00:24:49 +0530
commit5b58c6bcc3744c9ad984ba60448f8e98b994f913 (patch)
tree2109ef09b877876f74323859401081ee65d58e8a /lisp
parentfb6616c15efb736b50e1d84557b45b71e4ea858c (diff)
Add command and submenu to switch between selection styles
Make it possible to set `pdf-view-selection-style` from Easy Menu. Closes: #190
Diffstat (limited to 'lisp')
-rw-r--r--lisp/pdf-misc.el13
-rw-r--r--lisp/pdf-view.el14
2 files changed, 27 insertions, 0 deletions
diff --git a/lisp/pdf-misc.el b/lisp/pdf-misc.el
index b6bb896..bcba8ae 100644
--- a/lisp/pdf-misc.el
+++ b/lisp/pdf-misc.el
@@ -143,6 +143,19 @@
["Copy region" pdf-view-kill-ring-save
:keys "\\[kill-ring-save]"
:active (pdf-view-active-region-p)]
+ ("Selection style"
+ ["Glyph" (pdf-view-set-selection-style 'glyph)
+ :style radio
+ :selected (eq pdf-view-selection-style 'glyph)
+ :help "When dragging the mouse, select individual characters."]
+ ["Word" (pdf-view-set-selection-style 'word)
+ :style radio
+ :selected (eq pdf-view-selection-style 'word)
+ :help "When dragging the mouse, select entire words."]
+ ["Line" (pdf-view-set-selection-style 'line)
+ :style radio
+ :selected (eq pdf-view-selection-style 'line)
+ :help "When dragging the mouse, select entire lines."])
"--"
["Isearch document" isearch-forward
:visible (bound-and-true-p pdf-isearch-minor-mode)]
diff --git a/lisp/pdf-view.el b/lisp/pdf-view.el
index c1fc21b..9253721 100644
--- a/lisp/pdf-view.el
+++ b/lisp/pdf-view.el
@@ -1624,6 +1624,20 @@ the `convert' program is used."
(dolist (f (cons result images))
(when (file-exists-p f)
(delete-file f))))))
+
+(defun pdf-view-set-selection-style (&optional style)
+ "Set `pdf-view-selection-style' to STYLE in the current buffer.
+
+When called interactively or without an argument, cycle between
+the selection styles."
+ (interactive)
+ (unless style
+ (setq style (or (cadr (memq pdf-view-selection-style '(glyph word line)))
+ 'glyph))
+ (message "Setting selection style to `%s'." style))
+ (pdf-view-deactivate-region)
+ (setq-local pdf-view-selection-style style))
+
;; * ================================================================== *
;; * Bookmark + Register Integration