branch: elpa/toc-org
commit aa52bd036da7d61005b75bab7f1667c02f01064c
Author: Sergei Nosov <[email protected]>
Commit: Sergei Nosov <[email protected]>
handle headlines with COMMENT
---
toc-org-test.el | 24 +++++++++++++++++++++++-
toc-org.el | 11 +++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/toc-org-test.el b/toc-org-test.el
index 7bf8233d14..b9777aa24c 100644
--- a/toc-org-test.el
+++ b/toc-org-test.el
@@ -32,13 +32,35 @@
"* About\n:TOC:\n drawer\n:END:\n\ntoc-org is a utility to have an
up-to-date table of contents in the\norg files without exporting (useful
primarily for readme files on\nGitHub).\n\nIt is similar to the
[[https://github.com/ardumont/markdown-toc][markdown-toc]] package, but works
for org files.\n:TOC:\n drawer\n:END:\n\n* Table of Contents
:TOC:\n - [[#about][About]]\n -
[[#use][Use]]\n - [[#different-href-styles][Different href st [...]
"* About\n* Installation\n** via package.el\n** Manual\n* Use\n* Different
href styles\n* Example\n")
+ ;; test #+OPTIONS 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: todo: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 ~/.emacs file\n#
[...]
"* About\n* Installation\n** DONE via package.el\n** TODO Manual\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** TODO Manual\n"))
+ "* About\n* Installation\n** DONE via package.el\n** TODO Manual\n")
+
+ ;; test COMMENT 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"))
(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 368b7305e8..bc323743c2 100644
--- a/toc-org.el
+++ b/toc-org.el
@@ -58,6 +58,8 @@ files on GitHub)"
"Regexp to find tags on the line")
(defconst toc-org-states-regexp "^*+\s+\\(TODO\s+\\|DONE\s+\\)"
"Regexp to find states on the line")
+(defconst toc-org-COMMENT-regexp "\\(^*+\\)\s+\\(COMMENT\s+\\)"
+ "Regexp to find COMMENT headlines")
(defconst toc-org-priorities-regexp "^*+\s+\\(\\[#.\\]\s+\\)"
"Regexp to find states on the line")
(defconst toc-org-links-regexp "\\[\\[\\(.*?\\)\\]\\[\\(.*?\\)\\]\\]"
@@ -126,6 +128,15 @@ auxiliary text."
(while (re-search-forward toc-org-states-regexp nil t)
(replace-match "" nil nil nil 1)))
+ ;; strip COMMENT headlines
+ (goto-char (point-min))
+ (while (re-search-forward toc-org-COMMENT-regexp nil t)
+ (let ((skip-depth (concat (match-string 1) "*")))
+ (while (progn
+ (beginning-of-line)
+ (delete-region (point) (min (1+ (line-end-position))
(point-max)))
+ (string-prefix-p skip-depth (current-word))))))
+
;; strip priorities
(goto-char (point-min))
(while (re-search-forward toc-org-priorities-regexp nil t)