emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Suggestion] add an API function for getting link description


From: Nicolas Goaziou
Subject: Re: [Suggestion] add an API function for getting link description
Date: Wed, 20 May 2020 15:56:54 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)

Hello,

stardiviner <address@hidden> writes:

> I found org link can't get link description easily.
>
> I googled it how to get link description. Found this solution. But it's not 
> intuitive.
>
> #+begin_src emacs-lisp
> (defun get-description-at-point ()
>   (interactive)
>   (let ((link (org-element-context)))
>     (message "%s" (buffer-substring (org-element-property :contents-begin 
> link)
>                                     (org-element-property :contents-end 
> link)))))
> #+end_src
>
> Why now support this?
>
> #+begin_src emacs-lisp
> (org-element-property :desc (org-element-context))
> #+end_src
>
> Maybe the key ~:desc~ could be more meaningful detailed.

Links with description are not leaf elements in the AST. I.e., the
parser needs to go deeper. As any non-leaf object, as, e.g., bold, it
has :contents-begin and :contents-end properties. Adding :desc would
duplicate information for no good reason.

I see no problem writing an helper function once, and use it often.

Besides, there are other, slightly different implementations of this
function, e.g.,

  (defun get-description-at-point-2 ()
    (and (org-at-regexp-p org-link-bracket-re) (match-string 2)))

This one is fuzzier, it will get description in fake links too (e.g., in
comments, property drawers…), but will be faster. So there is no single
function that fits every need.


Regards,

-- 
Nicolas Goaziou



reply via email to

[Prev in Thread] Current Thread [Next in Thread]