Re: [O] Bug: Fix for org-make-link-description-function use in org-insert-link [9.0.10 (9.0.10-5-g1654a5-elpa @ /home/rrt/.emacs.d/elpa/org-20170904/)]

2017-09-07 Thread Nicolas Goaziou
Hello,

Reuben Thomas  writes:

> ​Attached, a revised patch.

Applied, with a minor refactoring so some lines could fit under 80
columns. 

Thank you!

Regards,

-- 
Nicolas Goaziou



Re: [O] Bug: Fix for org-make-link-description-function use in org-insert-link [9.0.10 (9.0.10-5-g1654a5-elpa @ /home/rrt/.emacs.d/elpa/org-20170904/)]

2017-09-07 Thread Reuben Thomas
On 5 September 2017 at 23:02, Nicolas Goaziou 
wrote:

> Reuben Thomas  writes:
>
> > ​If you (or someone) can confirm your interpretation above, I would be
> > happy to update my patch to implement the two behaviours required,
> namely,
> > that org-make-link-description-function is only called if the
> > default-description argument to org-insert-link is nil
>
> Ack.
>
> > and that if that function returns nil, then the link location is used.
> > I would also clarify the docstring regarding the second behaviour.
>
> It may not be a terribly useful behaviour anyway. You can always use
> (lambda (link description) link) as
> `org-make-link-description-function'.
>
> Perhaps we can simply remove "When nil, the link location will be used"
> from the docstring. Your call.
>

​I've removed it.​

​Attached, a revised patch.

-- 
https://rrt.sc3d.org
From df6e155c0e14bae6cebb2e8ac904405163c32b7d Mon Sep 17 00:00:00 2001
From: Reuben Thomas 
Date: Tue, 5 Sep 2017 17:00:25 +0100
Subject: [PATCH] Fix logic of calling org-make-link-desciption-function

* lisp/org.el (org-insert-link): Simplify so that description is only
prompted for once, if auto-desc is not set, and takes as its default
value, in order, default-description, the return value of
org-make-link-description-function (if the variable is non-nil), and
the current desc. Update the docstring to reflect that
default-description takes precedence over
org-make-link-description-function.
(org-make-link-description-function): Remove from docstring the
statement that if the variable is nil, then the link will be used as
the default description. This is undesirable, and was not in any case
implemented.
---
 lisp/org.el | 41 -
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 889987c..4347111 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -1939,10 +1939,10 @@ in the Org buffer so that the change takes effect."
 
 (defcustom org-make-link-description-function nil
   "Function to use for generating link descriptions from links.
-When nil, the link location will be used.  This function must take
-two parameters: the first one is the link, the second one is the
-description generated by `org-insert-link'.  The function should
-return the description to use."
+This function must take two parameters: the first one is the
+link, the second one is the description generated by
+`org-insert-link'.  The function should return the description to
+use."
   :group 'org-link
   :type '(choice (const nil) (function)))
 
@@ -10152,15 +10152,14 @@ the current directory or below.
 A `\\[universal-argument] \\[universal-argument] \\[universal-argument]' \
 prefix negates `org-keep-stored-link-after-insertion'.
 
