Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pdf-annots-action-perform function (avy-like edit annots) #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 61 additions & 0 deletions lisp/pdf-annot.el
Expand Up @@ -292,6 +292,7 @@ Setting this after the package was loaded has no effect."
(let ((kmap (make-sparse-keymap))
(smap (make-sparse-keymap)))
(define-key kmap pdf-annot-minor-mode-map-prefix smap)
(define-key kmap (kbd "e") 'pdf-annot-edit)
(define-key smap "l" #'pdf-annot-list-annotations)
;; (define-key smap "d" 'pdf-annot-toggle-display-annotations)
(define-key smap "a" #'pdf-annot-attachment-dired)
Expand Down Expand Up @@ -1542,6 +1543,66 @@ At any given point of time, only one annotation can be in edit mode."
(error "No annotation at this position"))
(pdf-annot-edit-contents a)))

(defun pdf-annot-edit (annot)
"Activate ANNOT, for editing.

Interactively, annot is read via `pdf-annot-read-annot'.
This function displays characters around the annots in the current
page and starts reading characters (ignoring case). After a
sufficient number of characters have been read, the corresponding
annot's annot is invoked. Additionally, SPC may be used to
scroll the current page."
(interactive
(list (or (pdf-annot-read-annot "Activate annot (SPC scrolls): ")
(error "No annot selected"))))
(pdf-annot-activate-annotation annot))

;; TODO 'merge' this function with `pdf-links-read-link-action' into a single
;; universal 'read-action' function (in `pdf-util'?)
(defun pdf-annot-read-annot (prompt)
"Using PROMPT, interactively read an annot-action.

See `pdf-annot-edit' for the interface."
(pdf-util-assert-pdf-window)
(let* ((annots (pdf-annot-getannots (pdf-view-current-page) nil nil))
(keys (pdf-links-read-link-action--create-keys
(length annots)))
(key-strings (mapcar (apply-partially 'apply 'string)
keys))
(alist (cl-mapcar 'cons keys annots))
(size (pdf-view-image-size))
(colors (pdf-util-face-colors
'pdf-links-read-link pdf-view-dark-minor-mode))
(args (list
:foreground (car colors)
:background (cdr colors)
:formats
`((?c . ,(lambda (_edges) (pop key-strings)))
(?P . ,(number-to-string
(max 1 (* (cdr size)
pdf-links-convert-pointsize-scale)))))
:commands pdf-links-read-link-convert-commands
:apply (pdf-util-scale-relative-to-pixel
(mapcar (lambda (l) (cdr (assq 'edges l)))
annots)))))
;; (print (plist-get args :apply))
(unless annots
(error "No annots on this page"))
(unwind-protect
(let ((image-data
(pdf-cache-get-image
(pdf-view-current-page)
(car size) (car size) 'pdf-annot-read-annot)))
(unless image-data
(setq image-data (apply 'pdf-util-convert-page args ))
(pdf-cache-put-image
(pdf-view-current-page)
(car size) image-data 'pdf-annot-read-annot))
(pdf-view-display-image
(create-image image-data (pdf-view-image-type) t)
(when pdf-view-roll-minor-mode (pdf-view-current-page)))
(pdf-links-read-link-action--read-chars prompt alist))
(pdf-view-redisplay))))


;; * ================================================================== *
Expand Down