astoff / devdocs.el

Emacs viewer for DevDocs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Storing links to devdocs

j-minster opened this issue · comments

Hi. Thank you for this package. I'd like to ask if there's any way to store links to devdocs buffers for later use? I'd like to use 'org-store-links' to save a link to something I'm reading in devdocs and come back to it later.

Thanks!

There is the devdocs-copy-url command (w on devdocs buffer) to copy a link to the entry. One can make browse-url handle these links in a special way by customizing browse-url-handlers. If we find a sensible configuration that makes sense for most users, we can add it to the package.

I'm not familiar with org-store-links, but, again, please let me know if you find a suitable configuration.

I believe the following does what you want:

(with-eval-after-load 'ol
  (org-link-set-parameters
   "devdocs"
   :follow (lambda (path _)
             (when (string-match "\\([^/]*\\)/\\(.*\\)" path)
               (let ((slug (match-string 1 path))
                     (entry (match-string 2 path)))
                 (message "%s %s %s" path slug entry)
                 (pop-to-buffer
                  (devdocs--render `((doc . ,(devdocs--doc-metadata slug))
                                     (path . ,entry)))))))
   :store (lambda ()
            (when-let ((entry (car devdocs--stack)))
              (let-alist entry
                (org-link-store-props
                 :type "devdocs"
                 :link (format "devdocs:%s/%s"
                               .doc.slug
                               (if .fragment
                                   (concat (devdocs--path-file .path) "#" .fragment)
                                 .path))))))
   :export (lambda (path desc backend)
             (let ((url (concat devdocs-site-url "/" path)))
               (pcase backend
                 ('html
                  (format "<a href=\"%s\">%s</a>" url (or desc url)))
                 ('latex
                  (if desc
                      (format "\\href{%s}{%s}" url desc)
	            (format "\\url{%s}" url)))
                 ('ascii
                  (if desc
                      (format "%s (%s)" desc url)
                    (format "<%s>" url)))
                 (_ uri))))))

I'm not sure I should add this to devdocs, since by design you can't set up org-links without loading org dependencies. I might just post it as a configuration example. In any case, let me know if it works properly.

@j-minster Did you get a chance to test this, and does it work?

I'll close this now, but feel free to comment is anything else comes up.