Remove special behaviour for TARGET keyword

* lisp/org.el (org-store-link, org-link-search, org-options-keywords):
  Remove reference to TARGET keyword.
* lisp/ox.el (org-export-resolve-fuzzy-link, org-export-get-ordinal):
  Do not use TARGET as a destination for links anymore.
* testing/lisp/test-ox.el: Update tests.
* testing/lisp/test-org.el: Update tests.

Its specifications were not useful enough to keep maintaining this
feature.
This commit is contained in:
Nicolas Goaziou 2013-04-04 19:23:07 +02:00
parent 3d65b46c0c
commit 479c21336f
4 changed files with 105 additions and 137 deletions

View File

@ -9456,7 +9456,7 @@ active region."
(et (org-element-type ee))
(ev (plist-get (cadr ee) :value))
(ek (plist-get (cadr ee) :key))
(eok (and (stringp ek) (string-match "name\\|target" ek))))
(eok (and (stringp ek) (string-match "name" ek))))
(setq txt (cond
((org-at-heading-p) nil)
((and (eq et 'keyword) eok) ev)
@ -10630,14 +10630,6 @@ visibility around point, thus ignoring
pos (match-beginning 0))))
;; There is an exact target for this
(goto-char pos))
((save-excursion
(goto-char (point-min))
(and
(re-search-forward
(format "^[ \t]*#\\+TARGET: %s" (regexp-quote s0)) nil t)
(setq type 'dedicated pos (match-beginning 0))))
;; Found an invisible target.
(goto-char pos))
((save-excursion
(goto-char (point-min))
(and
@ -11871,7 +11863,7 @@ keywords relative to each registered export back-end."
"DESCRIPTION:" "DRAWERS:" "EMAIL:" "EXCLUDE_TAGS:" "FILETAGS:" "INCLUDE:"
"INDEX:" "KEYWORDS:" "LANGUAGE:" "MACRO:" "OPTIONS:" "PROPERTY:"
"PRIORITIES:" "SELECT_TAGS:" "SEQ_TODO:" "SETUPFILE:" "STARTUP:" "TAGS:"
"TITLE:" "TODO:" "TYP_TODO:" "SELECT_TAGS:" "EXCLUDE_TAGS:" "TARGET:"))
"TITLE:" "TODO:" "TYP_TODO:" "SELECT_TAGS:" "EXCLUDE_TAGS:"))
(defcustom org-structure-template-alist
'(("s" "#+BEGIN_SRC ?\n\n#+END_SRC"

View File

@ -3808,8 +3808,7 @@ INFO is a plist holding contextual information.
Return value can be an object, an element, or nil:
- If LINK path matches a target object (i.e. <<path>>) or
element (i.e. \"#+TARGET: path\"), return it.
- If LINK path matches a target object (i.e. <<path>>) return it.
- If LINK path exactly matches the name affiliated keyword
\(i.e. #+NAME: path) of an element, return that element.
@ -3831,14 +3830,12 @@ significant."
(if match-title-p (substring raw-path 1) raw-path))))
(cond
;; First try to find a matching "<<path>>" unless user specified
;; he was looking for a headline (path starts with a *
;; he was looking for a headline (path starts with a "*"
;; character).
((and (not match-title-p)
(org-element-map (plist-get info :parse-tree) '(keyword target)
(org-element-map (plist-get info :parse-tree) 'target
(lambda (blob)
(and (or (eq (org-element-type blob) 'target)
(equal (org-element-property :key blob) "TARGET"))
(equal (org-split-string (org-element-property :value blob))
(and (equal (org-split-string (org-element-property :value blob))
path)
blob))
info t)))
@ -3851,10 +3848,10 @@ significant."
(let ((name (org-element-property :name el)))
(when (and name (equal (org-split-string name) path)) el)))
info 'first-match)))
;; Last case: link either points to a headline or to
;; nothingness. Try to find the source, with priority given to
;; headlines with the closest common ancestor. If such candidate
;; is found, return it, otherwise return nil.
;; Last case: link either points to a headline or to nothingness.
;; Try to find the source, with priority given to headlines with
;; the closest common ancestor. If such candidate is found,
;; return it, otherwise return nil.
(t
(let ((find-headline
(function
@ -3946,43 +3943,40 @@ a target, return the same value as if ELEMENT was the closest
table, item or headline containing the target. In any other
case, return the sequence number of ELEMENT among elements or
objects of the same type."
;; A target keyword, representing an invisible target, never has
;; a sequence number.
(unless (eq (org-element-type element) 'keyword)
;; Ordinal of a target object refer to the ordinal of the closest
;; table, item, or headline containing the object.
(when (eq (org-element-type element) 'target)
(setq element
(loop for parent in (org-export-get-genealogy element)
when
(memq
(org-element-type parent)
'(footnote-definition footnote-reference headline item
table))
return parent)))
(case (org-element-type element)
;; Special case 1: A headline returns its number as a list.
(headline (org-export-get-headline-number element info))
;; Special case 2: An item returns its number as a list.
(item (let ((struct (org-element-property :structure element)))
(org-list-get-item-number
(org-element-property :begin element)
struct
(org-list-prevs-alist struct)
(org-list-parents-alist struct))))
((footnote-definition footnote-reference)
(org-export-get-footnote-number element info))
(otherwise
(let ((counter 0))
;; Increment counter until ELEMENT is found again.
(org-element-map (plist-get info :parse-tree)
(or types (org-element-type element))
(lambda (el)
(cond
((eq element el) (1+ counter))
((not predicate) (incf counter) nil)
((funcall predicate el info) (incf counter) nil)))
info 'first-match))))))
;; Ordinal of a target object refer to the ordinal of the closest
;; table, item, or headline containing the object.
(when (eq (org-element-type element) 'target)
(setq element
(loop for parent in (org-export-get-genealogy element)
when
(memq
(org-element-type parent)
'(footnote-definition footnote-reference headline item
table))
return parent)))
(case (org-element-type element)
;; Special case 1: A headline returns its number as a list.
(headline (org-export-get-headline-number element info))
;; Special case 2: An item returns its number as a list.
(item (let ((struct (org-element-property :structure element)))
(org-list-get-item-number
(org-element-property :begin element)
struct
(org-list-prevs-alist struct)
(org-list-parents-alist struct))))
((footnote-definition footnote-reference)
(org-export-get-footnote-number element info))
(otherwise
(let ((counter 0))
;; Increment counter until ELEMENT is found again.
(org-element-map (plist-get info :parse-tree)
(or types (org-element-type element))
(lambda (el)
(cond
((eq element el) (1+ counter))
((not predicate) (incf counter) nil)
((funcall predicate el info) (incf counter) nil)))
info 'first-match)))))
;;;; For Src-Blocks

View File

@ -295,38 +295,34 @@
;;;; Fuzzy Links
;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
;; a target keyword (aka an invisible target: #+TARGET: text), to
;; a named element (#+name: text) and to headlines (* Text).
(ert-deftest test-org/fuzzy-links ()
"Test fuzzy links specifications."
;; 1. Fuzzy link goes in priority to a matching target.
(org-test-with-temp-text
"#+TARGET: Test\n#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
(goto-line 6)
(org-open-at-point)
(should (looking-at "<<Test>>")))
;; 2. Fuzzy link should then go to a matching target keyword.
(org-test-with-temp-text
"#+NAME: Test\n|a|b|\n#+TARGET: Test\n* Test\n[[Test]]"
(goto-line 5)
(org-open-at-point)
(should (looking-at "#\\+TARGET: Test")))
;; 3. Then fuzzy link points to an element with a given name.
(org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
(goto-line 5)
(org-open-at-point)
(should (looking-at "#\\+NAME: Test")))
;; 4. A target still lead to a matching headline otherwise.
(org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
(goto-line 4)
(org-open-at-point)
(should (looking-at "\\* Head2")))
;; 5. With a leading star in link, enforce heading match.
(org-test-with-temp-text "#+TARGET: Test\n* Test\n<<Test>>\n[[*Test]]"
(goto-line 4)
(org-open-at-point)
(should (looking-at "\\* Test"))))
(should
(org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
(goto-line 5)
(org-open-at-point)
(looking-at "<<Test>>")))
;; 2. Then fuzzy link points to an element with a given name.
(should
(org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
(goto-line 5)
(org-open-at-point)
(looking-at "#\\+NAME: Test")))
;; 3. A target still lead to a matching headline otherwise.
(should
(org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
(goto-line 4)
(org-open-at-point)
(looking-at "\\* Head2")))
;; 4. With a leading star in link, enforce heading match.
(should
(org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
(goto-line 3)
(org-open-at-point)
(looking-at "\\* Test"))))
;;;; Link Escaping

View File

@ -1348,15 +1348,7 @@ Paragraph[fn:1]"
(ert-deftest test-org-export/fuzzy-link ()
"Test fuzzy links specifications."
;; 1. Links to invisible (keyword) targets should be ignored.
(org-test-with-parsed-data
"Paragraph.\n#+TARGET: Test\n[[Test]]"
(should-not
(org-element-map tree 'link
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info)))
;; 2. Link to an headline should return headline's number.
;; Link to an headline should return headline's number.
(org-test-with-parsed-data
"Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
(should
@ -1366,7 +1358,7 @@ Paragraph[fn:1]"
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info t))))
;; 3. Link to a target in an item should return item's number.
;; Link to a target in an item should return item's number.
(org-test-with-parsed-data
"- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
(should
@ -1376,8 +1368,7 @@ Paragraph[fn:1]"
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info t))))
;; 4. Link to a target in a footnote should return footnote's
;; number.
;; Link to a target in a footnote should return footnote's number.
(org-test-with-parsed-data "
Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
(should
@ -1386,8 +1377,8 @@ Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info))))
;; 5. Link to a named element should return sequence number of that
;; element.
;; Link to a named element should return sequence number of that
;; element.
(org-test-with-parsed-data
"#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
(should
@ -1396,8 +1387,8 @@ Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info t))))
;; 6. Link to a target not within an item, a table, a footnote
;; reference or definition should return section number.
;; Link to a target not within an item, a table, a footnote
;; reference or definition should return section number.
(org-test-with-parsed-data
"* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
(should
@ -1406,13 +1397,13 @@ Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info t))))
;; 7. Space are not significant when matching a fuzzy link.
;; Space are not significant when matching a fuzzy link.
(should
(org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
(org-element-map tree 'link
(lambda (link) (org-export-resolve-fuzzy-link link info))
info t)))
;; 8. Statistics cookies are ignored for headline match.
;; Statistics cookies are ignored for headline match.
(should
(org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
(org-element-map tree 'link
@ -1491,55 +1482,50 @@ Another text. (ref:text)
(ert-deftest test-org-export/resolve-fuzzy-link ()
"Test `org-export-resolve-fuzzy-link' specifications."
;; 1. Match target objects.
(org-test-with-parsed-data "<<target>> [[target]]"
(should
;; Match target objects.
(should
(org-test-with-parsed-data "<<target>> [[target]]"
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))
;; 2. Match target elements.
(org-test-with-parsed-data "#+TARGET: target\n[[target]]"
(should
;; Match named elements.
(should
(org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))
;; 3. Match named elements.
(org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
(should
;; Match exact headline's name.
(should
(org-test-with-parsed-data "* My headline\n[[My headline]]"
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))
;; 4. Match exact headline's name.
(org-test-with-parsed-data "* My headline\n[[My headline]]"
(should
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))
;; 5. Targets objects have priority over named elements and headline
;; titles.
(org-test-with-parsed-data
"* target\n#+NAME: target\n<<target>>\n\n[[target]]"
(should
(eq 'target
;; Targets objects have priority over named elements and headline
;; titles.
(should
(eq 'target
(org-test-with-parsed-data
"* target\n#+NAME: target\n<<target>>\n\n[[target]]"
(org-element-type
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))))
;; 6. Named elements have priority over headline titles.
(org-test-with-parsed-data
"* target\n#+NAME: target\nParagraph\n\n[[target]]"
(should
(eq 'paragraph
;; Named elements have priority over headline titles.
(should
(eq 'paragraph
(org-test-with-parsed-data
"* target\n#+NAME: target\nParagraph\n\n[[target]]"
(org-element-type
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))))
;; 7. If link's path starts with a "*", only match headline titles,
;; though.
(org-test-with-parsed-data
"* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
(should
(eq 'headline
;; If link's path starts with a "*", only match headline titles,
;; though.
(should
(eq 'headline
(org-test-with-parsed-data
"* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
(org-element-type
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))))
;; 8. Return nil if no match.
(org-test-with-parsed-data "[[target]]"
(should-not
;; Return nil if no match.
(should-not
(org-test-with-parsed-data "[[target]]"
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info))))