emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/toc-org 39d983c381 074/128: add noexport support


From: ELPA Syncer
Subject: [nongnu] elpa/toc-org 39d983c381 074/128: add noexport support
Date: Sun, 2 Jan 2022 09:59:10 -0500 (EST)

branch: elpa/toc-org
commit 39d983c3817b66d6a790d472448fef79b8926b92
Author: Sergei Nosov <sergei.nosov@gmail.com>
Commit: Sergei Nosov <sergei.nosov@gmail.com>

    add noexport support
---
 README.org      | 11 +++++++++++
 toc-org-test.el | 44 +++++++++++++++++++++++++++++++++++++++++++-
 toc-org.el      | 25 ++++++++++++++++++++++---
 3 files changed, 76 insertions(+), 4 deletions(-)

diff --git a/README.org b/README.org
index e5c218898e..470cd6df3a 100644
--- a/README.org
+++ b/README.org
@@ -17,6 +17,7 @@ name conflict with one of the org contrib modules.
    - [[#manual][Manual]]
  - [[#use][Use]]
    - [[#follow-links][Follow links]]
+   - [[#exclude-headings][Exclude headings]]
    - [[#shortcut-for-toc-tag][Shortcut for TOC tag]]
  - [[#different-href-styles][Different href styles]]
  - [[#example][Example]]
@@ -81,6 +82,16 @@ is not nil).
 You can manually disable this functionality by setting
 =toc-org-enable-links-opening= to nil.
 
+** Exclude headings
+
+Headings tagged with =:noexport:= will be excluded from the TOC. If you want to
+preserve the heading, but strip its children (for changelog entries, for
+example), you can tag it =:noexport_1:= (by analogy, you can use 
=:noexport_2:=,
+=:noexport_3:=, etc. for children of deeper levels). Note, though, =:noexport:=
+has a similar meaning in =org-mode=, which I hope is a Good Thing (tm). 
However,
+=:noexport_1:= and friends won't be recognized by =org-mode= as anything
+special. Look at =org-export-exclude-tags= variable for more details.
+
 ** Shortcut for TOC tag
 
 In your emacs' setup, you can bind a tag =:TOC:= to a binding =T=:
diff --git a/toc-org-test.el b/toc-org-test.el
index b9777aa24c..34eb9d7be2 100644
--- a/toc-org-test.el
+++ b/toc-org-test.el
@@ -60,7 +60,49 @@
 
   (test-toc-org-raw-toc-gold-test
    "* About\n:TOC:\n drawer\n:END:\n\n* Table of Contents                      
                               :TOC:\n - [[#about][About]]\n - [[#use][Use]]\n 
- [[#different-href-styles][Different href styles]]\n - 
[[#example][Example]]\n\n#+OPTIONS: num: nil todo:t |:t\n\n* Installation\n** 
DONE via package.el\nThis is the simplest method if you have the package.el 
module\n(built-in since Emacs 24.1) you can simply use =M-x 
package-install=\nand then put the following snippet in your ~/. [...]
-   "* About\n* Installation\n** DONE via package.el\n*** Rather 
commentious\n** No remove\n* Test ***\n"))
+   "* About\n* Installation\n** DONE via package.el\n*** Rather 
commentious\n** No remove\n* Test ***\n")
+
+  ;; test noexport behavior
+  (test-toc-org-raw-toc-gold-test
+   "* About\n:TOC:\n drawer\n:END:\n\n* Table of Contents                      
                               :TOC:\n - [[#about][About]]\n - [[#use][Use]]\n 
- [[#different-href-styles][Different href styles]]\n - 
[[#example][Example]]\n\n#+OPTIONS: num: nil todo:t |:t\n\n* Installation\n** 
DONE via package.el\nThis is the simplest method if you have the package.el 
module\n(built-in since Emacs 24.1) you can simply use =M-x 
package-install=\nand then put the following snippet in your ~/. [...]
+   "* About\n* Installation\n** DONE via package.el\n")
+
+  (test-toc-org-raw-toc-gold-test
+   "* About\n:TOC:\n drawer\n:END:\n\n* Table of Contents                      
                               :TOC:\n - [[#about][About]]\n - [[#use][Use]]\n 
- [[#different-href-styles][Different href styles]]\n - 
[[#example][Example]]\n\n#+OPTIONS: num: nil todo:t |:t\n\n* Installation\n** 
DONE via package.el\nThis is the simplest method if you have the package.el 
module\n(built-in since Emacs 24.1) you can simply use =M-x 
package-install=\nand then put the following snippet in your ~/. [...]
+   "* About\n* Installation\n** DONE via package.el\n* Rather commentious\n")
+
+  (test-toc-org-raw-toc-gold-test
+   "* About\n:TOC:\n drawer\n:END:\n\n* Table of Contents                      
                               :TOC:\n - [[#about][About]]\n - [[#use][Use]]\n 
- [[#different-href-styles][Different href styles]]\n - 
[[#example][Example]]\n\n#+OPTIONS: num: nil todo:t |:t\n\n* Installation\n** 
DONE via package.el\nThis is the simplest method if you have the package.el 
module\n(built-in since Emacs 24.1) you can simply use =M-x 
package-install=\nand then put the following snippet in your ~/. [...]
+   "* About\n* Installation\n** DONE via package.el\n* Rather commentious\n** 
No remove\n* Test\n")
+
+  (test-toc-org-raw-toc-gold-test
+   "* About\n:TOC:\n drawer\n:END:\n\n* Table of Contents                      
                               :TOC:\n - [[#about][About]]\n - [[#use][Use]]\n 
- [[#different-href-styles][Different href styles]]\n - 
[[#example][Example]]\n\n#+OPTIONS: num: nil todo:t |:t\n\n* Installation\n** 
DONE via package.el\nThis is the simplest method if you have the package.el 
module\n(built-in since Emacs 24.1) you can simply use =M-x 
package-install=\nand then put the following snippet in your ~/. [...]
+   "* About\n* Installation\n** DONE via package.el\n*** Rather 
commentious\n** No remove\n* Test\n")
+
+  (test-toc-org-raw-toc-gold-test
+   "* About\n:TOC:\n drawer\n:END:\n\n* Table of Contents                      
                               :TOC:\n - [[#about][About]]\n - [[#use][Use]]\n 
- [[#different-href-styles][Different href styles]]\n - 
[[#example][Example]]\n\n#+OPTIONS: num: nil todo:t |:t\n\n* Installation\n** 
DONE via package.el\nThis is the simplest method if you have the package.el 
module\n(built-in since Emacs 24.1) you can simply use =M-x 
package-install=\nand then put the following snippet in your ~/. [...]
+   "* About\n* Installation\n** DONE via package.el\n*** Rather 
commentious\n** No remove\n* Test ***\n")
+
+  (test-toc-org-raw-toc-gold-test
+   "* About\n:TOC:\n drawer\n:END:\n\n* Table of Contents                      
                               :TOC:\n - [[#about][About]]\n - [[#use][Use]]\n 
- [[#different-href-styles][Different href styles]]\n - 
[[#example][Example]]\n\n#+OPTIONS: num: nil todo:t |:t\n\n* Installation\n** 
DONE via package.el\nThis is the simplest method if you have the package.el 
module\n(built-in since Emacs 24.1) you can simply use =M-x 
package-install=\nand then put the following snippet in your ~/. [...]
+   "* About\n* Installation\n** DONE via package.el\n*** Rather 
commentious\n** Manual\n** No remove\n* Test ***\n")
+
+  (test-toc-org-raw-toc-gold-test
+   "* About\n:TOC:\n drawer\n:END:\n\n* Table of Contents                      
                               :TOC:\n - [[#about][About]]\n - [[#use][Use]]\n 
- [[#different-href-styles][Different href styles]]\n - 
[[#example][Example]]\n\n#+OPTIONS: num: nil todo:t |:t\n\n* Installation\n** 
DONE via package.el\nThis is the simplest method if you have the package.el 
module\n(built-in since Emacs 24.1) you can simply use =M-x 
package-install=\nand then put the following snippet in your ~/. [...]
+   "* About\n* Installation\n** DONE via package.el\n*** Rather 
commentious\n** Manual\n*** Commented\n** No remove\n* Test ***\n")
+
+  (test-toc-org-raw-toc-gold-test
+   "* About\n:TOC:\n drawer\n:END:\n\n* Table of Contents                      
                               :TOC:\n - [[#about][About]]\n - [[#use][Use]]\n 
- [[#different-href-styles][Different href styles]]\n - 
[[#example][Example]]\n\n#+OPTIONS: num: nil todo:t |:t\n\n* Installation\n** 
DONE via package.el\nThis is the simplest method if you have the package.el 
module\n(built-in since Emacs 24.1) you can simply use =M-x 
package-install=\nand then put the following snippet in your ~/. [...]
+   "* About\n* Installation\n** DONE via package.el\n*** Rather 
commentious\n** Manual\n*** Commented\n** No remove\n* Test ***\n")
+
+  (test-toc-org-raw-toc-gold-test
+   "* About\n:TOC:\n drawer\n:END:\n\n* Table of Contents                      
                               :TOC:\n - [[#about][About]]\n - [[#use][Use]]\n 
- [[#different-href-styles][Different href styles]]\n - 
[[#example][Example]]\n\n#+OPTIONS: num: nil todo:t |:t\n\n* Installation\n** 
DONE via package.el\nThis is the simplest method if you have the package.el 
module\n(built-in since Emacs 24.1) you can simply use =M-x 
package-install=\nand then put the following snippet in your ~/. [...]
+   "* About\n* Installation\n** DONE via package.el\n*** Rather 
commentious\n** Manual\n*** EWW\n** No remove\n* Test ***\n")
+
+  (test-toc-org-raw-toc-gold-test
+   "* About\n:TOC:\n drawer\n:END:\n\n* Table of Contents                      
                               :TOC:\n - [[#about][About]]\n - [[#use][Use]]\n 
- [[#different-href-styles][Different href styles]]\n - 
[[#example][Example]]\n\n#+OPTIONS: num: nil todo:t |:t\n\n* Installation\n** 
DONE via package.el\nThis is the simplest method if you have the package.el 
module\n(built-in since Emacs 24.1) you can simply use =M-x 
package-install=\nand then put the following snippet in your ~/. [...]
+   "* About\n* Installation\n** DONE via package.el\n*** Rather 
commentious\n** Manual\n*** EWW\n*** Commented\n** No remove\n* Test ***\n")
+  )
 
 (ert-deftest test-toc-org-hrefify-gh ()
   "Test the `toc-org-hrefify-gh' function"
diff --git a/toc-org.el b/toc-org.el
index 3859910c48..8ca32899be 100644
--- a/toc-org.el
+++ b/toc-org.el
@@ -54,7 +54,9 @@ files on GitHub)"
 ;; just in case, simple regexp "^*.*:toc:\\($\\|[^ ]*:$\\)"
 (defconst toc-org-toc-org-regexp 
"^*.*:toc\\([@_][0-9]\\|\\([@_][0-9][@_][a-zA-Z]+\\)\\)?:\\($\\|[^ ]*?:$\\)"
   "Regexp to find the heading with the :toc: tag")
-(defconst toc-org-tags-regexp "\s*:[[:word:]:@]*:\s*$"
+(defconst toc-org-noexport-regexp 
"\\(^*+\\)\s+.*:noexport\\([@_][0-9]\\)?:\\($\\|[^ ]*?:$\\)"
+  "Regexp to find the extended version of :noexport: tag")
+(defconst toc-org-tags-regexp "\s*:[[:word:]:@_]*:\s*$"
   "Regexp to find tags on the line")
 (defconst toc-org-states-regexp "^*+\s+\\(TODO\s+\\|DONE\s+\\)"
   "Regexp to find states on the line")
@@ -137,14 +139,31 @@ auxiliary text."
                    (delete-region (point) (min (1+ (line-end-position)) 
(point-max)))
                    (string-prefix-p skip-depth (or (current-word) ""))))))
 
+      ;; strip headings with :noexport: tag
+      (goto-char (point-min))
+      (while (re-search-forward toc-org-noexport-regexp nil t)
+        (save-excursion
+          (let* ((tag  (match-string 2))
+                 (depth (if tag (string-to-number (substring tag 1)) 0))
+                 (subheading-depth (concat (match-string 1) "*"))
+                 (skip-depth (concat subheading-depth (make-string (max (1- 
depth) 0) ?*))))
+            (if (> depth 0)
+                (forward-line)
+              (beginning-of-line)
+              (delete-region (point) (min (1+ (line-end-position)) 
(point-max))))
+            (while (string-prefix-p subheading-depth (or (current-word) ""))
+              (if (string-prefix-p skip-depth (or (current-word) ""))
+                  (progn
+                    (beginning-of-line)
+                    (delete-region (point) (min (1+ (line-end-position)) 
(point-max))))
+                (forward-line))))))
+
       ;; strip priorities
       (goto-char (point-min))
       (while (re-search-forward toc-org-priorities-regexp nil t)
         (replace-match "" nil nil nil 1))
 
       ;; strip tags
-      ;; TODO :export: and :noexport: tags semantic should be probably
-      ;; implemented
       (goto-char (point-min))
       (while (re-search-forward toc-org-tags-regexp nil t)
         (replace-match "" nil nil))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]