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 ms11 with LMTPS id DK+eL0M3xV6/cgAA0tVLHw (envelope-from ) for ; Wed, 20 May 2020 13:57:23 +0000 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 UCTUKkM3xV5MGwAAbx9fmQ (envelope-from ) for ; Wed, 20 May 2020 13:57:23 +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 6191A940365 for ; Wed, 20 May 2020 13:57:23 +0000 (UTC) Received: from localhost ([::1]:42618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbPDm-0001Uz-3h for larch@yhetil.org; Wed, 20 May 2020 09:57:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbPDT-0001Ul-0L for emacs-orgmode@gnu.org; Wed, 20 May 2020 09:57:03 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:38549) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbPDR-0008G6-6h for emacs-orgmode@gnu.org; Wed, 20 May 2020 09:57:02 -0400 Received: from localhost (40-67.ipv4.commingeshautdebit.fr [185.131.40.67]) (Authenticated sender: admin@nicolasgoaziou.fr) by relay10.mail.gandi.net (Postfix) with ESMTPSA id E99F6240007; Wed, 20 May 2020 13:56:55 +0000 (UTC) From: Nicolas Goaziou To: stardiviner Subject: Re: [Suggestion] add an API function for getting link description References: <87pnazrlea.fsf@gmail.com> Mail-Followup-To: stardiviner , Org Mode Date: Wed, 20 May 2020 15:56:54 +0200 In-Reply-To: <87pnazrlea.fsf@gmail.com> (stardiviner's message of "Wed, 20 May 2020 17:44:13 +0800") Message-ID: <87mu62hfq1.fsf@nicolasgoaziou.fr> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=217.70.178.230; envelope-from=mail@nicolasgoaziou.fr; helo=relay10.mail.gandi.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/20 09:56:56 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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 Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=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-Spam-Score: -1.01 X-TUID: 7k3NJXbcbMsA Hello, stardiviner 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 n= ot 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 l= ink))))) > #+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=E2=80=A6), but will be faster. So there is no si= ngle function that fits every need. Regards, --=20 Nicolas Goaziou