Browse Source

Addendum to 50a434bb9faa23396c2619031bd07a2fa2d30d0b

* lisp/org-element.el (org-element-item-parser): Do not remove tag
  from body if list isn't descriptive.
* lisp/org-list.el (org-insert-item): Only ask about a term for
  descriptive lists.
(org-list-struct, org-list-insert-item): Do not recognize a tag in an
ordered list.
* testing/lisp/test-org-element.el: Add test.
Nicolas Goaziou 12 years ago
parent
commit
ad94a9433b
3 changed files with 56 additions and 30 deletions
  1. 25 20
      lisp/org-element.el
  2. 25 10
      lisp/org-list.el
  3. 6 0
      testing/lisp/test-org-element.el

+ 25 - 20
lisp/org-element.el

@@ -984,34 +984,39 @@ string instead.
 Assume point is at the beginning of the item."
   (save-excursion
     (beginning-of-line)
+    (looking-at org-list-full-item-re)
     (let* ((begin (point))
-	   (bullet (org-list-get-bullet (point) struct))
-	   (checkbox (let ((box (org-list-get-checkbox begin struct)))
+	   (bullet (org-match-string-no-properties 1))
+	   (checkbox (let ((box (org-match-string-no-properties 3)))
 		       (cond ((equal "[ ]" box) 'off)
 			     ((equal "[X]" box) 'on)
 			     ((equal "[-]" box) 'trans))))
-	   (counter (let ((c (org-list-get-counter begin struct)))
-		      (cond
-		       ((not c) nil)
-		       ((string-match "[A-Za-z]" c)
-			(- (string-to-char (upcase (match-string 0 c)))
-			   64))
-		       ((string-match "[0-9]+" c)
-			(string-to-number (match-string 0 c))))))
+	   (counter (let ((c (org-match-string-no-properties 2)))
+		      (save-match-data
+			(cond
+			 ((not c) nil)
+			 ((string-match "[A-Za-z]" c)
+			  (- (string-to-char (upcase (match-string 0 c)))
+			     64))
+			 ((string-match "[0-9]+" c)
+			  (string-to-number (match-string 0 c)))))))
 	   (end (save-excursion (goto-char (org-list-get-item-end begin struct))
 				(unless (bolp) (forward-line))
 				(point)))
-	   (contents-begin (progn (looking-at org-list-full-item-re)
-				  (goto-char (match-end 0))
-				  (skip-chars-forward " \r\t\n" limit)
-				  ;; If first line isn't empty,
-				  ;; contents really start at the text
-				  ;; after item's meta-data.
-				  (if (= (point-at-bol) begin) (point)
-				    (point-at-bol))))
+	   (contents-begin
+	    (progn (goto-char
+		    ;; Ignore tags in un-ordered lists: they are just
+		    ;; a part of item's body.
+		    (if (and (match-beginning 4)
+			     (save-match-data (string-match "[.)]" bullet)))
+			(match-beginning 4)
+		      (match-end 0)))
+		   (skip-chars-forward " \r\t\n" limit)
+		   ;; If first line isn't empty, contents really start
+		   ;; at the text after item's meta-data.
+		   (if (= (point-at-bol) begin) (point) (point-at-bol))))
 	   (hidden (progn (forward-line)
-			  (and (not (= (point) end))
-			       (org-invisible-p2))))
+			  (and (not (= (point) end)) (org-invisible-p2))))
 	   (contents-end (progn (goto-char end)
 				(skip-chars-backward " \r\t\n")
 				(forward-line)

+ 25 - 10
lisp/org-list.el

@@ -621,12 +621,15 @@ Assume point is at an item."
 	     ;; Return association at point.
 	     (lambda (ind)
 	       (looking-at org-list-full-item-re)
-	       (list (point)
-		     ind
-		     (match-string-no-properties 1)	; bullet
-		     (match-string-no-properties 2)	; counter
-		     (match-string-no-properties 3)	; checkbox
-		     (match-string-no-properties 4)))))	; description tag
+	       (let ((bullet (match-string-no-properties 1)))
+		 (list (point)
+		       ind
+		       bullet
+		       (match-string-no-properties 2) ; counter
+		       (match-string-no-properties 3) ; checkbox
+		       ;; Description tag.
+		       (and (save-match-data (string-match "[-+*]" bullet))
+			    (match-string-no-properties 4)))))))
 	   (end-before-blank
 	    (function
 	     ;; Ensure list ends at the first blank line.
@@ -1253,8 +1256,15 @@ This function modifies STRUCT."
     (let* ((item (progn (goto-char pos) (goto-char (org-list-get-item-begin))))
 	   (item-end (org-list-get-item-end item struct))
 	   (item-end-no-blank (org-list-get-item-end-before-blank item struct))
-	   (beforep (and (looking-at org-list-full-item-re)
-			 (<= pos (match-end 0))))
+	   (beforep
+	    (progn
+	      (looking-at org-list-full-item-re)
+	      ;; Do not count tag in a non-descriptive list.
+	      (<= pos (if (and (match-beginning 4)
+			       (save-match-data
+				 (string-match "[.)]" (match-string 1))))
+			  (match-beginning 4)
+			(match-end 0)))))
 	   (split-line-p (org-get-alist-option org-M-RET-may-split-line 'item))
 	   (blank-nb (org-list-separating-blank-lines-number
 		      pos struct prevs))
@@ -2187,14 +2197,19 @@ item is invisible."
 				       (org-list-struct)))
 	       (prevs (org-list-prevs-alist struct))
 	       ;; If we're in a description list, ask for the new term.
-	       (desc (when (org-list-get-tag itemp struct)
+	       (desc (when (eq (org-list-get-list-type itemp struct prevs)
+			       'descriptive)
 		       (concat (read-string "Term: ") " :: "))))
 	  (setq struct
 		(org-list-insert-item pos struct prevs checkbox desc))
 	  (org-list-write-struct struct (org-list-parents-alist struct))
 	  (when checkbox (org-update-checkbox-count-maybe))
 	  (looking-at org-list-full-item-re)
-	  (goto-char (match-end 0))
+	  (goto-char (if (and (match-beginning 4)
+			      (save-match-data
+				(string-match "[.)]" (match-string 1))))
+			 (match-beginning 4)
+		       (match-end 0)))
 	  t)))))
 
 (defun org-list-repair ()

+ 6 - 0
testing/lisp/test-org-element.el

@@ -890,6 +890,12 @@ DEADLINE: <2012-03-29 thu.>"
      :tag
      (org-test-with-temp-text "- tag :: description"
        (org-element-map (org-element-parse-buffer) 'item 'identity nil t)))))
+  ;; No tags in ordered lists.
+  (should-not
+   (org-element-property
+    :tag
+    (org-test-with-temp-text "1. tag :: description"
+      (org-element-map (org-element-parse-buffer) 'item 'identity nil t))))
   ;; Check-boxes
   (should
    (equal