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