emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Max Nikulin <manikulin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] ol.el: Restore complete by description for insert link
Date: Sat, 10 Sep 2022 18:04:20 +0700	[thread overview]
Message-ID: <tfhqvm$qlf$1@ciao.gmane.io> (raw)
In-Reply-To: <tf7lp4$5ha$1@ciao.gmane.io>

[-- Attachment #1: Type: text/plain, Size: 1902 bytes --]

On 06/09/2022 21:34, Max Nikulin wrote:
> Does anyone have an idea why it was necessary to drop completion of 
> stored links based on their description for the sake of ido?

I have no idea what is the proper way to enable ido for 
`org-insert-link'. Functions and variables specific to ido were removed 
from Org.
(ido-everywhere) and (ido-mode) are not enough.

I tried

     (setq-local completing-read-function #'ido-completing-read)

and the command broke completing read completely.

     (add-function :override completing-read-function #'ido-completing-read)

inspired by `ido-everywhere' code broke M-x, but it enabled ido for 

I believe that descriptions as completion options were removed because 
ido signals an error when nil is passed inside completion list. I 
consider it as a bug in ido (at least in Emacs-27), but even when 
`completing-read-default' is used, it causes appearance of undesired 
"nil" option. No description is a frequent case for links.

So I am attaching a patch to restore completion of link targets by their 
description, nil descriptions are filtered out.

The change is caused by the auto-desc local variable in 
`org-insert-link', its usage is rather strange and confusing currently. 
  Despite with this patch descriptions are restored, I believe that 
logic related to auto-desc should be removed, anyway it was broken for 
10 years. I am unsure in which thread the next change should be discussed.

> P.S. My question is related to the following threads:
> - Carlos Pita. Adding target and custom id links doesn't ask for 
> description. Tue, 2 Aug 2022 14:44:58 -0300. 
> https://list.orgmode.org/D99A712C-18D1-4A4F-8093-35A0BFB469C4@gmail.com
> - Max Nikulin. Re: Bug: org-store-link uses CUSTOM_ID instead of target 
> point. Sat, 6 Nov 2021 19:51:29 +0700. 
> https://list.orgmode.org/e2c807a7-1924-6f08-9e63-4f70aee9d3b5@gmail.com

[-- Attachment #2: 0001-ol.el-Restore-complete-by-description-for-insert-lin.patch --]
[-- Type: text/x-patch, Size: 2814 bytes --]

From 92e36ec13e84d2af1b367e4a3cac34288d1e8c27 Mon Sep 17 00:00:00 2001
From: Max Nikulin <manikulin@gmail.com>
Date: Sat, 10 Sep 2022 17:23:13 +0700
Subject: [PATCH] ol.el: Restore complete by description for insert link

* lisp/ol.el (org-insert-link): Allow completion of link target by its
description.  Almost certainly the feature was removed unintentionally.

Link descriptions were added to completion options in
the commit 1e34c5d34 Bastien Guerry,  "org.el: Fontify links to current
buffer when inserting a link", 2012-08-03 14:08:20 +0200
in response to
Yagnesh Raghava Yakkala, "#+LABEL and CUSTOM_ID with reftex",
Mon, 21 May 2012 04:45:29 +0900

List of description was removed from completion options
likely because `ido-completing-read' signals an error in the case of nil
variant (that is not uncommon for links with no description), see the
commit 7f096ad37 Tony Day, "org-insert-link: Use ido when inserting
links", 2012-10-12 14:39:53 +1100 and the discussion of the patch
- https://list.orgmode.org/04D0E787-A8A1-4246-8DD2-D607E38D61BA@gmail.com/T/#u
  tony day.  [PATCH] * org-insert-link: use ido when inserting links.
  Fri, 12 Oct 2012 14:58:29 +1100
- https://list.orgmode.org/5CE03302-7C87-44BE-B4AF-A6A92C96C803@gmail.com/T/#u
  tony day.  [PATCH] org-insert-link: allow ido usage when inserting
  links.  Fri, 14 Sep 2012 19:21:50 +1000
- https://list.orgmode.org/0CADA13B-8A22-4F34-91B1-2232997C1F04@gmail.com/T/#u
  tony day.  [PATCH] org-insert-link: allow ido usage when inserting
  links. Fri, 12 Oct 2012 14:56:10 +1100
- https://list.orgmode.org/97F9790D-3C7F-490B-BE9B-1A652BB9F187@gmail.com/
  tony day.  PATCH: using ido when inserting links.
  Fri, 14 Sep 2012 18:58:43 +1000

Since auto-desc variable added by first commit was not removed
by second one, I assume that disabling the feature was a side effect
rather than the purpose.
 lisp/ol.el | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lisp/ol.el b/lisp/ol.el
index 7e5398b22..20b085682 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -1878,7 +1878,12 @@ Use TAB to complete link prefixes, then RET for type-specific completion support
 		   "Link: "
 		    (mapcar (lambda (x) (concat x ":")) all-prefixes)
-		    (mapcar #'car org-stored-links))
+		    (mapcar #'car org-stored-links)
+                    ;; Allow description completion.  Avoid "nil" option
+                    ;; in the case of `completing-read-default' and
+                    ;; an error in `ido-completing-read' when some links
+                    ;; have no description.
+                    (delq nil (mapcar 'cadr org-stored-links)))
 		   nil nil nil
 		   (caar org-stored-links)))

  reply	other threads:[~2022-09-10 11:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-06 14:34 ido, org-insert-link, and completion based on link description Max Nikulin
2022-09-10 11:04 ` Max Nikulin [this message]
2022-09-10 19:19   ` [PATCH] ol.el: Restore complete by description for insert link Tim Cross
2022-09-11 12:02     ` Ihor Radchenko
2022-09-11 11:48   ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='tfhqvm$qlf$1@ciao.gmane.io' \
    --to=manikulin@gmail.com \
    --cc=emacs-orgmode@gnu.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).