Hello, stardiviner <numbch...@gmail.com> 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