Browse Source

Fix radio target update

* lisp/org.el (org-update-radio-target-regexp): Properly update cache
  when refreshing regexp.

* testing/lisp/test-org.el (test-org/update-radio-target-regexp): Fix
  test.
Nicolas Goaziou 11 years ago
parent
commit
f8b7eb4e20
2 changed files with 20 additions and 13 deletions
  1. 9 5
      lisp/org.el
  2. 11 8
      testing/lisp/test-org.el

+ 9 - 5
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)))))

+ 11 - 8
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))))))