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

[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.



reply via email to

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