emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Function for retrieving the link of an Org Mode buffer
@ 2021-08-14  1:14 Rodrigo Morales
  2021-08-14 12:48 ` John Kitchin
  0 siblings, 1 reply; 3+ messages in thread
From: Rodrigo Morales @ 2021-08-14  1:14 UTC (permalink / raw)
  To: emacs-orgmode

I've written the following function for retrieving the links from a
given Org Mode buffer.

#+BEGIN_SRC elisp
(defun my/org-collect-links-in-buffer (buffer)
  "Collect all the links in the current buffer. If the link has a
description, then it is also collected.

Returns a list of PLISTS of the form:

((:link LINK)
 (:link LINK :desc DESC)
 (:link LINK))"
  (with-current-buffer buffer
      (let (links)
        (while (re-search-forward org-any-link-re nil t)
          (catch 'done
            (let* ((element (org-element-context))
                   (type (org-element-type element)))
              (unless (eq type 'link)
                (throw 'done t))
              (let (obj
                    (link (org-element-property :raw-link element))
                (push link obj)
                (push :link obj)
                (when (and (org-element-property :contents-begin element)
                           (org-element-property :contents-end element))
                  (setq desc (buffer-substring-no-properties
                              (org-element-property :contents-begin element)
                              (org-element-property :contents-end element)))
                  (push desc obj)
                  (push :desc obj))
                (push obj links)))))

I would really appreciate any feedback.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-16  5:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-14  1:14 Function for retrieving the link of an Org Mode buffer Rodrigo Morales
2021-08-14 12:48 ` John Kitchin
2021-08-16  5:18   ` [SOLVED] " Rodrigo Morales

Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).