Skip to content

Instantly share code, notes, and snippets.

@igoralmeida
Created June 18, 2021 14:27
Show Gist options
  • Select an option

  • Save igoralmeida/4a993deb37c4f5815b805b7e4f17805f to your computer and use it in GitHub Desktop.

Select an option

Save igoralmeida/4a993deb37c4f5815b805b7e4f17805f to your computer and use it in GitHub Desktop.
(defvar sensible-pdf--childframe)
(defun sensible-pdf-show-childframe (link)
"Show a childframe with the destination LINK"
(interactive
(list (or (pdf-links-read-link-action "Link to show in childframe (SPC scrolls): ")
(error "No link selected"))))
(let-alist link
(cl-case .type
(goto-dest
;;edges is (LEFT TOP RIGHT BOT)
(let* ((parent (selected-window))
(paredges (window-edges parent t))
(par-left (nth 0 paredges))
(par-top (nth 1 paredges))
(par-right (nth 2 paredges))
(par-bot (nth 3 paredges))
(par-height (- par-bot par-top))
(childleft (* (/ par-left (- par-right par-left)) (+ 1 (nth 0 .edges))))
(childtop (+ par-top
(* par-height (+ 1 (nth 1 .edges)))))
win)
(setq win (display-buffer-in-child-frame
(current-buffer)
`((child-frame-parameters . ((left . ,childleft)
(top . ,childtop)
(width . 0.1)
(height . 0.1)
)))))
(with-selected-window win
(pdf-view-goto-page .page))
(setq sensible-pdf--childframe win)))
(t
(error "Unsupported link type: %s" .type)))
nil))
(defun sensible-pdf-kill-childframe ()
"kill it"
(interactive)
;;TODO should add a test here to avoid killing the main frame... again
(delete-frame (window-frame sensible-pdf--childframe))
(setq sensible-pdf--childframe nil))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment