From 73c5044963a44870483dbce6640ec549e72086ac Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Wed, 29 Feb 2012 19:05:45 +0100 Subject: [PATCH] org-export: Add `org-export-headline-numbered-p' predicate * contrib/lisp/org-export.el (org-export-numbered-headline-p): New function. * EXPERIMENTAL/org-e-ascii.el: Apply new function. * EXPERIMENTAL/org-e-latex.el: Apply new function. * testing/lisp/test-org-export.el: Add a test. --- EXPERIMENTAL/org-e-ascii.el | 7 +------ EXPERIMENTAL/org-e-latex.el | 22 ++++++++++------------ contrib/lisp/org-export.el | 7 +++++++ testing/lisp/test-org-export.el | 15 +++++++-------- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/EXPERIMENTAL/org-e-ascii.el b/EXPERIMENTAL/org-e-ascii.el index 0eb547b9b..5a2b0c2dc 100644 --- a/EXPERIMENTAL/org-e-ascii.el +++ b/EXPERIMENTAL/org-e-ascii.el @@ -585,12 +585,7 @@ title." (let* ((headlinep (eq (org-element-type element) 'headline)) (numbers ;; Numbering is specific to headlines. - (and headlinep - ;; Section numbering must be active, and headline's - ;; level should be above specified limit, if any. - (let ((sec-num (plist-get info :section-numbers))) - (if (not (wholenump sec-num)) sec-num - (<= (org-export-get-relative-level headline info) sec-num))) + (and headlinep (org-export-numbered-headline-p element info) ;; All tests passed: build numbering string. (concat (mapconcat diff --git a/EXPERIMENTAL/org-e-latex.el b/EXPERIMENTAL/org-e-latex.el index 9b61407f3..11f8afbfa 100644 --- a/EXPERIMENTAL/org-e-latex.el +++ b/EXPERIMENTAL/org-e-latex.el @@ -1072,8 +1072,7 @@ CONTENTS holds the contents of the headline. INFO is a plist holding contextual information." (let* ((class (plist-get info :latex-class)) (level (org-export-get-relative-level headline info)) - (numberedp (let ((sec-num (plist-get info :section-numbers))) - (if (wholenump sec-num) (<= level sec-num) sec-num))) + (numberedp (org-export-numbered-headline-p headline info)) (class-sectionning (assoc class org-e-latex-classes)) ;; Section formatting will set two placeholders: one for the ;; title and the other for the contents. @@ -1095,8 +1094,7 @@ holding contextual information." (when numberedp (concat (car sec) "\n%s" (nth 1 sec)))) ;; (num-in num-out no-num-in no-num-out) ((= (length sec) 4) - (if numberedp - (concat (car sec) "\n%s" (nth 1 sec)) + (if numberedp (concat (car sec) "\n%s" (nth 1 sec)) (concat (nth 2 sec) "\n%s" (nth 3 sec))))))) (text (org-export-secondary-string (org-element-property :title headline) 'e-latex info)) @@ -1144,14 +1142,14 @@ holding contextual information." (format "\\begin{%s}\n" (if numberedp 'enumerate 'itemize))) ;; Itemize headline "\\item " full-text "\n" headline-label pre-blanks contents))) - ;; If headline in the last sibling, close the list, before any - ;; blank line. Otherwise, simply return LOW-LEVEL-BODY. - (if (org-export-last-sibling-p headline info) - (replace-regexp-in-string - "[ \t\n]*\\'" - (format "\n\\\\end{%s}" (if numberedp 'enumerate 'itemize)) - low-level-body) - low-level-body))) + ;; If headline is not the last sibling simply return + ;; LOW-LEVEL-BODY. Otherwise, also close the list, before any + ;; blank line. + (if (not (org-export-last-sibling-p headline info)) low-level-body + (replace-regexp-in-string + "[ \t\n]*\\'" + (format "\n\\\\end{%s}" (if numberedp 'enumerate 'itemize)) + low-level-body)))) ;; Case 3. Standard headline. Export it as a section. (t (format section-fmt full-text (concat headline-label pre-blanks contents)))))) diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el index b8097584e..6d6b3fb94 100644 --- a/contrib/lisp/org-export.el +++ b/contrib/lisp/org-export.el @@ -2601,6 +2601,13 @@ and the last level being considered as high enough, or nil." INFO is a plist holding contextual information." (cdr (assoc headline (plist-get info :headline-numbering)))) +(defun org-export-numbered-headline-p (headline info) + "Return a non-nil value if HEADLINE element should be numbered. +INFO is a plist used as a communication channel." + (let ((sec-num (plist-get info :section-numbers)) + (level (org-export-get-relative-level headline info))) + (if (wholenump sec-num) (<= level sec-num) sec-num))) + (defun org-export-number-to-roman (n) "Convert integer N into a roman numeral." (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD") diff --git a/testing/lisp/test-org-export.el b/testing/lisp/test-org-export.el index faa277375..cc04cb912 100644 --- a/testing/lisp/test-org-export.el +++ b/testing/lisp/test-org-export.el @@ -57,11 +57,12 @@ as Org syntax." (equal (org-export-parse-option-keyword "arch:headline creator:comment d:(\"TEST\") - ^:{} toc:1 tags:not-in-toc tasks:todo") - '(:with-archived-trees - headline :with-creator comment :with-drawers ("TEST") - :with-sub-superscript {} :with-toc 1 :with-tags not-in-toc - :with-tasks todo)))) + ^:{} toc:1 tags:not-in-toc tasks:todo num:2") + '( :section-numbers + 2 + :with-archived-trees headline :with-creator comment + :with-drawers ("TEST") :with-sub-superscript {} :with-toc 1 + :with-tags not-in-toc :with-tasks todo)))) (ert-deftest test-org-export/get-inbuffer-options () "Test reading all standard export keywords." @@ -253,9 +254,7 @@ text (should (equal (buffer-string) "Small Org file with an include keyword. -#+BEGIN_SRC emacs-lisp :exports results -(+ 2 1) -#+END_SRC +#+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC Success! -- 2.11.4.GIT