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)) (et (org-element-type ee))
(ev (plist-get (cadr ee) :value)) (ev (plist-get (cadr ee) :value))
(ek (plist-get (cadr ee) :key)) (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 (setq txt (cond
((org-at-heading-p) nil) ((org-at-heading-p) nil)
((and (eq et 'keyword) eok) ev) ((and (eq et 'keyword) eok) ev)
@ -10630,14 +10630,6 @@ visibility around point, thus ignoring
pos (match-beginning 0)))) pos (match-beginning 0))))
;; There is an exact target for this ;; There is an exact target for this
(goto-char pos)) (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 ((save-excursion
(goto-char (point-min)) (goto-char (point-min))
(and (and
@ -11871,7 +11863,7 @@ keywords relative to each registered export back-end."
"DESCRIPTION:" "DRAWERS:" "EMAIL:" "EXCLUDE_TAGS:" "FILETAGS:" "INCLUDE:" "DESCRIPTION:" "DRAWERS:" "EMAIL:" "EXCLUDE_TAGS:" "FILETAGS:" "INCLUDE:"
"INDEX:" "KEYWORDS:" "LANGUAGE:" "MACRO:" "OPTIONS:" "PROPERTY:" "INDEX:" "KEYWORDS:" "LANGUAGE:" "MACRO:" "OPTIONS:" "PROPERTY:"
"PRIORITIES:" "SELECT_TAGS:" "SEQ_TODO:" "SETUPFILE:" "STARTUP:" "TAGS:" "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 (defcustom org-structure-template-alist
'(("s" "#+BEGIN_SRC ?\n\n#+END_SRC" '(("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: Return value can be an object, an element, or nil:
- If LINK path matches a target object (i.e. <<path>>) or - If LINK path matches a target object (i.e. <<path>>) return it.
element (i.e. \"#+TARGET: path\"), return it.
- If LINK path exactly matches the name affiliated keyword - If LINK path exactly matches the name affiliated keyword
\(i.e. #+NAME: path) of an element, return that element. \(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)))) (if match-title-p (substring raw-path 1) raw-path))))
(cond (cond
;; First try to find a matching "<<path>>" unless user specified ;; 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). ;; character).
((and (not match-title-p) ((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) (lambda (blob)
(and (or (eq (org-element-type blob) 'target) (and (equal (org-split-string (org-element-property :value blob))
(equal (org-element-property :key blob) "TARGET"))
(equal (org-split-string (org-element-property :value blob))
path) path)
blob)) blob))
info t))) info t)))
@ -3851,10 +3848,10 @@ significant."
(let ((name (org-element-property :name el))) (let ((name (org-element-property :name el)))
(when (and name (equal (org-split-string name) path)) el))) (when (and name (equal (org-split-string name) path)) el)))
info 'first-match))) info 'first-match)))
;; Last case: link either points to a headline or to ;; Last case: link either points to a headline or to nothingness.
;; nothingness. Try to find the source, with priority given to ;; Try to find the source, with priority given to headlines with
;; headlines with the closest common ancestor. If such candidate ;; the closest common ancestor. If such candidate is found,
;; is found, return it, otherwise return nil. ;; return it, otherwise return nil.
(t (t
(let ((find-headline (let ((find-headline
(function (function
@ -3946,9 +3943,6 @@ a target, return the same value as if ELEMENT was the closest
table, item or headline containing the target. In any other table, item or headline containing the target. In any other
case, return the sequence number of ELEMENT among elements or case, return the sequence number of ELEMENT among elements or
objects of the same type." 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 ;; Ordinal of a target object refer to the ordinal of the closest
;; table, item, or headline containing the object. ;; table, item, or headline containing the object.
(when (eq (org-element-type element) 'target) (when (eq (org-element-type element) 'target)
@ -3982,7 +3976,7 @@ objects of the same type."
((eq element el) (1+ counter)) ((eq element el) (1+ counter))
((not predicate) (incf counter) nil) ((not predicate) (incf counter) nil)
((funcall predicate el info) (incf counter) nil))) ((funcall predicate el info) (incf counter) nil)))
info 'first-match)))))) info 'first-match)))))
;;;; For Src-Blocks ;;;; For Src-Blocks

View File

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

View File

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