branch: externals/org
commit cca46a167646747f91fc51491989a5c05cadea08
Author: Ihor Radchenko <[email protected]>
Commit: Ihor Radchenko <[email protected]>
Fix regression introduced in 2556f75bf
* lisp/ol.el (org-insert-link): Insert updated link after removing
link at point, when we are updating link at point, not before.
* testing/lisp/test-ol.el (test-org-link/insert-link): New test case.
Reported-by: Bruno Cardoso <[email protected]>
Link: https://orgmode.org/list/[email protected]
---
lisp/ol.el | 26 ++++++++++++++------------
testing/lisp/test-ol.el | 8 +++++++-
2 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/lisp/ol.el b/lisp/ol.el
index bb542cbfb3..b918476b50 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -2858,18 +2858,20 @@ non-interactively, don't allow editing the default
description."
(or entry (push link org-link--insert-history))
(setq desc (or desc (nth 1 entry)))))
- (let ((org-link-file-path-type
- (if (equal complete-file '(16))
- 'absolute
- org-link-file-path-type)))
- (insert (org-link-make-string-for-buffer
- link (or description desc)
- (called-interactively-p 'any))))
-
- (when (funcall (if (equal complete-file '(64)) 'not 'identity)
- (not org-link-keep-stored-after-insertion))
- (setq org-stored-links (delq (assoc link org-stored-links)
org-stored-links)))
- (when remove (apply #'delete-region remove))
+ (let (new-link)
+ (let ((org-link-file-path-type
+ (if (equal complete-file '(16))
+ 'absolute
+ org-link-file-path-type)))
+ (setq new-link (org-link-make-string-for-buffer
+ link (or description desc)
+ (called-interactively-p 'any))))
+
+ (when (funcall (if (equal complete-file '(64)) 'not 'identity)
+ (not org-link-keep-stored-after-insertion))
+ (setq org-stored-links (delq (assoc link org-stored-links)
org-stored-links)))
+ (when remove (apply #'delete-region remove))
+ (insert new-link))
;; Redisplay so as the new link has proper invisible characters.
(sit-for 0)))
diff --git a/testing/lisp/test-ol.el b/testing/lisp/test-ol.el
index 47754b703c..75bd537c0a 100644
--- a/testing/lisp/test-ol.el
+++ b/testing/lisp/test-ol.el
@@ -852,7 +852,13 @@ API in `org-link-parameters'. Used in test
(org-insert-link nil "file:::going")
(should
(equal (buffer-string)
- (format "[[file:%s::going]]" file-name))))))
+ (format "[[file:%s::going]]" file-name)))))
+ ;; Test altering the link at point
+ (org-test-with-temp-text "[[file:file.org][<point>description]]"
+ (cl-letf (((symbol-function #'read-string)
+ (lambda (&rest _) "file:file.org")))
+ (org-insert-link nil nil "altered description"))
+ (should (equal (buffer-string) "[[file:file.org][altered description]]"))))
(provide 'test-ol)
;;; test-ol.el ends here