From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id SCELMc67F2F77QAAgWs5BA (envelope-from ) for ; Sat, 14 Aug 2021 14:49:18 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id UDewLM67F2EWRgAAbx9fmQ (envelope-from ) for ; Sat, 14 Aug 2021 12:49:18 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A7468B1A3 for ; Sat, 14 Aug 2021 14:49:17 +0200 (CEST) Received: from localhost ([::1]:59262 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mEt6B-0001CJ-Ap for larch@yhetil.org; Sat, 14 Aug 2021 08:49:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEt5O-0001CA-Sm for emacs-orgmode@gnu.org; Sat, 14 Aug 2021 08:48:26 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:33682) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mEt5M-00081C-Ab for emacs-orgmode@gnu.org; Sat, 14 Aug 2021 08:48:26 -0400 Received: by mail-wm1-x32f.google.com with SMTP id a201-20020a1c7fd2000000b002e6d33447f9so960813wmd.0 for ; Sat, 14 Aug 2021 05:48:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=andrew-cmu-edu.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0GtzdxrbNwwkgKdKrLWlERP4nQ5hqJ96LGI0dwMLbV0=; b=wJIlCXIxAQbMRyLcc11FrTXCbT2ciONnHcQWOKDT8cnitk2HK7CnAOxGco415QI7DR vL5gV3IrxKS2Xw0Jx64EYjTahXL7/t8hGsN5SX6/BjeXZw45HN6byO80cZSoZbjftio9 4GxD4m+Khul2SaUNVoob9xS9x718l/Ra3pn1a4GrOTzvy045mXifNmejzM2KJuhJl1wj hbpwFWN5WKzvDaYNmLxnSMejuMG9GK5WxrYMAT1t9eMymFb4IamfQG98rAsQT01v8uLo Aa5CSSXpT+2dkn7YZ6A1eNS55U6jc5ExyZkjk0BuS/g1ShqlVhZl62V4Bp6rW3dbkukM 9+TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0GtzdxrbNwwkgKdKrLWlERP4nQ5hqJ96LGI0dwMLbV0=; b=AseWOBDtVAjxSrYi5jGd9Uk8JUYvlsPPDK0NgAnnghfiFJ+lxcuHJhfiySyH0F0F8V YSw4pSeefBRulZmaAJXIT4fvq8LweJIHv+8L2ztOr6FR0MgJixOcJh+4OGbAM9P88e7f +0QGS2MFVjIM54d6qw/DJPeTJkccv/BB7iHmwIj0ZnBC0+0Ved/7VA5gdv+eXS7UTBou EGjRPIt29ATf1AOO2YsaNuAxeRA5V/QDA7QO3tagDWL+vcij2ca/AULzmubJ34PxPkGh rLqkKjgv0lY4rsEG64I4rcxoDt8bL/UjRqRSA9XrknMmpGZ2b4I24cn09WfZZTpVDH5R Qo7g== X-Gm-Message-State: AOAM532fEwbgwQHjzyFfz9dKES/jUtjqhXtwTBTmLqerHIry/udeAKHJ KRzFefZ2lsFB2w8FjUTYoWaAOZrXSBflQsQRpgA= X-Google-Smtp-Source: ABdhPJytrDtYo96jHFDSaF+fgZpksC1FMS2mA+ieB0daJ21mFwzMconl0qIHvp2lNBVSZOxki5CrWkeZkPAG9Cu01F0= X-Received: by 2002:a7b:c014:: with SMTP id c20mr6956748wmb.81.1628945302276; Sat, 14 Aug 2021 05:48:22 -0700 (PDT) MIME-Version: 1.0 References: <87y2943k05.fsf@gmail.com> In-Reply-To: <87y2943k05.fsf@gmail.com> From: John Kitchin Date: Sat, 14 Aug 2021 08:48:11 -0400 Message-ID: Subject: Re: Function for retrieving the link of an Org Mode buffer To: Rodrigo Morales Content-Type: multipart/alternative; boundary="00000000000019cd1105c98462f7" Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=johnrkitchin@gmail.com; helo=mail-wm1-x32f.google.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: org-mode-email Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1628945358; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=0GtzdxrbNwwkgKdKrLWlERP4nQ5hqJ96LGI0dwMLbV0=; b=iFLhISuqCL/Zhqwu8CoX8t12RnMjbLvGmf9T8MTjyi+nql458On80zKrus2Pcsl85iiPOG 906yJUrPdHT5g5ynlxtPEM7YMqYYYBosiUDs21w2YUlflUIH4o03SxJUKbKx/I0H2jg29F 7F2ifJIHuYPCAayoYos2Z928njFw1tXzKVMCH9qo4hzM2E3JRWe1OOeyU9UuKxNrtFv7HO qCDIU6rtsHvTm5EIEC4Hlm/pj1orM9tifrpi23sxKhXNN7osaO2yRQgkqoMxOh55jklVnu p4385w5PViQEiAZSmQlUiF7IO3ELz/r3VmosLsuenf8bBwVcCRSr+pfXCGrEsg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1628945358; a=rsa-sha256; cv=none; b=cjkeY3gB0KkvGv1MmeVHmu1B6VtSu+OZRaBeEaL9nagGpbHa6L69rhIUPHP7Ea3ouaQsC0 TY8OUkWbfHPkp9pUap0NHU+e2eKhtMS7D64uJYSMA5/Do9J2lCFcD/S99QMLqls2TWj3jF rnA7qFKUXqbFBpQSqrZFe5vaCvfDOlwwIDViQ+A/TutJ7gII5lJf4bjKHJiYAXD0UcVdsE YCTmMZx8qy+fRPZTPCsFnd0UXpXx9L3rMATvkcj0N7us/w5jeZoDJYdsdojUUTUPFWMiny ZGJycbX/jAc2bbuT75HWT9i+UKn9JIJ69rZLkjaHHFrtVOh1XckM99USRN0Vfw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=andrew-cmu-edu.20150623.gappssmtp.com header.s=20150623 header.b=wJIlCXIx; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -2.51 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=andrew-cmu-edu.20150623.gappssmtp.com header.s=20150623 header.b=wJIlCXIx; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=andrew.cmu.edu (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: A7468B1A3 X-Spam-Score: -2.51 X-Migadu-Scanner: scn1.migadu.com X-TUID: 9yBnNhOsPjdz --00000000000019cd1105c98462f7 Content-Type: text/plain; charset="UTF-8" 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. > > --00000000000019cd1105c98462f7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I would probably do it like this:

(org-= element-map (org-element-parse-buffer) 'link
=C2=A0 (lambda (lnk)=C2=A0 =C2=A0 (let ((lnkplist '()))
=C2=A0 =C2=A0 =C2=A0 (setq lnkp= list (plist-put lnkplist :link (org-element-property :raw-link lnk)))
= =C2=A0 =C2=A0 =C2=A0 (when (org-element-property :contents-begin lnk)
(= setq lnkplist (plist-put lnkplist :desc (buffer-substring-no-properties
= =C2=A0(org-element-property :contents-begin lnk)
=C2=A0(or= g-element-property :contents-end lnk)))))
=C2=A0 =C2=A0 =C2=A0 lnkplist)= ))



John

--------------------------------= ---
Professor John Kitchin (he/him/his)
Doherty Hall A207F
Departm= ent of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA= 15213
412-268-7803


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)
=C2=A0 "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)
=C2=A0(:link LINK :desc DESC)
=C2=A0(:link LINK))"
=C2=A0 (with-current-buffer buffer
=C2=A0 =C2=A0 (save-excursion
=C2=A0 =C2=A0 =C2=A0 (beginning-of-buffer)
=C2=A0 =C2=A0 =C2=A0 (let (links)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (while (re-search-forward org-any-link-re nil t= )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (catch 'done
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (let* ((element (org-element-cont= ext))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(type = (org-element-type element)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (unless (eq type 'link= )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (throw 'done t)= )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (let (obj
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (link= (org-element-property :raw-link element))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 desc)=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (push link obj)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (push :link obj) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (when (and (org-ele= ment-property :contents-begin element)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0(org-element-property :contents-end element))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq desc (= buffer-substring-no-properties
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (org-element-property :contents-begin eleme= nt)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (org-element-property :contents-end element= )))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (push desc o= bj)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (push :desc = obj))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (push obj links))))= )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 links))))
#+END_SRC

I would really appreciate any feedback.

--00000000000019cd1105c98462f7--