summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2014-05-17 11:14:27 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2014-05-17 11:14:27 +0200
commit3702dce1db942fde746025523829cde0f2db6dec (patch)
tree2450f09c2e6652d1204da09a40109ff732887171
parentf8b7eb4e20bfd1ff1a8d00e61da66b44a86830e7 (diff)
downloadorg-mode-3702dce1db942fde746025523829cde0f2db6dec.tar.gz
Fix previous patch
* lisp/org.el (org-update-radio-target-regexp): Fix previous patch. * testing/lisp/test-org.el (test-org/update-radio-target-regexp): Add test.
-rw-r--r--lisp/org.el36
-rw-r--r--testing/lisp/test-org.el19
2 files changed, 40 insertions, 15 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 14e8cee..c7f0d7f 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -6107,6 +6107,8 @@ by a #."
Also refresh fontification if needed."
(interactive)
(let ((old-regexp org-target-link-regexp)
+ (before-re "\\(?:^\\|[^[:alnum:]]\\)\\(")
+ (after-re "\\)\\(?:$\\|[^[:alnum:]]\\)")
(targets
(org-with-wide-buffer
(goto-char (point-min))
@@ -6120,25 +6122,31 @@ Also refresh fontification if needed."
rtn))))
(setq org-target-link-regexp
(and targets
- (concat "\\(?:^\\|[^[:alnum:]]\\)\\("
+ (concat before-re
(mapconcat
- (lambda (x)
- (replace-regexp-in-string
- " +" "\\s-+" (regexp-quote x) t t))
+ #'(lambda (x)
+ (replace-regexp-in-string
+ " +" "\\s-+" (regexp-quote x) t t))
targets
"\\|")
- "\\)\\(?:$\\|[^[:alnum:]]\\)")))
+ after-re)))
(unless (equal old-regexp org-target-link-regexp)
;; Clean-up cache.
- (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))))))
+ (let ((regexp (cond ((not old-regexp) org-target-link-regexp)
+ ((not org-target-link-regexp) old-regexp)
+ (t
+ (concat before-re
+ (mapconcat
+ #'(lambda (re)
+ (substring re (length before-re)
+ (- (length after-re))))
+ (list old-regexp org-target-link-regexp)
+ "\\|")
+ after-re)))))
+ (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 14ef96f..e82b2fd 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -1742,7 +1742,7 @@ Text.
(ert-deftest test-org/update-radio-target-regexp ()
"Test `org-update-radio-target-regexp' specifications."
- ;; Properly update cache.
+ ;; Properly update cache with no previous radio target regexp.
(should
(eq 'link
(org-test-with-temp-text "radio\n\nParagraph\n\nradio"
@@ -1752,6 +1752,23 @@ Text.
(insert ">>>")
(org-update-radio-target-regexp)
(goto-char (point-max))
+ (org-element-type (org-element-context)))))
+ ;; Properly update cache with previous radio target regexp.
+ (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)
+ (search-backward "r")
+ (delete-char 5)
+ (insert "new")
+ (org-update-radio-target-regexp)
+ (goto-char (point-max))
+ (delete-region (line-beginning-position) (point))
+ (insert "new")
(org-element-type (org-element-context))))))