From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id qDFUHV1BQmKxCAAAgWs5BA (envelope-from ) for ; Tue, 29 Mar 2022 01:14:37 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id WNbFFV1BQmKYqgAAG6o9tA (envelope-from ) for ; Tue, 29 Mar 2022 01:14:37 +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 011CC211FB for ; Tue, 29 Mar 2022 01:14:36 +0200 (CEST) Received: from localhost ([::1]:33568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nYyZI-0002l3-0z for larch@yhetil.org; Mon, 28 Mar 2022 19:14:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:42762) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nYyX0-0000FK-EX for emacs-orgmode@gnu.org; Mon, 28 Mar 2022 19:12:14 -0400 Received: from [2a01:c0:2:6:225:90ff:fed2:2b47] (port=41875 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 1nYyWy-0003gm-HV for emacs-orgmode@gnu.org; Mon, 28 Mar 2022 19:12:13 -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 22SNCAiM009636 sender hugo@heagren.com ; Tue, 29 Mar 2022 00:12:10 +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= 202203; bh=Dee8gFi8AzGSOASGMR3ewbfPM4Q=; b=FkcvoRMg4xA8HFXL312cu fSjo0oaCSwktreE3xDF3tV06Rk7j8DGp5QAxww+/5sl5v5dnGPVIM2aud7voRgG+ 7vXOoTQaUOIMQSbA20jrsnBL+YgDfWcCjxwXcRwpwiiqztiFZJt//VEqsBUDm0E2 4IFErtCgG4LUwBPfDl5ysezUeCASopqusB6y/SAqaCT8YF/f1Yq40FHcTTV8Dhdd Lsn2WJ38mx0VKBRguurUlUc4kchNSWTuaAjPV/SKZvK X-Assp-Version: 2.6.5(21218) on ASSP.OA5.COM X-Assp-ID: ASSP.OA5.COM X-Assp-Session: 7F4B88F478E8 (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-156.nat-2.net.cam.ac.uk ([131.111.5.156] helo=localhost) by ASSP.OA5.COM with SMTPSA(TLSv1_2 ECDHE-RSA-AES128-GCM-SHA256) (2.6.5); 29 Mar 2022 00:12:10 +0100 From: Hugo Heagren To: emacs-orgmode@gnu.org Cc: Hugo Heagren Subject: [PATCH] ol.el: add description format parameter to org-link-parameters Date: Tue, 29 Mar 2022 00:15:49 +0100 Message-Id: <20220328231549.30935-2-hugo@heagren.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220328231549.30935-1-hugo@heagren.com> References: <20220328231549.30935-1-hugo@heagren.com> 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=1648509277; 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=/jiU5/IOLWraKOmIWuxfISFZxHSOA1Vvl9X1c7/AaZ8=; b=oGVvWC1Yp9afqP2Izpte0UUSg0LS/aHtr3oCDoM+/m3zSLtJTyL70ZodfirOlfghT+f+Jp xdBYhJ5XJOe4lLpUXdbAzWtuqI9vBVU0emS7B3sABhSldvKKUMPvMp3r9hr1EwH4ZS2wi1 Qdu7/XRHUDmzZCENDsN/5hyCV0sGnWSL7pMdlO5+48hJInGS7zRN34YL6kRgJgwckelMxu YlXi2zS/Y4zv7SOCVwBeMGNaUesZXTc8AQePMZq2vZRmCsiRjHnsEHzcY5BH2tb+0p2v/I X45EizfU1FKk1O3tPVOHE4lLXrLJY8enPJ2uXDiuIs2V0LBvgNw5I1oE51dGZg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1648509277; a=rsa-sha256; cv=none; b=GB840HgZHUha1sK+g3ehGzO6GYevaPU7dU5U/SPG5pDR5zn2RVKl6GYEbjlgunY4wC0Lxe xpUUBDL1VL81DpKTFK7X9Gv03MDRoVVN/Q6z2RuvGeEVjY5BmeJhSbpsS220VJwanXYNtO eLDsJqqR8IwhGA1jVClofnpixe5UamIgNGSJaS86AgQoyncbmaJNdKyHpOgOzpv4hp/jmk Re5w/9AiKX4/cPi3h+iTlXz8fkvzvufHnjgxwFN3b9MMETZdZDEDYXerkZU4+lxd5Q1aIC kf4E86pqskOLVq3KXQzEfmUEI2/xSw4gCwfferkQiwEUd+hBwwfaYAV9bWSemg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=heagren.com header.s=202203 header.b=FkcvoRMg; 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: -7.87 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=heagren.com header.s=202203 header.b=FkcvoRMg; 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: 011CC211FB X-Spam-Score: -7.87 X-Migadu-Scanner: scn0.migadu.com X-TUID: DVhPMidhXkd5 * 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. --- lisp/ol.el | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/lisp/ol.el b/lisp/ol.el index 1b2bb9a9a..af0aaaf35 100644 --- a/lisp/ol.el +++ b/lisp/ol.el @@ -140,6 +140,13 @@ 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 the full link text as the sole argument, and should + return a single string. + `:display' Value for `invisible' text property on the hidden parts of the @@ -1761,11 +1768,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 +1785,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 +1852,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,14 +1929,24 @@ 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) - (t (condition-case nil - (funcall org-link-make-description-function link desc) - (error - (message "Can't get link description from %S" - (symbol-name org-link-make-description-function)) - (sit-for 2) - nil)))))) + (desc) + ((org-link-get-parameter + type + :default-description) + (let ((def (org-link-get-parameter + type + :default-description))) + (cond + ((stringp def) def) + ((functionp def) + (funcall def link))))) + (org-link-make-description-function + (funcall org-link-make-description-function link desc)) + (t (error + (message "Can't get link description from %S" + (symbol-name org-link-make-description-function)) + (sit-for 2) + nil))))) (setq desc (if (called-interactively-p 'any) (read-string "Description: " initial-input) initial-input)))) -- 2.20.1