From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id INpGKOsIF2GKRAEAgWs5BA (envelope-from ) for ; Sat, 14 Aug 2021 02:06:03 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id oFTYI+sIF2EPZgAAB5/wlQ (envelope-from ) for ; Sat, 14 Aug 2021 00:06:03 +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 E9CF62A7B3 for ; Sat, 14 Aug 2021 02:06:00 +0200 (CEST) Received: from localhost ([::1]:45854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mEhBW-0005dc-Hx for larch@yhetil.org; Fri, 13 Aug 2021 20:05:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56978) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEhAZ-0005dU-5V for emacs-orgmode@gnu.org; Fri, 13 Aug 2021 20:04:59 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:34725) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mEhAW-0000p0-Nm for emacs-orgmode@gnu.org; Fri, 13 Aug 2021 20:04:58 -0400 Received: by mail-wr1-x42e.google.com with SMTP id h13so15450579wrp.1 for ; Fri, 13 Aug 2021 17:04:54 -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=I9Sv0Tj5hUcG1QGDmCOiIWWxgVP28s/foUlFZTAZKDc=; b=ejUi2Hkqg5OnNDd2FMeTR+GeRHiJI6UjPPbrWBXY6u3MAxJt8GvoH/2ZHAxO6kewpo Jypb9+54kWDF7xjw5yEkhk/apF5UugdGNMMk1T4tjwETzaa177o1v+L+5t9rFP2alst+ Qqs7emahgSayI/DCJD48nsl7y9SBkBTTO8TeBY0BBsKT6ypQuIUMp7fli7mooFxQVXvt fjSeBkNbnaoSnYX3jaWQhpaWCVoNDME9F+q56Eye2xnfTIgEhNfNRb6RzbYam3CUnS8q 5GwPo1RXVz93bms7Ot90BArCckmlKIeyUx8f7S6dq5sZaseF6dMN1FvmSGTrlyhSJzij N2iw== 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=I9Sv0Tj5hUcG1QGDmCOiIWWxgVP28s/foUlFZTAZKDc=; b=XQkBJM4w6rwjxz6UROf7OBY6WZO4qw9/DZQVd8AiurhLtCiWWWTp3fbIGnFuCz/EHZ lL+xEEOYGEDXtDRD3b8694vjOLUswz4t5it1/Y3AS/gfnShlWcgGh1jjYoekq+YtM393 flsWgnMI6SVR9dj5of6DndHswaLwPmhl8pMntCCmMW4WnEq0cCrH/ynmv90HzGmiU8LW ahcdIJ8VXOaOO7bbNbGOc5e1j1JKsh1J4dke1+gfgwHCqI5+FD/1w9XscASDI5g3k62O KaaQVvsTRyVTWKJDTaD4hs287mZgK3Y+8JfmjkELN4hU9XhuFNr2PIdNkW2m+YmyUyvv r7rw== X-Gm-Message-State: AOAM533CeEmCdH5qt7q7Kofy7m4Bm2/doo++RNgiLM5rqrHbDmwTVII8 1fRGuWAaofvIWlZFyZkZ1oVwYtuDDl1rhJnLwn0= X-Google-Smtp-Source: ABdhPJy1lFFGKw4Xt6TD+iGwkvqCH1Lj/UUjA+2byfZhbjYEeCDsoBtCRZRrWxC0QchsS+7vsDvv1rytkqBnTWW3GQU= X-Received: by 2002:a5d:6484:: with SMTP id o4mr5651633wri.75.1628899492869; Fri, 13 Aug 2021 17:04:52 -0700 (PDT) MIME-Version: 1.0 References: <87eeax54aw.fsf@gmail.com> In-Reply-To: <87eeax54aw.fsf@gmail.com> From: John Kitchin Date: Fri, 13 Aug 2021 20:04:41 -0400 Message-ID: Subject: Re: [Q] How to programmatically get the description of a link? To: Rodrigo Morales Content-Type: multipart/alternative; boundary="000000000000a5b8be05c979b75a" Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=johnrkitchin@gmail.com; helo=mail-wr1-x42e.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=1628899561; 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=I9Sv0Tj5hUcG1QGDmCOiIWWxgVP28s/foUlFZTAZKDc=; b=uEH4kOVzIzACwKCQdyIxJCWYUbin1SKUY/mLZCp0qsYtLDpal04QM7wThyC9Q6uLuHr4ZB kN66FeM86mVastKQS8Esm7/dFQcne/u8uhgAFsBl7oYB0V1QIttOEq2yqPvG0yuWXnJSHc /PPiAdDR0LBuqhRoqkW0z/zd8qj0Urqv9lF0d4NXzLhH81G3dWpuQtbylC/j2k5PC5LffS pWuAZIkbSpCwDmux/xoW7815bb9SbBIaWTR1dgj916g7vPMjyW98xk75A8XuCvKK+a/fKI R2HDhj/yr7LUCUu+Yfoz29Xc+uS0ni9yumWjdoomY1qms/+V0RdedVCE9OHm8Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1628899561; a=rsa-sha256; cv=none; b=X3icJzaY5Ye5F4vjfLuMWS2Lkx796DKpcjq650XxCihlfN/QdbcLxkJsiLC3yVizJGkMOz UwOTTQ6Hzre/AOPyuamEMi6eQ809fL1ral1/b0ZCN7SmDlQkmqRJ8oWZCi4irdYisYmKkR YBV6yJ14WBmKkUm9N1aFX4PHBADjc0WfPJ2slcSlqf8+kG+0F5otnFeVoJZLDlLuZkd2GM yQukoNxtu630wKaZ5yh3bc1fxy+TZRCQ1PcpfPFInqjILy1snwpnFhCMYrPfES55Fe4oUr mFAqKFbl474BoEjLq7zZ32HQPaBhoQb6rBsP0tfl51P7UsiolwQarNMrftZYuQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=andrew-cmu-edu.20150623.gappssmtp.com header.s=20150623 header.b=ejUi2Hkq; 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: -1.51 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=andrew-cmu-edu.20150623.gappssmtp.com header.s=20150623 header.b=ejUi2Hkq; 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: E9CF62A7B3 X-Spam-Score: -1.51 X-Migadu-Scanner: scn1.migadu.com X-TUID: GPKUujZk/YKC --000000000000a5b8be05c979b75a Content-Type: text/plain; charset="UTF-8" I think you can do something like this: (defun get-description () (interactive) (let ((link (org-element-context))) (message (buffer-substring (org-element-property :contents-begin link) (org-element-property :contents-end link))))) 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 7:12 PM Rodrigo Morales < moralesrodrigo1100@gmail.com> wrote: > > * The question > > Let's say I have the following link > > #+BEGIN_SRC org > This is a sentence [[foo][bar]]. This is another sentence. > #+END_SRC > > How to programmatically get the description of the link (i.e. =bar=)? > > * Additional information > > I've tried using =org-element-context=. The following sexp was > executed when the cursor was on the link which was presented above. > > #+BEGIN_SRC text > ELISP> (with-current-buffer "main.org" (org-element-context)) > #+END_SRC > > #+BEGIN_SRC text > (link > (:type "fuzzy" :path "foo" :format bracket :raw-link "foo" :application > nil :search-option nil :begin 1 :end 15 :contents-begin 8 :contents-end 13 > :post-blank 0 :parent > (paragraph > (:begin 1 :end 16 :contents-begin 1 :contents-end 16 :post-blank > 0 :post-affiliated 1 :parent nil)))) > #+END_SRC > > and =org-element-at-point=. The following sexp was executed when the > cursor was on the link which was presented above. > > #+BEGIN_SRC text > ELISP> (with-current-buffer "main.org" (org-element-at-point)) > #+END_SRC > > #+BEGIN_SRC text > (paragraph > (:begin 1 :end 16 :contents-begin 1 :contents-end 16 :post-blank 0 > :post-affiliated 1 :parent nil)) > #+END_SRC > > but neither of those get the description of the link as metadata. > > --000000000000a5b8be05c979b75a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I think you can do something like this:

