2

Radio targets in org-mode work by recognizing spacing between words. This makes the function redundant in when work wth Chinese and Japanese texts.

I discovered an interesting function in ol.el with a comment that says:

Some languages, e.g., Chinese, do not use spaces to separate words. Also allow to surround radio targets with line-breakable characters.

(defun org-update-radio-target-regexp ()
  "Find all radio targets in this file and update the regular expression.
Also refresh fontification if needed."
  (interactive)
  (let ((old-regexp org-target-link-regexp)
    ;; Some languages, e.g., Chinese, do not use spaces to
    ;; separate words.  Also allow to surround radio targets with
    ;; line-breakable characters.
    (before-re "\\(?:^\\|[^[:alnum:]]\\|\\c|\\)\\(")
    (after-re "\\)\\(?:$\\|[^[:alnum:]]\\|\\c|\\)")
    (targets
     (org-with-wide-buffer
      (goto-char (point-min))
      (let (rtn)
        (while (re-search-forward org-radio-target-regexp nil t)
          ;; Make sure point is really within the object.
          (backward-char)
          (let ((obj (org-element-context)))
        (when (eq (org-element-type obj) 'radio-target)
          (cl-pushnew (org-element-property :value obj) rtn
                  :test #'equal))))
        rtn))))
    (setq org-target-link-regexp
      (and targets
           (concat before-re
               (mapconcat
            (lambda (x)
              (replace-regexp-in-string
               " +" "\\s-+" (regexp-quote x) t t))
            targets
            "\\|")
               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 before-re
                   (mapconcat
                    (lambda (re)
                      (substring re (length before-re)
                         (- (length after-re))))
                    (list old-regexp org-target-link-regexp)
                    "\\|")
                   after-re)))))
    (when (featurep 'org-element)
      (org-with-point-at 1
        (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)))))

Running the function on the sample text below shows that only 1 and 2 are linked.

 <<<劉邵>>>


1. 劉邵

2. 其邯鄲淳事在〈王粲傳〉,蘇林事在〈劉邵〉、〈高堂隆傳〉,樂詳事在〈杜畿傳〉。

3. 六月,權令將軍賀齊督糜芳、劉邵等襲蘄春,邵等生虜宗。

How do we make radio targets work without the spacing requirement?

2
  • Does anyone know how wikipedia tags proper names, especially in languages with no spacing in between words such as Chinese? I am looking for a function very similar to that in org-mode and the radio target is what I've found. Would welcome any suggestions to do otherwise.
    – Sati
    Commented Feb 24, 2020 at 10:58
  • Hidden xml tagging that is indexed, perhaps?
    – Sati
    Commented Feb 24, 2020 at 11:00

1 Answer 1

1

You could insert the UTF-8 character Zero Width Space to invisible separate your targets from the rest of the text.

You can insert that character by using C-x 8 <ret> zero width space.

This seems the easiest option, but with a tradeof. Because, when introducing a new radio target, you need to do a search-replace operation (to insert those invisible spaces into the text).

3
  • Interesting idea. But I'd like better to have a radio target function that supports Chinese text search, separate from the original radio target function.
    – Sati
    Commented Feb 24, 2020 at 6:33
  • Is there a mode that can show zero width spaces? whitespace-mode doesn't seem to show it.
    – Sati
    Commented Mar 14, 2020 at 4:39
  • @Sati it is possible with whitespace-mode together with unicode-whitespace. This additional requires ucs-utils and list-utils and some adjustments. But whitespace-mode does not what you expect, read its documentation!
    – jue
    Commented Mar 16, 2020 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.