Browse Source

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.
Reuben Thomas 7 years ago
parent
commit
a307011136
1 changed files with 22 additions and 21 deletions
  1. 22 21
      lisp/org.el

+ 22 - 21
lisp/org.el

@@ -1928,10 +1928,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)))
 
@@ -10146,15 +10146,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))
@@ -10288,17 +10287,19 @@ 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
+      (let ((initial-input
+	     (cond
+	      (default-description)
+	      ((not org-make-link-description-function) desc)
+	      (t (condition-case nil
+		     (funcall org-make-link-description-function link desc)
+		   (error
+		    (message "Can't get link description from `%s'"
+			     (symbol-name org-make-link-description-function))
+		    (sit-for 2)
+		    nil))))))
+	(setq desc (read-string "Description: " initial-input))))
 
     (unless (string-match "\\S-" desc) (setq desc nil))
     (when remove (apply 'delete-region remove))