emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: John Kitchin <jkitchin@andrew.cmu.edu>
To: Rodrigo Morales <moralesrodrigo1100@gmail.com>
Cc: org-mode-email <emacs-orgmode@gnu.org>
Subject: Re: [Q] How to programmatically get the description of a link?
Date: Fri, 13 Aug 2021 20:04:41 -0400	[thread overview]
Message-ID: <CAJ51ETqZm+8rwcOMYMh2MEXe8Si0Nzn2Wq3K55N041-RAxhSew@mail.gmail.com> (raw)
In-Reply-To: <87eeax54aw.fsf@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1870 bytes --]

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.
>
>

[-- Attachment #2: Type: text/html, Size: 2819 bytes --]

      reply	other threads:[~2021-08-14  0:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-13 23:10 [Q] How to programmatically get the description of a link? Rodrigo Morales
2021-08-14  0:04 ` John Kitchin [this message]

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=CAJ51ETqZm+8rwcOMYMh2MEXe8Si0Nzn2Wq3K55N041-RAxhSew@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).