From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id GOk/IwKQEF/ZVgAA0tVLHw (envelope-from ) for ; Thu, 16 Jul 2020 17:36:02 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id AGVEHwKQEF+RIAAA1q6Kng (envelope-from ) for ; Thu, 16 Jul 2020 17:36:02 +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 D1941940225 for ; Thu, 16 Jul 2020 17:36:01 +0000 (UTC) Received: from localhost ([::1]:42538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jw7na-0002Ty-IB for larch@yhetil.org; Thu, 16 Jul 2020 13:35:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40936) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jw7n9-0002Rq-IC for emacs-orgmode@gnu.org; Thu, 16 Jul 2020 13:35:31 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]:34472) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jw7n7-0003go-6B for emacs-orgmode@gnu.org; Thu, 16 Jul 2020 13:35:31 -0400 Received: by mail-wm1-x335.google.com with SMTP id g10so5796950wmc.1 for ; Thu, 16 Jul 2020 10:35:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:user-agent:mime-version; bh=LAPvGqXm7h42rnqNCtonED2OlKHd/HL0hmJxr27aPkE=; b=vHUbEwyrZ50qD1ci1c9frWFLOXxH4wQxirM14E2sYqUApnrIXmjmmqXC5dAICtVzgV 7idKbugL1F8bbtWzk4IDEAJffL02QYSNiDVA3g0RGL10S4uqea5zvy3leMutur23hYgh i2VhWXjnY2Kpk44qSDCncCLS9Cu4sfMJ3zHAkbdlBRM9zx9WW6EG7fEX/rNKl9CI3Vv1 0yrOEyIM0CeQLW+1tKLueQoJgUAbhW5+p+r4HFOsNCegi/5cP1S80mN+9MdHqfpLMLQ9 k4BW4KtDZdT2m48DsYuE2RWPDhK9+pD6kMA6Uoi8HKE/ELA8sCaY4gJ6m08B7mwp98bq a2uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:user-agent :mime-version; bh=LAPvGqXm7h42rnqNCtonED2OlKHd/HL0hmJxr27aPkE=; b=GVJhw4juLlT3H5OHAcNpWrFwDWkjD6Bvs0JgOhM/yIkt/C18bK5mqJvXDrHj+tQMC0 yTJ1fcrwQnaeSeEFr+TBGtRDfpS9/vqMy+x5iQn+908qZaXgB4e7/lVpY5kMI2bGgDfJ zGilhjjWwZHaO937u+EVliWttrh9CecsbkcDWnouUXLArSVYUVMUnoJkK0gF2HMH2WkL xTVxsWmCWlXcGtnUFVRziBEtwHf309btIfNlHFqi6mazqn+hItwc7Qw4+CWD4km37KjH rPBuqp27u+dE9i3ug4XOHtu4QOQEsfPrKg1R6ynC5tkKmMlpSNPzROvCaSbxKSX/m/Gj eG0Q== X-Gm-Message-State: AOAM5307hQG0jQwgI14ELPXjz75zt/eg51BRZtF4AbuvETC1VjaOjOEX TLRYmv5mtWVmlOnBMYldXkLciUct X-Google-Smtp-Source: ABdhPJyKgTsIsbCigBu6Mk6nKCpu4DpEf6zNvqNxxQXNF0z4XFYRrXvDuttN2OTBNzOULSAD99xZ+w== X-Received: by 2002:a1c:7413:: with SMTP id p19mr5208760wmc.60.1594920926121; Thu, 16 Jul 2020 10:35:26 -0700 (PDT) Received: from hirondell (alyon-655-1-146-123.w90-14.abo.wanadoo.fr. [90.14.72.123]) by smtp.gmail.com with ESMTPSA id n14sm9487356wro.81.2020.07.16.10.35.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jul 2020 10:35:25 -0700 (PDT) From: =?utf-8?Q?K=C3=A9vin_Le_Gouguec?= To: emacs-orgmode@gnu.org Subject: Default description for abbreviated links Date: Thu, 16 Jul 2020 19:35:23 +0200 Message-ID: <87mu3ze52c.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=kevin.legouguec@gmail.com; helo=mail-wm1-x335.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=vHUbEwyr; dmarc=pass (policy=none) header.from=gmail.com; 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.71 X-TUID: KWe/RTe4AaHZ --=-=-= Content-Type: text/plain Hello Org, I like #+LINK keywords because they make documents self-sufficient: anyone opening my document can follow these links or export the buffer; they do not need to run some Elisp to add to org-link-parameters. One thing I don't know how to customize, however, is how these links are exported when they have no description. Let's say I define this abbreviation: #+LINK: bug https://debbugs.gnu.org/ If I jot down references to [[bug:12345]] in my document, these will be exported as: https://debbugs.gnu.org/12345 Whereas I'd prefer: bug:12345 Looking at org-element-link-parser, I see that this is because the :contents-begin and :contents-end properties are nil, since they correspond to an unmatched optional group in org-link-bracket-re. I could probably customize org-link-parameters, but then my document would not be self-sufficient anymore. Besides, depending on the document I might use the same abbreviation for different URLs. Would it make sense to add a way for abbreviated links with no description to fallback to LINKKEY:TAG[1] instead of the full URL? If so, what would be the best way to go about it? (1) A single variable (e.g. org-link-abbrev-default-description), default nil, which a user could set to 'key-tag or just 'tag. (2) A third entry in org-link-abbrev-alist(-local), default nil, which a user could set to 'key-tag or just 'tag. (3) Something else (e.g. a new alist). I've attached a very crude patch for (1): now if I stick this footer in my Org files: #+LINK: bug https://debbugs.gnu.org/ # Local variables: # org-link-abbrev-default-description: key-tag # end: Then [[bug:12345]] is exported as bug:12345. WDYT? If the idea is sound, I will clean up the patch, clarify docstrings, add :safe predicates and unit tests, and re-submit. Thank you for your time. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=org-link-description.patch diff --git a/lisp/ol.el b/lisp/ol.el index 82fc69769..fa0ade8b8 100644 --- a/lisp/ol.el +++ b/lisp/ol.el @@ -255,6 +255,16 @@ See the manual for examples." (`(,(pred stringp) . ,(pred stringp)) t) (_ nil)))) +(defcustom org-link-abbrev-default-description nil + "Fallback behaviour for abbreviated links with no description. +If this is nil, do not set a description; some export backends +will use the fully expanded link as fallback. If 'key-tag, then +use the abbreviated form KEY:TAG. If 'tag, then use TAG." + :group 'org-link + :type '(choice (const :tag "None" nil) + (const :tag "KEY:TAG" key-tag) + (const :tag "TAG" tag))) + (defgroup org-link-follow nil "Options concerning following links in Org mode." :tag "Org Follow Link" @@ -993,6 +1003,16 @@ and then used in capture templates." if store-func collect store-func)) +(defun org-link-abbrev-default-desc (link) + (save-match-data + (when (string-match "^\\([^:]*\\)::?\\(.+\\)$" link) + (pcase org-link-abbrev-default-description + ('nil '(nil nil)) + ('key-tag + (list (match-beginning 1) (match-end 2))) + ('tag + (list (match-beginning 2) (match-end 2))))))) + (defun org-link-expand-abbrev (link) "Replace link abbreviations in LINK string. Abbreviations are defined in `org-link-abbrev-alist'." diff --git a/lisp/org-element.el b/lisp/org-element.el index a693cb68d..a82fce52a 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -3146,11 +3146,19 @@ Assume point is at the beginning of the link." ;; (e.g., insert [[shell:ls%20*.org]] instead of ;; [[shell:ls *.org]], which defeats Org's focus on ;; simplicity. - (setq raw-link (org-link-expand-abbrev - (org-link-unescape - (replace-regexp-in-string - "[ \t]*\n[ \t]*" " " - (match-string-no-properties 1))))) + (let ((link-spec (match-string-no-properties 1)) + (link-beg (match-beginning 1))) + (setq raw-link (org-link-expand-abbrev (org-link-unescape + (replace-regexp-in-string + "[ \t]*\n[ \t]*" " " + link-spec)))) + ;; If there is no description, try to find a fallback. + (unless contents-begin + (pcase-let ((`(,default-beg ,default-end) + (org-link-abbrev-default-desc link-spec))) + (when default-beg + (setq contents-begin (+ link-beg default-beg) + contents-end (+ link-beg default-end)))))) ;; Determine TYPE of link and set PATH accordingly. According ;; to RFC 3986, remove whitespaces from URI in external links. ;; In internal ones, treat indentation as a single space. --=-=-= Content-Type: text/plain [1] Or just TAG. If I look at ORG-NEWS for examples, I see a lot of [[doc:org-symbol][org-symbol]]. --=-=-=--