emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Rudolf Adamkovič" <rudolf@adamkovic.org>
To: emacs-orgmode@gnu.org
Cc: Rudolf Adamkovic <rudolf@adamkovic.org>
Subject: [PATCH] ox-texinfo: Support numeric values of `toc' in `#+OPTIONS'
Date: Sat, 31 Aug 2024 22:34:49 +0200	[thread overview]
Message-ID: <20240831203449.31407-1-rudolf@adamkovic.org> (raw)

From: Rudolf Adamkovic <rudolf@adamkovic.org>

* etc/ORG-NEWS (Texinfo exporter now supports numeric =toc= values in
=#+OPTIONS:=): Announce the new feature.
* lisp/ox.el (org-export-excluded-from-toc-p): Return nil for all
headlines that are above the `toc' value in export `#+OPTIONS'.
* testing/lisp/test-ox-texinfo.el
(test-ox-texinfo/headings-and-table-of-contents): Add a test.
---
 etc/ORG-NEWS                    | 12 ++++++
 lisp/ox.el                      |  6 ++-
 testing/lisp/test-ox-texinfo.el | 66 +++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 392788055..f93776754 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -77,6 +77,18 @@ You can now create links to =shortdoc= documentation groups for Emacs
 Lisp functions (see =M-x shortdoc-display-group=).  Requires Emacs 28
 or newer.
 
+<<<<<<< HEAD
+=======
+*** Texinfo exporter now supports numeric =toc= values in =#+OPTIONS:=
+
+For example, given =H:3= and =toc:2= in =#+OPTIONS:=, all headings at
+the 1st and 2nd level appear in the table of contents and those at the
+3rd level do not.  The latter will be instead exported as if they had
+the =UNNUMBERED= property set to =notoc=, that is using the Texinfo
+command given in the =unnumbered-no-toc-3= list position of the
+=org-texinfo-classes= variable, as documented.
+
+>>>>>>> ox-texinfo: Support numeric values of `toc' in `#+OPTIONS'
 ** New and changed options
 
 # Chanes deadling with changing default values of customizations,
diff --git a/lisp/ox.el b/lisp/ox.el
index 7a0ab4dc7..acc535f72 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -5625,7 +5625,11 @@ contents.  However, it is useful if some additional processing is
 required on headlines excluded from table of contents."
   (or (org-element-property :footnote-section-p headline)
       (org-export-low-level-p headline info)
-      (equal "notoc" (org-export-get-node-property :UNNUMBERED headline t))))
+      (equal "notoc" (org-export-get-node-property :UNNUMBERED headline t))
+      (let ((toc-depth (plist-get info :with-toc)))
+        (and (wholenump toc-depth)
+             (> (org-element-property :level headline)
+                toc-depth)))))
 
 (defun org-export-toc-entry-backend (parent &rest transcoders)
   "Return an export backend appropriate for table of contents entries.
diff --git a/testing/lisp/test-ox-texinfo.el b/testing/lisp/test-ox-texinfo.el
index b16a344e7..e2bacd4d9 100644
--- a/testing/lisp/test-ox-texinfo.el
+++ b/testing/lisp/test-ox-texinfo.el
@@ -345,5 +345,71 @@ body
        (should-not (org-element-contents section))
        (should (eq first-heading (org-element-parent section)))))))
 
+\f
+;;; Headings and table of contents
+
+(ert-deftest test-ox-texinfo/headings-and-table-of-contents ()
+  "Test headings with regards to table of contents."
+  (should
+   (org-test-with-temp-text
+       (string-join
+        (list "#+OPTIONS: h:2 toc:1 num:nil"
+              "* Level 1"
+              "** Level 1-1"
+              "*** Level 1-1-1"
+              "*** Level 1-1-2"
+              "** Level 1-2"
+              "*** Level 1-2-1"
+              "*** Level 1-2-2"
+              "* Level 2"
+              "** Level 2-1"
+              "*** Level 2-1-1"
+              "*** Level 2-1-2"
+              "** Level 2-2"
+              "*** Level 2-2-1"
+              "*** Level 2-2-2")
+        "\n")
+     (let ((export-buffer "*Test Texinfo Export*")
+           (org-export-show-temporary-export-buffer nil))
+       (org-export-to-buffer 'texinfo export-buffer
+         nil nil nil nil nil
+         #'texinfo-mode)
+       (with-current-buffer export-buffer
+         (goto-char (point-min))
+         (and
+          (re-search-forward "^@menu$")
+          (re-search-forward "^* Level 1::$")
+          (re-search-forward "^* Level 2::$")
+          (re-search-forward "^@detailmenu$")
+          (re-search-forward "^Level 1$")
+          (re-search-forward "^* Level 1-1::$")
+          (re-search-forward "^* Level 1-2::$")
+          (re-search-forward "^Level 2$")
+          (re-search-forward "^* Level 2-1::$")
+          (re-search-forward "^* Level 2-2::$")
+          (re-search-forward "^@node Level 1$")
+          (re-search-forward "^@unnumbered Level 1$")
+          (re-search-forward "^@menu$")
+          (re-search-forward "^* Level 1-1::$")
+          (re-search-forward "^* Level 1-2::$")
+          (re-search-forward "^@heading Level 1-1$")
+          (re-search-forward "^@anchor{Level 1-1-1}Level 1-1-1$")
+          (re-search-forward "^@anchor{Level 1-1-2}Level 1-1-2$")
+          (re-search-forward "^@heading Level 1-2$")
+          (re-search-forward "^@anchor{Level 1-2-1}Level 1-2-1$")
+          (re-search-forward "^@anchor{Level 1-2-2}Level 1-2-2$")
+          (re-search-forward "^@node Level 2$")
+          (re-search-forward "^@unnumbered Level 2$")
+          (re-search-forward "^@menu$")
+          (re-search-forward "^* Level 2-1::$")
+          (re-search-forward "^* Level 2-2::$")
+          (re-search-forward "^@heading Level 2-1$")
+          (re-search-forward "^@anchor{Level 2-1-1}Level 2-1-1$")
+          (re-search-forward "^@anchor{Level 2-1-2}Level 2-1-2$")
+          (re-search-forward "^@anchor{Level 2-2}$")
+          (re-search-forward "^@heading Level 2-2$")
+          (re-search-forward "^@anchor{Level 2-2-1}Level 2-2-1$")
+          (re-search-forward "^@anchor{Level 2-2-2}Level 2-2-2$")))))))
+
 (provide 'test-ox-texinfo)
 ;;; test-ox-texinfo.el end here
-- 
2.46.0



             reply	other threads:[~2024-08-31 20:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-31 20:34 Rudolf Adamkovič [this message]
2024-09-01 16:52 ` [PATCH] ox-texinfo: Support numeric values of `toc' in `#+OPTIONS' Ihor Radchenko
2024-09-03 22:29   ` Rudolf Adamkovič
2024-09-09 17:57     ` Ihor Radchenko
2024-09-11 22:33       ` Rudolf Adamkovič
2024-09-15 12:16         ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240831203449.31407-1-rudolf@adamkovic.org \
    --to=rudolf@adamkovic.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).