[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/toc-org 8cf236450b 045/128: don't modify and save file on
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/toc-org 8cf236450b 045/128: don't modify and save file on opening |
Date: |
Sun, 2 Jan 2022 09:59:08 -0500 (EST) |
branch: elpa/toc-org
commit 8cf236450b25f5b655f3262564d5a6af325bf6f4
Author: Sergei Nosov <sergei.nosov@gmail.com>
Commit: Sergei Nosov <sergei.nosov@gmail.com>
don't modify and save file on opening
---
toc-org.el | 55 +++++++++++++++++++++++++++----------------------------
1 file changed, 27 insertions(+), 28 deletions(-)
diff --git a/toc-org.el b/toc-org.el
index c6c740fcd9..b8ab961a5a 100644
--- a/toc-org.el
+++ b/toc-org.el
@@ -272,10 +272,14 @@ each heading into a link."
(should (equal (toc-org-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 toc-org-insert-toc ()
+(defun toc-org-insert-toc (&optional dry-run)
"Looks for a headline with the TOC tag and updates it with the
current table of contents.
+If optional second argument DRY-RUN is provided, then the buffer
+is not modified at all. Only the internal hash-table is updated
+to enable `org-open-at-point' for TOC links.
+
To add a TOC tag, you can use the command
`org-set-tags-command' (C-c C-q).
@@ -297,11 +301,6 @@ following tag formats:
(let ((case-fold-search t))
;; find the first heading with the :TOC: tag
(when (re-search-forward toc-org-toc-org-regexp (point-max) t)
-
- ;; make toc visible
- (save-match-data
- (org-show-entry))
-
(let* ((tag (match-string 1))
(depth (if tag
(- (aref tag 1) ?0) ;; is there a better way to
convert char to number?
@@ -312,26 +311,27 @@ following tag formats:
(hrefify-string (concat "toc-org-hrefify-" hrefify-tag))
(hrefify (intern-soft hrefify-string)))
(if hrefify
- (progn
- (newline (forward-line 1))
-
- ;; insert newline if TOC is currently empty
- (when (looking-at "^\\*")
- (open-line 1))
-
- ;; remove previous TOC
- (delete-region (point)
- (save-excursion
- (when (search-forward-regexp "^\\*"
(point-max) t)
- (forward-line -1))
- (end-of-line)
- (point)))
-
- (insert (toc-org-hrefify-toc
- (toc-org-flush-subheadings (toc-org-raw-toc) depth)
- hrefify
- (when toc-org-hrefify-hash
- (clrhash toc-org-hrefify-hash)))))
+ (let ((new-toc
+ (toc-org-hrefify-toc
+ (toc-org-flush-subheadings (toc-org-raw-toc) depth)
+ hrefify
+ (when toc-org-hrefify-hash
+ (clrhash toc-org-hrefify-hash)))))
+ (unless dry-run
+ (newline (forward-line 1))
+
+ ;; insert newline if TOC is currently empty
+ (when (looking-at "^\\*")
+ (open-line 1))
+
+ ;; remove previous TOC
+ (delete-region (point)
+ (save-excursion
+ (when (search-forward-regexp "^\\*"
(point-max) t)
+ (forward-line -1))
+ (end-of-line)
+ (point)))
+ (insert new-toc)))
(message (concat "Hrefify function " hrefify-string " is not
found")))))))))
;;;###autoload
@@ -346,8 +346,7 @@ following tag formats:
(equal org-link-translation-function 'toc-org-unhrefify)))
(setq toc-org-hrefify-hash (make-hash-table :test 'equal))
(setq org-link-translation-function 'toc-org-unhrefify)
- (toc-org-insert-toc)
- (save-buffer)))
+ (toc-org-insert-toc t)))
(ert-deftest toc-org-test-insert-toc ()
"Test the `toc-org-insert-toc' function"
- [nongnu] elpa/toc-org 328d34144f 124/128: Bump version to 1.1, (continued)
- [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, 2022/01/02
- [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 <=
- [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
- [nongnu] elpa/toc-org c83c19ddb4 093/128: Merge pull request #59 from snosov1/add-quote, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 35781c6313 126/128: Merge pull request #82 from skangas/add-license, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 08ed3f0883 061/128: Merge pull request #30 from snosov1/fix-28, ELPA Syncer, 2022/01/02