emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: hyperscope


From: Jean Louis
Subject: Re: hyperscope
Date: Fri, 6 Nov 2020 22:18:52 +0300
User-agent: Mutt/+ (1036f0e) (2020-10-18)

* Eduardo Ochs <eduardoochs@gmail.com> [2020-11-06 21:19]:
> do you have examples of the syntax of these links and of what we need
> to make them work? I am especially interested in "MPV play video at
> exact time", "Launch Program", "Media", "PDF by Page Nr." and
> "Set"...

I do not have universal approach similar like URL, it is database
approach such as (hyperscope 123) where ID 123 is defined to open
specific video at specific time. Links are shown to user on screen as
such and users define them but they are not accessible without
database.

> I am asking because one of the topics of my talk at the next EmacsConf
> (in a few weeks!) is how eev implements links to all these things,
> and I want to compare eev's approach with other packages. See:
> 
>   http://angg.twu.net/eev-intros/find-pdf-like-intro.html
>   http://angg.twu.net/eev-intros/find-audiovideo-intro.html

I was researching eev before weeks and it has alignment with some
principles of collective IQ creation, so I may as well include eev
mode in my hyperscope if such exist. 

Here are some functions handling those links, you may see that mpv
opens up by using id

(defun hlink-mpv-play-video-at-exact-time (id)
  (let* ((link (hlinks-link id))
         (arguments (hlinks-arguments id))
         (command (format "mpv --start=%s '%s'" arguments link)))
    (async-shell-command command)
    (hlink-description-show id)))

(defun hlink-show-pdf-by-page (link argument)
  "Opens the PDF page by number"
  (funcall (intern hyperscope-pdf-function) link argument))

hyperscope-pdf-function:

(defun hyperscope-evince (file &optional page query)
  "Opens PDF with evince document viewer"
  (let* ((command "evince")
         (command (if page (format "%s --page-index=%s" command page) command))
         (command (if query (format "%s -l '%s'" command query) command))
         (command (format "%s '%s'" command file)))
    (async-shell-command command)))

> I know org-player and org-pdftools, but I found them hard to set up.

It is better you make simple eev based functions to handle such links.

Maybe this function below can open PDF inside of Emacs at specific
page number for maybe specific query in PDF/DJVU/DVI or specific
match. But it could be as well not functional. I have to test it to
confirm, but you could reuse for evv to view PDF/DJVU/DVI finely
grained inside of Emacs.

(defun doc-view-open-file (file &optional page-number query match)
  "Opens PDF file in GNU Emacs at specific page number or at
specific match"
  (let* ((allowed-extensions '("pdf" "djvu" "dvi"))
         (file-ext (file-name-extension file))
         (match (if match match 0)))
    (when (and (file-exists-p file)
               (seq-contains-p allowed-extensions file-ext 'equalp))
      (setq doc-view--current-search-matches nil)
      (let ((created (create-file-buffer file))
            (buffer (get-file-buffer file)))
        (switch-to-buffer created)
        (set-visited-file-name file t)
        (insert file)
        (doc-view-mode)
        (read-only-mode)
        (when page-number
          (doc-view-goto-page page-number))
        (when query
          (let ((txt (expand-file-name "doc.txt"
                                       (doc-view--current-cache-dir))))
            (if (file-readable-p txt)
                (progn
                  (setq doc-view--current-search-matches
                        (doc-view-search-internal query txt))
                  (doc-view-search-next-match match)))))))))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]