From b4e5195da4f084a9efd9697db556168d9907a17e Mon Sep 17 00:00:00 2001 From: Max Nikulin Date: Wed, 14 Sep 2022 22:43:51 +0700 Subject: [PATCH 1/2] ol.el: Always prompt for description in `org-insert-link' * lisp/ol.el (org-insert-link): Do not bypass code trying to generated description and prompt user when link path and description are identical. Make behavior of description prompt more consistent. Remove confusing `auto-desc' local variable. Originally the variable was added with implementation of completion of stored link target by the description in the commit 1e34c5d34 Bastien Guerry, "org.el: Fontify links to current buffer when inserting a link", 2012-08-03 14:08:20 +0200. The feature was broken soon by the commit 7f096ad37 Tony Day, "org-insert-link: Use ido when inserting links", 2012-10-12 14:39:53 +1100. Last decade users were not asked to edit description in the case of the same link target and description (a remained side effect of 1e34c5d34). Recent commit 0432f4fe6 Max Nikulin, "ol.el: Restore complete by description for insert link", 2022-09-10 17:23:13 +0700 restored completion by description. Due to the commit 4fc2c8dd8 Ihor Radchenko, "org-store-link: Default to empty description for target/custom-id links", 2022-08-10 13:25:26 +0800 description identical to link path became a more rare case. An alternative would be fixing condition to allow users to edit description when it is the same as the path, but use stored description without additional interaction when the link is chosen by description completion. Despite it was likely the original intention, always asking the user to confirm or edit description may be more consistent behavior. --- lisp/ol.el | 72 ++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/lisp/ol.el b/lisp/ol.el index f3f6e04ef..8f700397e 100644 --- a/lisp/ol.el +++ b/lisp/ol.el @@ -1822,7 +1822,7 @@ non-interactively, don't allow to edit the default description." (all-prefixes (append (mapcar #'car abbrevs) (mapcar #'car org-link-abbrev-alist) (org-link-types))) - entry auto-desc) + entry) (cond (link-location) ; specified by arg, just use it. ((org-in-regexp org-link-bracket-re 1) @@ -1885,8 +1885,7 @@ Use TAB to complete link prefixes, then RET for type-specific completion support (unless (org-string-nw-p link) (user-error "No link selected")) (dolist (l org-stored-links) (when (equal link (cadr l)) - (setq link (car l)) - (setq auto-desc t))) + (setq link (car l)))) (when (or (member link all-prefixes) (and (equal ":" (substring link -1)) (member (substring link 0 -1) all-prefixes) @@ -1963,41 +1962,40 @@ Use TAB to complete link prefixes, then RET for type-specific completion support (when (equal desc origpath) (setq desc path))))) - (unless auto-desc - (let* ((type - (cond - ((and all-prefixes - (string-match (rx-to-string `(: string-start (submatch (or ,@all-prefixes)) ":")) link)) - (match-string 1 link)) - ((file-name-absolute-p link) "file") - ((string-match "\\`\\.\\.?/" link) "file"))) - (initial-input - (cond - (description) - (desc) - ((org-link-get-parameter type :insert-description) - (let ((def (org-link-get-parameter type :insert-description))) - (condition-case nil - (cond - ((stringp def) def) - ((functionp def) - (funcall def link desc))) - (error - (message "Can't get link description from org link parameter `:insert-description': %S" - def) - (sit-for 2) - nil)))) - (org-link-make-description-function + (let* ((type + (cond + ((and all-prefixes + (string-match (rx-to-string `(: string-start (submatch (or ,@all-prefixes)) ":")) link)) + (match-string 1 link)) + ((file-name-absolute-p link) "file") + ((string-match "\\`\\.\\.?/" link) "file"))) + (initial-input + (cond + (description) + (desc) + ((org-link-get-parameter type :insert-description) + (let ((def (org-link-get-parameter type :insert-description))) (condition-case nil - (funcall org-link-make-description-function link desc) - (error - (message "Can't get link description from %S" - org-link-make-description-function) - (sit-for 2) - nil)))))) - (setq desc (if (called-interactively-p 'any) - (read-string "Description: " initial-input) - initial-input)))) + (cond + ((stringp def) def) + ((functionp def) + (funcall def link desc))) + (error + (message "Can't get link description from org link parameter `:insert-description': %S" + def) + (sit-for 2) + nil)))) + (org-link-make-description-function + (condition-case nil + (funcall org-link-make-description-function link desc) + (error + (message "Can't get link description from %S" + org-link-make-description-function) + (sit-for 2) + nil)))))) + (setq desc (if (called-interactively-p 'any) + (read-string "Description: " initial-input) + initial-input))) (unless (org-string-nw-p desc) (setq desc nil)) (when remove (apply #'delete-region remove)) -- 2.25.1