[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/toc-org 752fe14c5b 042/128: fix "_1_org"-style suffixes
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/toc-org 752fe14c5b 042/128: fix "_1_org"-style suffixes |
Date: |
Sun, 2 Jan 2022 09:59:08 -0500 (EST) |
branch: elpa/toc-org
commit 752fe14c5bf2b4085a702fa8441b0633ebe313f0
Author: Sergei Nosov <sergei.nosov@gmail.com>
Commit: Sergei Nosov <sergei.nosov@gmail.com>
fix "_1_org"-style suffixes
---
toc-org.el | 47 ++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 42 insertions(+), 5 deletions(-)
diff --git a/toc-org.el b/toc-org.el
index ed5f3fc8c7..dc66b8d40f 100644
--- a/toc-org.el
+++ b/toc-org.el
@@ -94,7 +94,7 @@ tags."
;; don't include the TOC itself
(goto-char (point-min))
- (re-search-forward toc-org-toc-org-regexp)
+ (re-search-forward toc-org-toc-org-regexp nil t)
(beginning-of-line)
(delete-region (point) (progn (forward-line 1) (point)))
@@ -286,7 +286,8 @@ following tag formats:
(when (re-search-forward toc-org-toc-org-regexp (point-max) t)
;; make toc visible
- (org-show-entry)
+ (save-match-data
+ (org-show-entry))
(let* ((tag (match-string 1))
(depth (if tag
@@ -299,7 +300,7 @@ following tag formats:
(hrefify (intern-soft hrefify-string)))
(if hrefify
(progn
- (forward-line 1)
+ (newline (forward-line 1))
;; insert newline if TOC is currently empty
(when (looking-at "^\\*")
@@ -308,8 +309,8 @@ following tag formats:
;; remove previous TOC
(delete-region (point)
(save-excursion
- (search-forward-regexp "^\\*" (point-max) 0)
- (forward-line -1)
+ (when (search-forward-regexp "^\\*"
(point-max) t)
+ (forward-line -1))
(end-of-line)
(point)))
@@ -335,6 +336,42 @@ following tag formats:
(toc-org-insert-toc)
(save-buffer)))
+(ert-deftest toc-org-test-insert-toc ()
+ "Test the `toc-org-insert-toc' function"
+
+ (defun toc-org-test-insert-toc-gold-test (content gold)
+ (with-temp-buffer
+ (org-mode)
+ (insert content)
+ (toc-org-raw-toc)
+ (toc-org-insert-toc)
+ (should (equal
+ (buffer-substring-no-properties
+ (point-min) (point-max))
+ gold))))
+ (declare-function toc-org-test-insert-toc-gold-test "toc-org") ;; suppress
compiler warning
+
+ (let ((beg "* 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* Hello\n** Good-bye\n*** Salut\n*
Table of Contents "))
+ (toc-org-test-insert-toc-gold-test
+ (concat beg ":TOC:")
+ "* 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* Hello\n** Good-bye\n*** Salut\n*
Table of Contents :TOC:\n -
[[#about][About]]\n - [[#hello][Hello]]\n - [[ [...]
+
+ (toc-org-test-insert-toc-gold-test
+ (concat beg ":TOC_1:")
+ "* 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* Hello\n** Good-bye\n*** Salut\n*
Table of Contents :TOC_1:\n
- [[#about][About]]\n - [[#hello][Hello]]\n")
+
+ (toc-org-test-insert-toc-gold-test
+ (concat beg ":TOC_3:")
+ "* 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* Hello\n** Good-bye\n*** Salut\n*
Table of Contents :TOC_3:\n
- [[#about][About]]\n - [[#hello][Hello]]\n - [...]
+
+ (toc-org-test-insert-toc-gold-test
+ (concat beg ":TOC_1_org:")
+ "* 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* Hello\n** Good-bye\n*** Salut\n*
Table of Contents
:TOC_1_org:\n - [[About][About]]\n - [[Hello][Hello]]\n")
+
+ (toc-org-test-insert-toc-gold-test
+ (concat beg ":TOC_3_org:")
+ "* 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* Hello\n** Good-bye\n*** Salut\n*
Table of Contents
:TOC_3_org:\n - [[About][About]]\n - [[Hello][Hello]]\n [...]
+
;; Local Variables:
;; compile-command: "emacs -batch -l ert -l *.el -f
ert-run-tests-batch-and-exit && emacs -batch -f batch-byte-compile *.el 2>&1 |
sed -n '/Warning\|Error/p' | xargs -r ls"
;; End:
- [nongnu] elpa/toc-org f455bd4c88 103/128: Call batch compile before running the tests, (continued)
- [nongnu] elpa/toc-org f455bd4c88 103/128: Call batch compile before running the tests, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 8321d3c76b 120/128: Revert "Respect the file-local value of org-list-indent-offset.", ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 6eca67f9a8 127/128: Merge pull request #83 from skangas/silence-byte-compiler, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 328d34144f 124/128: Bump version to 1.1, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org ebff38bfa4 094/128: make toc-org a minor mode (#61), ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org aa9aea6d69 102/128: Supress warnings, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 215d3e41e3 114/128: fix C-c C-o for links with cookies, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org a2cb4c254f 128/128: Merge pull request #84 from skangas/nongnu-elpa, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org d66a41f6b7 010/128: strip tags, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org cac667fabd 018/128: Add a small note about global tag setup, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 752fe14c5b 042/128: fix "_1_org"-style suffixes,
ELPA Syncer <=
- [nongnu] elpa/toc-org 815c6d8c1b 044/128: flatten links when creating raw toc, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org e0cef2c6a1 027/128: print emacs version in travis log, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 8cf236450b 045/128: don't modify and save file on opening, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 114dcc9813 053/128: make GitHub hrefs unique (fixes #16), ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 72883a08b0 049/128: update the TOC only if it's actually different from the current one, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 4e4b4e6484 057/128: generate correct toc when it's the last heading, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 4380d99113 065/128: add unit test for #31, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 970560a874 069/128: fix travis build, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 39d983c381 074/128: add noexport support, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 663e5ec281 116/128: Correct sample configuration to valid code, ELPA Syncer, 2022/01/02