-If `org-make-link-description-function' is non-nil, this function will be
-called with the link target, and the result will be the default
-link description.
-
 If the LINK-LOCATION parameter is non-nil, this value will be used as
 the link location instead of reading one interactively.
 
-If the DEFAULT-DESCRIPTION parameter is non-nil, this value will be used
-as the default description."
+If the DEFAULT-DESCRIPTION parameter is non-nil, this value will
+be used as the default description.  Otherwise, if
+`org-make-link-description-function' is non-nil, this function
+will be called with the link target, and the result will be the
+default link description."
   (interactive "P")
   (let* ((wcf (current-window-configuration))
 	 (origbuf (current-buffer))
@@ -10294,17 +10293,17 @@ Use TAB to complete link prefixes, then RET for type-specific completion support
 	  (when (equal desc origpath)
 	(setq desc path)
 
-(if org-make-link-description-function
-	(setq desc
-	  (or (condition-case nil
-		  (funcall org-make-link-description-function link desc)
-		(error (progn (message "Can't get link description from `%s'"
-	   (symbol-name org-make-link-description-function))
-  (sit-for 2) nil)))
-		  (read-string "Description: " default-description)))
-  (if default-description (setq desc default-description)
-	(setq desc (or (and auto-desc desc)
-		   (read-string "Description: " desc)
+(unless auto-desc
+  (setq desc (read-string "Description: "
+			  (or default-description
+  (when org-make-link-description-function
+(condition-case nil
+	(funcall org-make-link-description-function link desc)
+  (error (progn (message "Can't get link description from `%s'"
+			 (symbol-name org-make-link-description-function))
+		(sit-for 2) nil
+  
+  desc
 
 (unless (string-match "\\S-" desc) (setq desc nil))
 (when remove (apply 'delete-region remove))
-- 
2.7.4



Re: [O] Bug: Fix for org-make-link-description-function use in org-insert-link [9.0.10 (9.0.10-5-g1654a5-elpa @ /home/rrt/.emacs.d/elpa/org-20170904/)]

2017-09-05 Thread Nicolas Goaziou
Reuben Thomas  writes:

> ​If you (or someone) can confirm your interpretation above, I would be
> happy to update my patch to implement the two behaviours required, namely,
> that org-make-link-description-function is only called if the
> default-description argument to org-insert-link is nil

Ack.

> and that if that function returns nil, then the link location is used.
> I would also clarify the docstring regarding the second behaviour.

It may not be a terribly useful behaviour anyway. You can always use
(lambda (link description) link) as
`org-make-link-description-function'.

Perhaps we can simply remove "When nil, the link location will be used"
from the docstring. Your call.

Thank you.

Regards,



Re: [O] Bug: Fix for org-make-link-description-function use in org-insert-link [9.0.10 (9.0.10-5-g1654a5-elpa @ /home/rrt/.emacs.d/elpa/org-20170904/)]

2017-09-05 Thread Reuben Thomas
On 5 September 2017 at 21:49, Nicolas Goaziou 
wrote:

> Hello,
>

​Hi, thanks for looking at this.​


> Reuben Thomas  writes:
>
> > This seems to be incorrect behaviour, as the docstring for
> > org-insert-link says:
> >
> >   If `org-make-link-description-function' is non-nil, this function
> will be
> >   called with the link target, and the result will be the default
> >   link description.
> >
> > The implication is that the value returned is used as the default, not
> > that it overrides the prompt.
>
> I agree.
>
> > First, org-make-link-description-function is called if it is non-nil,
> > and used to set default-description.
>
> I think the optional parameter from the function call should still
> prevail. I.e., shouldn't this function be called when
> DEFAULT-DESCRIPTION is nil (e.g., called interatively)?
>

​This question occurred to me too, but I didn't form an opinion. However, I
am inclined to agree with you on thinking about it some more.​


> > Then (unless auto-desc is non-nil) the description is prompted for with
> > default-description as the default value (unless
> > org-make-link-description-function returned nil, in which case the
> > current value of desc, if any, is used).
> >
> > There is one further matter that my patch does not address: the
> > docstring for org-make-link-description-function says:
> >
> > “When [org-make-link-description-function is] nil, the link location
> > will be used.”
> >
> > This does not happen (it’s precisely the behaviour I’ve been trying to
> > obtain!), and my patch does not make it happen. Indeed, it’s not clear
> > that it’s desirable (if one is using numbered sections, for example).
>
> Obviously, it would not be desirable.
>
> However, I think it should read "When
> `org-make-link-description-function' _returns_ nil, the link location is
> used". This is not what is implemented either, tho.
>

​If you (or someone) can confirm your interpretation above, I would be
happy to update my patch to implement the two behaviours required, namely,
that org-make-link-description-function is only called if the
default-description argument to org-insert-link is nil, and that if that
function returns nil, then the link location is used. I would also clarify
the docstring regarding the second behaviour.

-- 
https://rrt.sc3d.org 


Re: [O] Bug: Fix for org-make-link-description-function use in org-insert-link [9.0.10 (9.0.10-5-g1654a5-elpa @ /home/rrt/.emacs.d/elpa/org-20170904/)]

2017-09-05 Thread Nicolas Goaziou
Hello,

Reuben Thomas  writes:

> This seems to be incorrect behaviour, as the docstring for
> org-insert-link says:
>
>   If `org-make-link-description-function' is non-nil, this function will be
>   called with the link target, and the result will be the default
>   link description.
>
> The implication is that the value returned is used as the default, not
> that it overrides the prompt.

I agree.

> First, org-make-link-description-function is called if it is non-nil,
> and used to set default-description.

I think the optional parameter from the function call should still
prevail. I.e., shouldn't this function be called when
DEFAULT-DESCRIPTION is nil (e.g., called interatively)?

> Then (unless auto-desc is non-nil) the description is prompted for with
> default-description as the default value (unless
> org-make-link-description-function returned nil, in which case the
> current value of desc, if any, is used).
>
> There is one further matter that my patch does not address: the
> docstring for org-make-link-description-function says:
>
> “When [org-make-link-description-function is] nil, the link location
> will be used.”
>
> This does not happen (it’s precisely the behaviour I’ve been trying to
> obtain!), and my patch does not make it happen. Indeed, it’s not clear
> that it’s desirable (if one is using numbered sections, for example).

Obviously, it would not be desirable. 

However, I think it should read "When
`org-make-link-description-function' _returns_ nil, the link location is
used". This is not what is implemented either, tho.


Regards,

-- 
Nicolas Goaziou