Browse Source

org.el: Fall back in interactive prompt when `org-make-link-description-function' fails

* org.el (org-make-link-description-function): Enhance
docstring.
(org-insert-link): Fall back on interactive prompt when
`org-make-link-description-function' fails.

Thanks to Sylvain Rousseau for triggering this.
Bastien Guerry 12 years ago
parent
commit
d9e5aed2aa
1 changed files with 12 additions and 6 deletions
  1. 12 6
      lisp/org.el

+ 12 - 6
lisp/org.el

@@ -1395,11 +1395,11 @@ Changing this variable requires a restart of Emacs to become effective."
 	      (const :tag "Footnotes" footnote)))
 
 (defcustom org-make-link-description-function nil
-  "Function to use to generate link descriptions from links.
-If nil the link location will be used.  This function must take
-two parameters; the first is the link and the second the
-description `org-insert-link' has generated, and should return the
-description to use."
+  "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."
   :group 'org-link
   :type 'function)
 
@@ -9497,7 +9497,13 @@ Use TAB to complete link prefixes, then RET for type-specific completion support
 	    (setq desc path))))
 
     (if org-make-link-description-function
-	(setq desc (funcall org-make-link-description-function link desc))
+	(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)))))