[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/toc-org 658c03111b 017/128: add some more tests and fix wo
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/toc-org 658c03111b 017/128: add some more tests and fix wording |
Date: |
Sun, 2 Jan 2022 09:59:06 -0500 (EST) |
branch: elpa/toc-org
commit 658c03111b91510b29249dcc8e3f13c2cdca6c7d
Author: Sergei Nosov <sergei.nosov@gmail.com>
Commit: Sergei Nosov <sergei.nosov@gmail.com>
add some more tests and fix wording
---
README.org | 33 ++++++++++++++++-----------------
org-toc.el | 45 ++++++++++++++++++++++++++++++++++-----------
2 files changed, 50 insertions(+), 28 deletions(-)
diff --git a/README.org b/README.org
index 3b5beb66b7..fea802ee0f 100644
--- a/README.org
+++ b/README.org
@@ -2,9 +2,8 @@
* About
-org-toc is a utility to have an up-to-date table of contents in the
-org files without exporting (useful primarily for readme files on
-GitHub).
+org-toc helps you to have an up-to-date table of contents in org files without
+exporting (useful primarily for readme files on GitHub).
It is similar to the
[[https://github.com/ardumont/markdown-toc][markdown-toc]] package, but works
for org files.
@@ -47,29 +46,29 @@ repository and then put the following snippet in your
~/.emacs file
* Use
-After the installation, every time you'll be saving an org file, the
-first headline with a :TOC: tag will be updated with the current table
-of contents.
+After the installation, every time you'll be saving an org file, the first
+headline with a =:TOC:= tag will be updated with the current table of contents.
-To add a TOC tag, you can use the command =org-set-tags-command=.
+To add a =:TOC:= tag, you can use the command =org-set-tags-command=, normally
+found bound to =C-c C-q=.
-In addition to the simple :TOC: tag, you can also use the following
-tag formats:
+In addition to the simple =:TOC:= tag, you can also use the following tag
+formats:
-- :TOC@2: - sets the max depth of the headlines in the table of
- contents to 2 (the default)
+- =:TOC_2:= - sets the max depth of the headlines in the table of contents to 2
+ (the default)
-- :TOC@2@gh: - sets the max depth as in above and also uses the
- GitHub-style hrefs in the table of contents (the default). The other
- supported href style is 'org', which is the default org style (you
- can use C-c C-o to go to the headline at point).
+- =:TOC_2_gh:= - sets the max depth as in above and also uses the GitHub-style
+ hrefs in the table of contents (the default). The other supported href style
+ is 'org', which is the default org style (you can use =C-c C-o= to go to the
+ headline at point).
-You can also use =_= as separator, instead of =@=.
+You can also use =@= as separator, instead of =_=.
* Different href styles
Currently, only 2 href styles are supported: =gh= and =org=. You can easily
-define your own styles. If you use the tag =:TOC@2@STYLE:= (=STYLE= being a
+define your own styles. If you use the tag =:TOC_2_STYLE:= (=STYLE= being a
style name), then the package will look for a function named
=org-toc-hrefify-STYLE=, which accepts a heading string and returns a href
corresponding to that heading.
diff --git a/org-toc.el b/org-toc.el
index 7e85aca1ac..aae3ee60b8 100644
--- a/org-toc.el
+++ b/org-toc.el
@@ -24,18 +24,19 @@
;;; Commentary:
-;; org-toc is a utility to have an up-to-date table of contents in the
-;; org files without exporting (useful primarily for readme files on
-;; GitHub).
+;; org-toc helps you to have an up-to-date table of contents in org files
+;; without exporting (useful primarily for readme files on GitHub).
-;; To enable this functionality put into your .emacs file something
-;; like
+;; After installation put into your .emacs file something like
-;; (add-hook 'org-mode-hook 'org-toc-enable)
+;; (eval-after-load "org-toc-autoloads"
+;; '(progn
+;; (if (require 'org-toc nil t)
+;; (add-hook 'org-mode-hook 'org-toc-enable)
+;; (warn "org-toc not found"))))
-;; After that, every time you'll be saving an org file the first
-;; headline with a :TOC: tag will be updated with the current table of
-;; contents.
+;; And every time you'll be saving an org file, the first headline with a :TOC:
+;; tag will be updated with the current table of contents.
;; For details, see https://github.com/snosov1/org-toc
@@ -129,8 +130,7 @@ tags."
rules."
(let* ((spc-fix (replace-regexp-in-string " " "-" str))
(upcase-fix (replace-regexp-in-string "[A-Z]" 'downcase spc-fix t))
- (special-chars-fix (replace-regexp-in-string
org-toc-special-chars-regexp "" upcase-fix t))
- )
+ (special-chars-fix (replace-regexp-in-string
org-toc-special-chars-regexp "" upcase-fix t)))
(concat "#" special-chars-fix)))
(ert-deftest org-toc-test-hrefify-gh ()
@@ -177,6 +177,12 @@ each heading into a link."
(buffer-substring-no-properties
(point-min) (point-max))))
+(ert-deftest org-toc-test-hrefify-toc ()
+ (should (equal (org-toc-hrefify-toc "* About\n" 'upcase)
+ " - [[ABOUT][About]]\n"))
+ (should (equal (org-toc-hrefify-toc "* About\n* Installation\n** via
package.el\n** Manual\n* Use\n* Different href styles\n* Example\n" 'upcase)
+ " - [[ABOUT][About]]\n - [[INSTALLATION][Installation]]\n
- [[VIA PACKAGE.EL][via package.el]]\n - [[MANUAL][Manual]]\n -
[[USE][Use]]\n - [[DIFFERENT HREF STYLES][Different href styles]]\n -
[[EXAMPLE][Example]]\n")))
+
(defun org-toc-flush-subheadings (toc max-depth)
"Flush subheadings of the raw `toc' deeper than `max-depth'."
(with-temp-buffer
@@ -191,6 +197,23 @@ each heading into a link."
(buffer-substring-no-properties
(point-min) (point-max))))
+(ert-deftest org-toc-test-flush-subheadings ()
+ (should (equal (org-toc-flush-subheadings "* About\n" 0)
+ ""))
+ (should (equal (org-toc-flush-subheadings "* About\n" 1)
+ "* About\n"))
+ (should (equal (org-toc-flush-subheadings "* About\n" 2)
+ "* About\n"))
+
+ (should (equal (org-toc-flush-subheadings "* About\n* Installation\n** via
package.el\n** Manual\n* Use\n* Different href styles\n* Example\n" 0)
+ ""))
+ (should (equal (org-toc-flush-subheadings "* About\n* Installation\n** via
package.el\n** Manual\n* Use\n* Different href styles\n* Example\n" 1)
+ "* About\n* Installation\n* Use\n* Different href styles\n*
Example\n"))
+ (should (equal (org-toc-flush-subheadings "* About\n* Installation\n** via
package.el\n** Manual\n* Use\n* Different href styles\n* Example\n" 2)
+ "* About\n* Installation\n** via package.el\n** Manual\n*
Use\n* Different href styles\n* Example\n"))
+ (should (equal (org-toc-flush-subheadings "* About\n* Installation\n** via
package.el\n** Manual\n* Use\n* Different href styles\n* Example\n" 3)
+ "* About\n* Installation\n** via package.el\n** Manual\n*
Use\n* Different href styles\n* Example\n")))
+
(defun org-toc-insert-toc ()
"Looks for a headline with the TOC tag and updates it with the
current table of contents.
- [nongnu] elpa/toc-org 63a0144afa 031/128: fix documentation, (continued)
- [nongnu] elpa/toc-org 63a0144afa 031/128: fix documentation, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org cfb309e8ab 035/128: fix typo, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 1a213baa8a 048/128: don't alter the type and path if we don't recognize it as a TOC entry, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org d23140d604 056/128: Merge pull request #21 from snosov1/fix-properties-handling, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 17c6cf1d1a 060/128: add tests, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 01cb78ead6 063/128: Use `delete-region` instead of kill-line while creating the TOC, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org d3d3503b34 062/128: Delete trailing whitespaces from links, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 4d076d1e9d 118/128: Respect the file-local value of org-list-indent-offset., ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org f3218fdaf1 123/128: Add license and copyright header to toc-org-test.el, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 501f36db68 021/128: Merge pull request #5 from ardumont/wrap-tests-definition, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 658c03111b 017/128: add some more tests and fix wording,
ELPA Syncer <=
- [nongnu] elpa/toc-org d3677cd8c8 022/128: make compile-command run the tests, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 0dee7197c8 026/128: fix byte-compilation check, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 242eecba19 034/128: add a note about previous name, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 90894242a6 046/128: treat org-list-indent-offset properly, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 4c0b28da59 037/128: add more tags for easier search, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org e38e81af3f 088/128: Merge pull request #57 from JAremko/master, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org cda8f73640 073/128: Merge pull request #37 from snosov1/handle-comment, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org ee70dd23e1 104/128: resolve missing functions warnings, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org d52f95fae8 105/128: Handle trailing #'s, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 5ce7c24920 096/128: handle paranthesis in #+TODO line (fixes #65), ELPA Syncer, 2022/01/02