(defun get-description ()
=C2=A0 (interactive)
=C2=A0 (let ((link (o= rg-element-context)))
=C2=A0 =C2=A0 (message (buffer-substring (org-elem= ent-property :contents-begin link)
=C2=A0 =C2=A0 =C2=A0 (org-element= -property :contents-end link)))))

John

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


On Fri, Aug = 13, 2021 at 7:12 PM Rodrigo Morales <moralesrodrigo1100@gmail.com> wrote:

* The question

Let's say I have the following link

#+BEGIN_SRC org
This is a sentence [[foo][bar]]. This is another sentence.
#+END_SRC

How to programmatically get the description of the link (i.e. =3Dbar=3D)?
* Additional information

I've tried using =3Dorg-element-context=3D. The following sexp was
executed when the cursor was on the link which was presented above.

#+BEGIN_SRC text
ELISP> (with-current-buffer "main.org" (org-element-context))
#+END_SRC

#+BEGIN_SRC text
(link
=C2=A0(:type "fuzzy" :path "foo" :format bracket :raw-l= ink "foo" :application nil :search-option nil :begin 1 :end 15 :c= ontents-begin 8 :contents-end 13 :post-blank 0 :parent
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (paragraph
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(:begin 1 :end 16 :contents-begin 1 :cont= ents-end 16 :post-blank 0 :post-affiliated 1 :parent nil))))
#+END_SRC

and =3Dorg-element-at-point=3D. The following sexp was executed when the cursor was on the link which was presented above.

#+BEGIN_SRC text
ELISP> (with-current-buffer "main.org" (org-element-at-point))
#+END_SRC

#+BEGIN_SRC text
(paragraph
=C2=A0(:begin 1 :end 16 :contents-begin 1 :contents-end 16 :post-blank 0 :p= ost-affiliated 1 :parent nil))
#+END_SRC

but neither of those get the description of the link as metadata.

--000000000000a5b8be05c979b75a--