From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 2D8aLR+YTGIxnwAAgWs5BA (envelope-from ) for ; Tue, 05 Apr 2022 21:27:27 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id uG+yJR+YTGId+AAAG6o9tA (envelope-from ) for ; Tue, 05 Apr 2022 21:27:27 +0200 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 5EC8F28E08 for ; Tue, 5 Apr 2022 21:27:26 +0200 (CEST) Received: from localhost ([::1]:39088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nbopp-00061u-7n for larch@yhetil.org; Tue, 05 Apr 2022 15:27:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51752) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nbop3-00061V-RC for emacs-orgmode@gnu.org; Tue, 05 Apr 2022 15:26:37 -0400 Received: from [2a01:c0:2:6:225:90ff:fed2:2b47] (port=57776 helo=mail.oa5.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nbooz-0006Zz-CV for emacs-orgmode@gnu.org; Tue, 05 Apr 2022 15:26:36 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) hugo@heagren.com (authenticated bits=0) by mail.oa5.com (8.14.4/8.12.11) with ESMTP id 235JQEr2010784 sender hugo@heagren.com ; Tue, 5 Apr 2022 20:26:14 +0100 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=heagren.com; h= Message-ID:From:Subject:Date:To:MIME-Version:Content-Type; s= 202204; bh=XDunq1GSwiZZq0XpuwAljTjYDt8=; b=Rb05eetx4dfNx+e1ZbtuL u7UXW7YyUdGUXkaHLoN4AOV2RztW2+ZLSLvxDzliKvdx3Ss3DrtIvmZvannLMykB +pQNx/YTQmC2kYA6Aq0TIcAm6uNeBrwH4pdRcJ5M4IRt0/iA/m/ApWjCZcwcJDCN LHIfr7FU1WWUuWl/9DY5el3KVUgaCQ8lYfLDrH9sVRTADfl1VLm8kq139bHnuxcI kWFvzhBpBbG+GWvgbWJT9bY9oeoe5q/lmrURqf2jVdn X-Assp-Version: 2.6.5(21218) on ASSP.OA5.COM X-Assp-ID: ASSP.OA5.COM X-Assp-Session: 7F4B047D2B78 (mail 1) X-Assp-Envelope-From: hugo@heagren.com X-Assp-Intended-For: emacs-orgmode@gnu.org X-Assp-Intended-For: hugo@heagren.com X-Assp-Client-TLS: yes Received: from global-5-154.nat-2.net.cam.ac.uk ([131.111.5.154] helo=localhost) by ASSP.OA5.COM with SMTPSA(TLSv1_2 ECDHE-RSA-AES128-GCM-SHA256) (2.6.5); 5 Apr 2022 20:26:14 +0100 From: Hugo Heagren To: emacs-orgmode@gnu.org Cc: Hugo Heagren Subject: [PATCH v2] ol.el: add description format parameter to org-link-parameters Date: Tue, 5 Apr 2022 20:29:31 +0100 Message-Id: <20220405192931.6747-1-hugo@heagren.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <87zgl1npow.fsf@localhost> References: <87zgl1npow.fsf@localhost> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:c0:2:6:225:90ff:fed2:2b47 (failed) Received-SPF: pass client-ip=2a01:c0:2:6:225:90ff:fed2:2b47; envelope-from=hugo@heagren.com; helo=mail.oa5.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1649186847; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=kLYjrjWsBUVVNpgRPS+v4+SevDP/wYq41x8eeGtAldw=; b=MzBsVCx5+dunSe7sS7cL+Ubu2mjeZ2HAm8WtRQyOrnX9KVHDpetOpuVpZGGQhFtew2aSY+ sBw1Krx/6t/UyH3sDTeK9bUuGuW8iNLM9TxqJmk7ayYpbNXu8N0vDCbWc4o4L1n8LdilpN L+G8dL/tk0txbaP46RLRrRBMNZ4rl//hfU9Je4SvwZTcXZ5JbYeKDwhkmXShl3icTvWUz6 8p2q+gWrtScXjakCBW7JjLkqdnoe5JIausmjJRSiwLYetSuAU8DGEQMFttw07zP2TFnaES x78mecUDInsq8yKVcxU5ZNYxV/RMlMJB+4QAxszUo6SAQ8cJMvWvNe3lETJyVA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1649186847; a=rsa-sha256; cv=none; b=tl5WneDxAZTmCyAEsmd2mPoUPeJTPbOAdpuOSSpIFyChZmlppjv406W02lHY9AChAW9kei 1widPdaBkKQOIvW4E0paunE2/dMzQKSFivlTTvOr3TpVfFQFkOO489ugBKIl6ZYWbUp1Sv ocCVm06vnDNb3p1avsGk/wZKdWnyodi3CVdDK/zsCXdwGa7L6lR7VC3mj/mDcyKHxAcnBl 0q19RfCLCaVBXEWM/9UjlR7egm1cWBstT7x/VuPlR598DbK7arDaEWC/E2cgq6PxvSFgUw R+9Wbx18W4c+j06o+yLqkYOGgdzzyJnfMRhg2AJg+nQ+v2IAiOqniYozSLODtA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=heagren.com header.s=202204 header.b=Rb05eetx; dmarc=pass (policy=quarantine) header.from=heagren.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.57 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=heagren.com header.s=202204 header.b=Rb05eetx; dmarc=pass (policy=quarantine) header.from=heagren.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 5EC8F28E08 X-Spam-Score: -2.57 X-Migadu-Scanner: scn0.migadu.com X-TUID: IqGO6d8x15oF * ol.el (org-link-parameters): add parameter `:default-description', a string or a function. * (org-insert-link): if no description is provided (pre-existing or as an argument), next option is to use the `:default-description' (if non-nil) parameter to generate one. Default descriptions are predictable within a link type, but because link types are quite diverse, are NOT predictable across many types. A type-parameter is thus a good place to store information on the default description. --- I've added the condition-case back to the check on `org-link-make-description', and added a new one to the check for the `:default-description' parameter, as Ihor suggested. I've also modified the handling of that parameter, to reflect `org-link-make-description', and updated the docstring accordingly. Apologies if the subject formatting is not correct, I'm still getting the hang of git-send-email. Hugo lisp/ol.el | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/lisp/ol.el b/lisp/ol.el index 1b2bb9a9a..e74ef8dda 100644 --- a/lisp/ol.el +++ b/lisp/ol.el @@ -140,6 +140,15 @@ link. Function that inserts a link with completion. The function takes one optional prefix argument. +`:default-description' + + String or function used as a default when prompting users for a + link's description. A string is used as-is, a function is + called with two arguments: the full link text, and the + description generated by `org-insert-linke'. It should return + the description to use (this reflects the behaviour of + `org-link-make-description-function'). + `:display' Value for `invisible' text property on the hidden parts of the @@ -1761,11 +1770,14 @@ prefix negates `org-link-keep-stored-after-insertion'. If the LINK-LOCATION parameter is non-nil, this value will be used as the link location instead of reading one interactively. -If the DESCRIPTION parameter is non-nil, this value will be used as the -default description. Otherwise, if `org-link-make-description-function' -is non-nil, this function will be called with the link target, and the -result will be the default link description. When called non-interactively, -don't allow to edit the default description." +If the DESCRIPTION parameter is non-nil, this value will be used +as the default description. If not, and the chosen link type has +a non-nil `:default-description' parameter, that is used to +generate a description as described in `org-link-parameters' +docstring. Otherwise, if `org-link-make-description-function' is +non-nil, this function will be called with the link target, and +the result will be the default link description. When called +non-interactively, don't allow to edit the default description." (interactive "P") (let* ((wcf (current-window-configuration)) (origbuf (current-buffer)) @@ -1775,7 +1787,7 @@ don't allow to edit the default description." (desc region) (link link-location) (abbrevs org-link-abbrev-alist-local) - entry all-prefixes auto-desc) + entry all-prefixes auto-desc type) (cond (link-location) ; specified by arg, just use it. ((org-in-regexp org-link-bracket-re 1) @@ -1842,6 +1854,7 @@ Use TAB to complete link prefixes, then RET for type-specific completion support (and (equal ":" (substring link -1)) (member (substring link 0 -1) all-prefixes) (setq link (substring link 0 -1)))) + (setq type link) (setq link (with-current-buffer origbuf (org-link--try-special-completion link))))) (set-window-configuration wcf) @@ -1918,7 +1931,23 @@ Use TAB to complete link prefixes, then RET for type-specific completion support (let ((initial-input (cond (description) - ((not org-link-make-description-function) desc) + (desc) + ((org-link-get-parameter + type + :default-description) + (condition-case nil + (let ((def (org-link-get-parameter + type + :default-description))) + (cond + ((stringp def) def) + ((functionp def) + (funcall def link desc)))) + (error + (message "Can't get link description from %S" + (symbol-name def)) + (sit-for 2) + nil))) (t (condition-case nil (funcall org-link-make-description-function link desc) (error -- 2.20.1