1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-26 07:33:39 +00:00

org-e-ascii: Get item number right

* EXPERIMENTAL/org-e-ascii.el (org-e-ascii-item): Use new
  `org-list-get-item-number' function.
* contrib/lisp/org-element.el (org-element-item-interpreter): Use new
  `org-list-get-item-number' function.
This commit is contained in:
Nicolas Goaziou 2012-02-20 17:15:04 +01:00
parent f07929f5f1
commit abaeb42a3a
2 changed files with 47 additions and 21 deletions

View File

@ -1287,22 +1287,37 @@ contextual information."
(let ((bullet (let ((bullet
;; First parent of ITEM is always the plain-list. Get ;; First parent of ITEM is always the plain-list. Get
;; `:type' property from it. ;; `:type' property from it.
(let ((type (org-element-get-property (org-list-bullet-string
:type (car (plist-get info :genealogy))))) (let ((type (org-element-get-property
(if (eq type 'descriptive) :type (car (plist-get info :genealogy)))))
(concat (cond
(org-export-secondary-string ((eq type 'descriptive)
(org-element-get-property :tag item) 'e-ascii info) ": ") (concat
(org-element-get-property :bullet item))))) (org-export-secondary-string
(org-element-get-property :tag item) 'e-ascii info) ": "))
((eq type 'ordered)
;; Return correct number for ITEM, paying attention to
;; counters.
(let* ((struct (org-element-get-property :structure item))
(bul (org-element-get-property :bullet item))
(num
(number-to-string
(car (last (org-list-get-item-number
(org-element-get-property :begin item)
struct
(org-list-prevs-alist struct)
(org-list-parents-alist struct)))))))
(replace-regexp-in-string "[0-9]+" num bul)))
(t (let ((bul (org-element-get-property :bullet item)))
;; Change bullets into more visible form if UTF-8 is active.
(if (not (eq (plist-get info :ascii-charset) 'utf-8)) bul
(replace-regexp-in-string
"-" ""
(replace-regexp-in-string
"+" ""
(replace-regexp-in-string "*" "" bul)))))))))))
(concat (concat
;; Change bullets into more visible form if UTF-8 is active. bullet
(if (not (eq (plist-get info :ascii-charset) 'utf-8)) bullet
(replace-regexp-in-string
"-" ""
(replace-regexp-in-string
"+" ""
(replace-regexp-in-string
"*" "" bullet))))
;; Contents: Pay attention to indentation. Note: check-boxes are ;; Contents: Pay attention to indentation. Note: check-boxes are
;; already taken care of at the paragraph level so they don't ;; already taken care of at the paragraph level so they don't
;; interfere with indentation. ;; interfere with indentation.

View File

@ -621,7 +621,22 @@ Assume point is at the beginning of the item."
(defun org-element-item-interpreter (item contents) (defun org-element-item-interpreter (item contents)
"Interpret ITEM element as Org syntax. "Interpret ITEM element as Org syntax.
CONTENTS is the contents of the element." CONTENTS is the contents of the element."
(let* ((bullet (org-element-get-property :bullet item)) (let* ((bullet
(let* ((beg (org-element-get-property :begin item))
(struct (org-element-get-property :structure item))
(pre (org-list-prevs-alist struct))
(bul (org-element-get-property :bullet item)))
(org-list-bullet-string
(if (not (eq (org-list-get-list-type beg struct pre) 'ordered)) "-"
(let ((num
(car
(last
(org-list-get-item-number
beg struct pre (org-list-parents-alist struct))))))
(format "%d%s"
num
(if (eq org-plain-list-ordered-item-terminator ?\)) ")"
".")))))))
(checkbox (org-element-get-property :checkbox item)) (checkbox (org-element-get-property :checkbox item))
(counter (org-element-get-property :counter item)) (counter (org-element-get-property :counter item))
(tag (org-element-get-property :raw-tag item)) (tag (org-element-get-property :raw-tag item))
@ -630,9 +645,6 @@ CONTENTS is the contents of the element."
;; Indent contents. ;; Indent contents.
(concat (concat
bullet bullet
(when (and org-list-two-spaces-after-bullet-regexp
(string-match org-list-two-spaces-after-bullet-regexp bullet))
" ")
(and counter (format "[@%d] " counter)) (and counter (format "[@%d] " counter))
(cond (cond
((eq checkbox 'on) "[X] ") ((eq checkbox 'on) "[X] ")
@ -640,8 +652,7 @@ CONTENTS is the contents of the element."
((eq checkbox 'trans) "[-] ")) ((eq checkbox 'trans) "[-] "))
(and tag (format "%s :: " tag)) (and tag (format "%s :: " tag))
(org-trim (org-trim
(replace-regexp-in-string (replace-regexp-in-string "\\(^\\)[ \t]*\\S-" ind contents nil nil 1)))))
"\\(^\\)[ \t]*\\S-" ind contents nil nil 1)))))
;;;; Plain List ;;;; Plain List