From: John Kitchin <jkitchin@andrew.cmu.edu>
To: Rodrigo Morales <moralesrodrigo1100@gmail.com>
Cc: org-mode-email <emacs-orgmode@gnu.org>
Subject: Re: Function for retrieving the link of an Org Mode buffer
Date: Sat, 14 Aug 2021 08:48:11 -0400 [thread overview]
Message-ID: <CAJ51ETpsi9qWNzMkW0VcChyS8iULr2qqFHnE7+3cpTj-7cWmdw@mail.gmail.com> (raw)
In-Reply-To: <87y2943k05.fsf@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2301 bytes --]
I would probably do it like this:
(org-element-map (org-element-parse-buffer) 'link
(lambda (lnk)
(let ((lnkplist '()))
(setq lnkplist (plist-put lnkplist :link (org-element-property
:raw-link lnk)))
(when (org-element-property :contents-begin lnk)
(setq lnkplist (plist-put lnkplist :desc (buffer-substring-no-properties
(org-element-property :contents-begin lnk)
(org-element-property :contents-end lnk)))))
lnkplist)))
John
-----------------------------------
Professor John Kitchin (he/him/his)
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
On Fri, Aug 13, 2021 at 9:16 PM Rodrigo Morales <
moralesrodrigo1100@gmail.com> wrote:
>
> 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
> (save-excursion
> (beginning-of-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))
> desc)
> (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)))))
> links))))
> #+END_SRC
>
> I would really appreciate any feedback.
>
>
[-- Attachment #2: Type: text/html, Size: 3326 bytes --]
next prev parent reply other threads:[~2021-08-14 12:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-14 1:14 Function for retrieving the link of an Org Mode buffer Rodrigo Morales
2021-08-14 12:48 ` John Kitchin [this message]
2021-08-16 5:18 ` [SOLVED] " Rodrigo Morales
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAJ51ETpsi9qWNzMkW0VcChyS8iULr2qqFHnE7+3cpTj-7cWmdw@mail.gmail.com \
--to=jkitchin@andrew.cmu.edu \
--cc=emacs-orgmode@gnu.org \
--cc=moralesrodrigo1100@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
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).