diff --git a/lisp/org.el b/lisp/org.el index 2661686e7..14e8cee7d 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -6130,11 +6130,15 @@ Also refresh fontification if needed." "\\)\\(?:$\\|[^[:alnum:]]\\)"))) (unless (equal old-regexp org-target-link-regexp) ;; Clean-up cache. - (when old-regexp - (org-with-wide-buffer - (goto-char (point-min)) - (while (re-search-forward old-regexp nil t) - (org-element-cache-refresh (match-beginning 1))))) + (let ((regexp (cond + ((not old-regexp) org-target-link-regexp) + ((not org-target-link-regexp) old-regexp) + (t (concat old-regexp "\\|" org-target-link-regexp))))) + (when regexp + (org-with-wide-buffer + (goto-char (point-min)) + (while (re-search-forward regexp nil t) + (org-element-cache-refresh (match-beginning 1)))))) ;; Re fontify buffer. (when (memq 'radio org-highlight-links) (org-restart-font-lock))))) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index ded526df3..14ef96f24 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -1742,14 +1742,17 @@ Text. (ert-deftest test-org/update-radio-target-regexp () "Test `org-update-radio-target-regexp' specifications." - (org-test-with-temp-text "radio\n\nParagraph\n\nradio" - (save-excursion (goto-char (point-max)) (org-element-context)) - (insert "<<<") - (search-forward "o") - (insert ">>>") - (org-update-radio-target-regexp) - (goto-char (point-max)) - (org-element-type (org-element-context)))) + ;; Properly update cache. + (should + (eq 'link + (org-test-with-temp-text "radio\n\nParagraph\n\nradio" + (save-excursion (goto-char (point-max)) (org-element-context)) + (insert "<<<") + (search-forward "o") + (insert ">>>") + (org-update-radio-target-regexp) + (goto-char (point-max)) + (org-element-type (org-element-context))))))