diff options
author | Nicolas Goaziou <n.goaziou@gmail.com> | 2014-03-23 11:28:26 +0100 |
---|---|---|
committer | Nicolas Goaziou <n.goaziou@gmail.com> | 2014-03-24 14:13:24 +0100 |
commit | 8212776cfcccd3a45594797b6253bb94f1a3944e (patch) | |
tree | 684bd0e1433879df16ac9fe985bb6810c3e9be5d | |
parent | 955d9d8a78b82fa038ef9fd32ec185bda8ef9658 (diff) | |
download | org-mode-8212776cfcccd3a45594797b6253bb94f1a3944e.tar.gz |
Fix radio target parsing
* lisp/org-element.el (org-element-all-successors,
org-element-object-restrictions): Prioritize `link' over other
successors in order to find radio links starting with another syntax
object (e.g., an entity). Also allow text markup within radio
targets.
(org-element-link-parser): Add contents to radio targets.
* lisp/org.el (org-make-target-link-regexp): Fix regexp so it can
match targets starting with an Org object (e.g., an entity).
(org-ctrl-c-ctrl-c): Fix function when applied on an object contained
within a radio target.
* testing/lisp/test-org-element.el (test-org-element/radio-target-parser): Add test.
* testing/lisp/test-ox.el (test-org-export/resolve-radio-link): Add test.
-rw-r--r-- | lisp/org-element.el | 19 | ||||
-rw-r--r-- | lisp/org.el | 10 | ||||
-rw-r--r-- | testing/lisp/test-org-element.el | 15 | ||||
-rw-r--r-- | testing/lisp/test-ox.el | 9 |
4 files changed, 37 insertions, 16 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el index 9bb7944..9589714 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -187,10 +187,10 @@ is not sufficient to know if point is at a paragraph ending. See "List of recursive element types aka Greater Elements.") (defconst org-element-all-successors - '(export-snippet footnote-reference inline-babel-call inline-src-block - latex-or-entity line-break link macro plain-link radio-target - statistics-cookie sub/superscript table-cell target - text-markup timestamp) + '(link export-snippet footnote-reference inline-babel-call + inline-src-block latex-or-entity line-break macro plain-link + radio-target statistics-cookie sub/superscript table-cell target + text-markup timestamp) "Complete list of successors.") (defconst org-element-object-successor-alist @@ -328,13 +328,13 @@ Don't modify it, set `org-element-affiliated-keywords' instead.") (paragraph ,@standard-set) ;; Remove any variable object from radio target as it would ;; prevent it from being properly recognized. - (radio-target latex-or-entity sub/superscript) + (radio-target latex-or-entity sub/superscript text-markup) (strike-through ,@standard-set) (subscript ,@standard-set) (superscript ,@standard-set) ;; Ignore inline babel call and inline src block as formulas are ;; possible. Also ignore line breaks and statistics cookies. - (table-cell export-snippet footnote-reference latex-or-entity link macro + (table-cell link export-snippet footnote-reference latex-or-entity macro radio-target sub/superscript target text-markup timestamp) (table-row table-cell) (underline ,@standard-set) @@ -346,7 +346,8 @@ a list of successors that will be called within an element or object of such type. For example, in a `radio-target' object, one can only find -entities, latex-fragments, subscript and superscript. +entities, latex-fragments, subscript, superscript and text +markup. This alist also applies to secondary string. For example, an `headline' type element doesn't directly contain objects, but @@ -3095,7 +3096,9 @@ Assume point is at the beginning of the link." ((and org-target-link-regexp (looking-at org-target-link-regexp)) (setq type "radio" link-end (match-end 0) - path (org-match-string-no-properties 0))) + path (org-match-string-no-properties 0) + contents-begin (match-beginning 0) + contents-end (match-end 0))) ;; Type 2: Standard link, i.e. [[http://orgmode.org][homepage]] ((looking-at org-bracket-link-regexp) (setq contents-begin (match-beginning 3) diff --git a/lisp/org.el b/lisp/org.el index 56ae096..6d6fbeb 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -6097,7 +6097,7 @@ The regular expression finds the targets also if there is a line break between words." (and targets (concat - "\\<\\(" + "\\_<\\(" (mapconcat (lambda (x) (setq x (regexp-quote x)) @@ -6106,7 +6106,7 @@ between words." x) targets "\\|") - "\\)\\>"))) + "\\)\\_>"))) (defun org-activate-tags (limit) (if (re-search-forward (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@#%:]+:\\)[ \r\n]") limit t) @@ -20262,13 +20262,15 @@ This command does many different things, depending on context: ;; When at a link, act according to the parent instead. (link (setq context (org-element-property :parent context)) (setq type (org-element-type context))) - ;; Unsupported object types: check parent element instead. + ;; Unsupported object types: refer to the first supported + ;; element or object containing it. ((bold code entity export-snippet inline-babel-call inline-src-block italic latex-fragment line-break macro strike-through subscript superscript underline verbatim) (while (and (setq context (org-element-property :parent context)) (not (memq (setq type (org-element-type context)) - '(paragraph verse-block table-cell))))))) + '(radio-target paragraph verse-block + table-cell))))))) ;; For convenience: at the first line of a paragraph on the ;; same line as an item, apply function on that item instead. (when (eq type 'paragraph) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index c65151e..9d00af9 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -1688,12 +1688,19 @@ Outside list" "Test `radio-target' parser." ;; Standard test. (should - (org-test-with-temp-text "<<<radio>>>" - (org-element-map (org-element-parse-buffer) 'radio-target 'identity))) + (eq 'radio-target + (org-test-with-temp-text "<<<radio>>>" + (org-element-type (org-element-context))))) ;; Radio targets with objects. (should - (org-test-with-temp-text "<<<radio \\alpha>>>" - (org-element-map (org-element-parse-buffer) 'radio-target 'identity)))) + (eq 'radio-target + (org-test-with-temp-text "<<<radio \\alpha>>>" + (org-element-type (org-element-context))))) + ;; Radio targets starting with an object. + (should + (eq 'radio-target + (org-test-with-temp-text "<<<\\alpha radio>>>" + (org-element-type (org-element-context)))))) ;;;; Section diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el index f5572d3..759e7a1 100644 --- a/testing/lisp/test-ox.el +++ b/testing/lisp/test-ox.el @@ -1858,6 +1858,15 @@ Another text. (ref:text) (org-export-resolve-radio-link (org-element-map tree 'link 'identity info t) info)))) + ;; Radio target with objects at its beginning. + (should + (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio" + (org-update-radio-target-regexp) + (let* ((tree (org-element-parse-buffer)) + (info `(:parse-tree ,tree))) + (org-export-resolve-radio-link + (org-element-map tree 'link 'identity info t) + info)))) ;; Multiple radio targets. (should (equal '("radio1" "radio2") |