Browse Source

org-element: Fix parsing of syntax at beginning of item

* lisp/org-element.el (org-element-sub/superscript-successor): Fix
  parsing of sub/superscript at beginning of item.
(org-element-latex-or-entity-successor): Fix parsing of latex
  fragments at beginning of item.
* testing/lisp/test-org-element.el: Add test.
Nicolas Goaziou 12 years ago
parent
commit
c65abd8577
2 changed files with 23 additions and 3 deletions
  1. 2 0
      lisp/org-element.el
  2. 21 3
      testing/lisp/test-org-element.el

+ 2 - 0
lisp/org-element.el

@@ -2412,6 +2412,7 @@ LIMIT bounds the search.
 Return value is a cons cell whose CAR is `entity' or
 `latex-fragment' and CDR is beginning position."
   (save-excursion
+    (unless (bolp) (backward-char))
     (let ((matchers
 	   (remove "begin" (plist-get org-format-latex-options :matchers)))
 	  ;; ENTITY-RE matches both LaTeX commands and Org entities.
@@ -3089,6 +3090,7 @@ LIMIT bounds the search.
 Return value is a cons cell whose CAR is either `subscript' or
 `superscript' and CDR is beginning position."
   (save-excursion
+    (unless (bolp) (backward-char))
     (when (re-search-forward org-match-substring-regexp limit t)
       (cons (if (string= (match-string 2) "_") 'subscript 'superscript)
 	    (match-beginning 2)))))

+ 21 - 3
testing/lisp/test-org-element.el

@@ -1074,7 +1074,13 @@ e^{i\\pi}+1=0
     (should
      (org-test-with-temp-text "\\[a\\]"
        (org-element-map
-	(org-element-parse-buffer) 'latex-fragment 'identity)))))
+	(org-element-parse-buffer) 'latex-fragment 'identity)))
+    ;; Test fragment at the beginning of an item.
+    (should
+     (eq 'latex-fragment
+	 (org-test-with-temp-text "- $x$"
+	   (progn (search-forward "$")
+		  (org-element-type (org-element-context))))))))
 
 
 ;;;; Line Break
@@ -1511,7 +1517,13 @@ Outside list"
   ;; With braces.
   (should
    (org-test-with-temp-text "a_{b}"
-     (org-element-map (org-element-parse-buffer) 'subscript 'identity))))
+     (org-element-map (org-element-parse-buffer) 'subscript 'identity)))
+  ;; At the beginning of an item.
+  (should
+   (eq 'subscript
+       (org-test-with-temp-text "- _b"
+	 (progn (search-forward "_")
+		(org-element-type (org-element-context)))))))
 
 
 ;;;; Superscript
@@ -1525,7 +1537,13 @@ Outside list"
   ;; With braces.
   (should
    (org-test-with-temp-text "a^{b}"
-     (org-element-map (org-element-parse-buffer) 'superscript 'identity))))
+     (org-element-map (org-element-parse-buffer) 'superscript 'identity)))
+  ;; At the beginning of an item.
+  (should
+   (eq 'superscript
+       (org-test-with-temp-text "- ^b"
+	 (progn (search-forward "^")
+		(org-element-type (org-element-context)))))))
 
 
 ;;;; Table