Browse Source

org-list: new accessor returning type of list

* lisp/org-list.el (org-list-get-list-type): new function.
(org-list-parse-list): use new function.
* lisp/org-html.el (org-html-export-list-line): use new function.
* lisp/org-docbook.el (org-export-docbook-list-line): use new function.
Nicolas Goaziou 14 years ago
parent
commit
cddea8c542
3 changed files with 36 additions and 31 deletions
  1. 10 10
      lisp/org-docbook.el
  2. 10 10
      lisp/org-html.el
  3. 16 11
      lisp/org-list.el

+ 10 - 10
lisp/org-docbook.el

@@ -1337,14 +1337,14 @@ modifications to buffer. STRUCT is the list structure. PREVS is
 the alist of previous items."
   (let* ((get-type
 	  (function
-	   ;; Return type of list containing element POS, among
-	   ;; "ordered", "variable" or "itemized".
-	   (lambda (pos)
-	     (cond
-	      ((string-match "[[:alnum:]]" (org-list-get-bullet pos struct))
-	       "ordered")
-	      ((org-list-get-tag pos struct) "variable")
-	      (t "itemized")))))
+	   ;; Translate type of list containing POS to "ordered",
+	   ;; "variable" or "itemized".
+	   (lambda (pos struct prevs)
+	     (let ((type (org-list-get-list-type pos struct prevs)))
+	       (cond
+		((eq 'ordered type) "ordered")
+		((eq 'descriptive type) "variable")
+		(t "itemized"))))))
 	 (get-closings
 	  (function
 	   ;; Return list of all items and sublists ending at POS, in
@@ -1364,7 +1364,7 @@ the alist of previous items."
     (mapc (lambda (e)
 	    (let* ((lastp (= (org-list-get-last-item e struct prevs) e))
 		   (first-item (org-list-get-list-begin e struct prevs))
-		   (type (funcall get-type first-item)))
+		   (type (funcall get-type first-item struct prevs)))
 	      ;; Ending for every item
 	      (org-export-docbook-close-para-maybe)
 	      (insert (if (equal type "variable")
@@ -1389,7 +1389,7 @@ the alist of previous items."
 	     (firstp (= list-beg pos))
 	     ;; Always refer to first item to determine list type, in
 	     ;; case list is ill-formed.
-	     (type (funcall get-type list-beg))
+	     (type (funcall get-type list-beg struct prevs))
 	     ;; Special variables for ordered lists.
 	     (order-type (let ((bullet (org-list-get-bullet list-beg struct)))
 			   (cond

+ 10 - 10
lisp/org-html.el

@@ -2395,14 +2395,14 @@ modifications to buffer. STRUCT is the list structure. PREVS is
 the alist of previous items."
   (let* ((get-type
 	  (function
-	   ;; Return type of list containing element POS, among "d",
-	   ;; "o" or "u".
-	   (lambda (pos)
-	     (cond
-	      ((string-match "[[:alnum:]]" (org-list-get-bullet pos struct))
-	       "o")
-	      ((org-list-get-tag pos struct) "d")
-	      (t "u")))))
+	   ;; Translate type of list containing POS to "d", "o" or
+	   ;; "u".
+	   (lambda (pos struct prevs)
+	     (let ((type (org-list-get-list-type pos struct prevs)))
+	       (cond
+		((eq 'ordered type) "o")
+		((eq 'descriptive type) "d")
+		(t "u"))))))
 	 (get-closings
 	  (function
 	   ;; Return list of all items and sublists ending at POS, in
@@ -2422,7 +2422,7 @@ the alist of previous items."
     (mapc (lambda (e)
 	    (let* ((lastp (= (org-list-get-last-item e struct prevs) e))
 		   (first-item (org-list-get-list-begin e struct prevs))
-		   (type (funcall get-type first-item)))
+		   (type (funcall get-type first-item struct prevs)))
 	      (org-close-par-maybe)
 	      ;; Ending for every item
 	      (org-close-li type)
@@ -2445,7 +2445,7 @@ the alist of previous items."
 	     (firstp (= list-beg pos))
 	     ;; Always refer to first item to determine list type, in
 	     ;; case list is ill-formed.
-	     (type (funcall get-type list-beg))
+	     (type (funcall get-type list-beg struct prevs))
 	     ;; Special variables for ordered lists.
 	     (order-type (let ((bullet (org-list-get-bullet list-beg struct)))
 			   (cond

+ 16 - 11
lisp/org-list.el

@@ -1389,6 +1389,21 @@ STRUCT is the structure of the list. PREVS is the alist of
 previous items. See `org-list-struct-prev-alist'."
   (org-list-get-item-end (org-list-get-last-item item struct prevs) struct))
 
+(defun org-list-get-list-type (item struct prevs)
+  "Return the type of the list containing ITEM as a symbol.
+
+STRUCT is the structure of the list, as returned by
+`org-list-struct'. PREVS is the alist of previous items. See
+`org-list-struct-prev-alist'.
+
+Possible types are `descriptive', `ordered' and `unordered'. The
+type is determined by the first item of the list."
+  (let ((first (org-list-get-list-begin item struct prevs)))
+    (cond
+     ((org-list-get-tag first struct) 'descriptive)
+     ((string-match "[[:alnum:]]" (org-list-get-bullet first struct)) 'ordered)
+     (t 'unordered))))
+
 (defun org-list-get-nth (n key struct)
   "Return the Nth value of KEY in STRUCT."
   (nth n (assq key struct)))
@@ -2501,22 +2516,12 @@ Point is left at list end."
 	 (top (org-list-get-top-point struct))
 	 (bottom (org-list-get-bottom-point struct))
 	 out
-	 (get-list-type
-	  (function
-	   ;; determine type of list by getting info on item POS in
-	   ;; STRUCT.
-	   (lambda (pos struct)
-	     (cond ((string-match "[[:alnum:]]"
-				  (org-list-get-bullet pos struct))
-		    'ordered)
-		   ((org-list-get-tag pos struct) 'descriptive)
-		   (t 'unordered)))))
 	 (parse-sublist
 	  (function
 	   ;; return a list whose car is list type and cdr a list of
 	   ;; items' body.
 	   (lambda (e)
-	     (cons (funcall get-list-type (car e) struct)
+	     (cons (org-list-get-list-type (car e) struct prevs)
 		   (mapcar parse-item e)))))
 	 (parse-item
 	  (function