branch: externals/org commit 084e78544c9fe13ca9651190f8de540416257973 Author: Ihor Radchenko <yanta...@posteo.net> Commit: Ihor Radchenko <yanta...@posteo.net>
org-insert-link: Fix edge case for links like file:::search * lisp/ol.el (org-insert-link): Do not err when filename is not present. * testing/lisp/test-ol.el (test-org-link/insert-link): New test. Reported-by: g-gundam at #org-mode IRC --- lisp/ol.el | 4 +++- testing/lisp/test-ol.el | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lisp/ol.el b/lisp/ol.el index 09802d358c..9ee080e0e5 100644 --- a/lisp/ol.el +++ b/lisp/ol.el @@ -2781,13 +2781,15 @@ non-interactively, don't allow editing the default description." (when (string-match "\\`\\(file\\|docview\\):" link) (let* ((type (match-string-no-properties 0 link)) (path-start (match-end 0)) - (search (and (string-match "::\\(.*\\)\\'" link) + (search (and (string-match "::\\(.*\\)\\'" link path-start) (match-string 1 link))) (path (if search (substring-no-properties link path-start (match-beginning 0)) (substring-no-properties link (match-end 0)))) + ;; file:::search + (path (if (org-string-nw-p path) path (buffer-file-name))) (origpath path)) (setq path (org-link--normalize-filename path diff --git a/testing/lisp/test-ol.el b/testing/lisp/test-ol.el index 44950fe18e..2888d565b3 100644 --- a/testing/lisp/test-ol.el +++ b/testing/lisp/test-ol.el @@ -843,5 +843,16 @@ API in `org-link-parameters'. Used in test (let ((org-link-make-description-function nil)) (test-ol-insert-link-get-desc "fake-link-type:foo-bar"))))) +(ert-deftest test-org-link/insert-link () + "Test `org-insert-link'." + ;; Test edge case when no file name is given. + (org-test-with-temp-text-in-file "" + (let ((file-name (buffer-file-name)) + (org-link-file-path-type 'absolute)) + (org-insert-link nil "file:::going") + (should + (equal (buffer-string) + (format "[[file:%s::going]]" file-name)))))) + (provide 'test-ol) ;;; test-ol.el ends here