[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/toc-org b0cac21cdf 059/128: handle statistics cookies and
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/toc-org b0cac21cdf 059/128: handle statistics cookies and #+OPTIONS: todo:t |
Date: |
Sun, 2 Jan 2022 09:59:09 -0500 (EST) |
branch: elpa/toc-org
commit b0cac21cdf625cdc393d7010daac3a45a9201b80
Author: Sergei Nosov <sergei.nosov@gmail.com>
Commit: Sergei Nosov <sergei.nosov@gmail.com>
handle statistics cookies and #+OPTIONS: todo:t
fixes #28
---
README.org | 4 ++--
toc-org.el | 49 +++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 43 insertions(+), 10 deletions(-)
diff --git a/README.org b/README.org
index 4778f45e44..e5c218898e 100644
--- a/README.org
+++ b/README.org
@@ -103,13 +103,13 @@ hrefs. The table can be used to maintain href uniqueness
(see
=toc-org-hrefify-gh=, for example). Return value should be a href corresponding
to that heading.
-E.g. for =org= style it simply returns input as is:
+E.g. for =org= style it makes links to be the same as their visible text:
#+BEGIN_SRC emacs-lisp
(defun toc-org-hrefify-org (str &optional hash)
"Given a heading, transform it into a href using the org-mode
rules."
- str)
+ (toc-org-format-visible-link str))
#+END_SRC
* Example
diff --git a/toc-org.el b/toc-org.el
index 72ffde745c..ec7c4e50b6 100644
--- a/toc-org.el
+++ b/toc-org.el
@@ -66,6 +66,10 @@ files on GitHub)"
(defconst toc-org-special-chars-regexp "[^[:alnum:]_-]"
"Regexp with the special characters (which are omitted in hrefs
by GitHub)")
+(defconst toc-org-statistics-cookies-regexp
"\s*\\[[0-9]*\\(%\\|/[0-9]*\\)\\]\s*$"
+ "Regexp to find statistics cookies on the line")
+(defconst toc-org-leave-todo-regexp "^#\\+OPTIONS:.*\stodo:t[\s\n]"
+ "Regexp to find the todo export setting")
(defconst toc-org-drawer-regexp "^[ ]*:\\(\\(?:\\w\\|[-_]\\)+\\):[ ]*$"
"Regexp to match org drawers. Note: generally, it should be
equal to `org-drawer-regexp'. However, some older versions of
@@ -97,9 +101,17 @@ headings.")
i.e. simply flush everything that's not a heading and strip
auxiliary text."
(let ((content (buffer-substring-no-properties
- (point-min) (point-max))))
+ (point-min) (point-max)))
+ (leave-states-p nil))
(with-temp-buffer
(insert content)
+
+ ;; set leave-states-p variable
+ (goto-char (point-min))
+ (when (re-search-forward toc-org-leave-todo-regexp nil t)
+ (setq leave-states-p t))
+
+ ;; keep only lines starting with *s
(goto-char (point-min))
(keep-lines "^\*+[ ]")
@@ -110,9 +122,10 @@ auxiliary text."
(delete-region (point) (progn (forward-line 1) (point)))
;; strip states
- (goto-char (point-min))
- (while (re-search-forward toc-org-states-regexp nil t)
- (replace-match "" nil nil nil 1))
+ (unless leave-states-p
+ (goto-char (point-min))
+ (while (re-search-forward toc-org-states-regexp nil t)
+ (replace-match "" nil nil nil 1)))
;; strip priorities
(goto-char (point-min))
@@ -196,10 +209,22 @@ rules."
(puthash "#about-2" "About" hash)
(should (equal (toc-org-hrefify-gh "About" hash) "#about-3"))))
+(defun toc-org-format-visible-link (str)
+ "Formats the visible text of the link."
+ (with-temp-buffer
+ (insert str)
+
+ ;; strip statistics cookies
+ (goto-char (point-min))
+ (while (re-search-forward toc-org-statistics-cookies-regexp nil t)
+ (replace-match "" nil nil))
+ (buffer-substring-no-properties
+ (point-min) (point-max))))
+
(defun toc-org-hrefify-org (str &optional hash)
"Given a heading, transform it into a href using the org-mode
rules."
- str)
+ (toc-org-format-visible-link str))
(defun toc-org-unhrefify (type path)
"Looks for a value in toc-org-hrefify-hash using path as a key."
@@ -253,7 +278,11 @@ each heading into a link."
(insert "[[")
(insert hrefified)
(insert "][")
- (end-of-line)
+ (insert
+ (toc-org-format-visible-link
+ (buffer-substring-no-properties
+ (point) (line-end-position))))
+ (kill-line)
(insert "]]")
;; maintain the hash table, if provided
@@ -365,8 +394,8 @@ following tag formats:
(let ((end
(save-excursion ;; limit to next heading
(search-forward-regexp "^\\*" (point-max)
'skip))))
- (while (re-search-forward toc-org-drawer-regexp end t)
- (skip-chars-forward "[:space:]")))
+ (while (re-search-forward toc-org-drawer-regexp end t)
+ (skip-chars-forward "[:space:]")))
(beginning-of-line)
;; insert newline if TOC is currently empty
@@ -446,6 +475,10 @@ following tag formats:
(test-toc-org-insert-toc-gold-test
"* H1\n* H2\n* TOC :TOC:\n - [[#header-1][Header 1]]\n -
[[#header-2][Header 2]]\n"
"* H1\n* H2\n* TOC :TOC:\n - [[#h1][H1]]\n - [[#h2][H2]]\n")
+
+ (test-toc-org-insert-toc-gold-test
+ "* H1\n* TODO H2\n* TOC :TOC:\n \n"
+ "* H1\n* TODO H2\n* TOC :TOC:\n - [[#h1][H1]]\n -
[[#h2][H2]]\n")
))
;; Local Variables:
- [nongnu] elpa/toc-org 32975071df 039/128: mention former name in description, (continued)
- [nongnu] elpa/toc-org 32975071df 039/128: mention former name in description, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org c662f96040 090/128: add quote functionality, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 4cd71edc29 082/128: bump emacs25 version, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 827dc448e0 013/128: push .travis.yml, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 11be82816a 019/128: Merge pull request #4 from ardumont/add-tag-setup, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org b4dbeb936c 024/128: simply require ert, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 3dd30029b6 043/128: strip TODO and DONE states, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 7eb2874ed3 041/128: require org, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 3e0bdb5a29 054/128: fix properties handling (see #20), ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 7c54f809d6 058/128: Merge pull request #23 from snosov1/fix-eof-toc, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org b0cac21cdf 059/128: handle statistics cookies and #+OPTIONS: todo:t,
ELPA Syncer <=
- [nongnu] elpa/toc-org 44c2e17543 070/128: Merge pull request #36 from snosov1/move-tests, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 421956e9cc 078/128: remove opening space in each toc item, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 379b457fcf 107/128: fix subheading link in readme, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org f0b94e07bb 075/128: Merge pull request #39 from snosov1/add-noexport-support, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 274e821fd4 079/128: update emacs to 25 for travis testing, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 5deaec41ed 109/128: Update README.org, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org aef220c266 115/128: Merge pull request #71 from snosov1/fix-70, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 4798d15365 110/128: WIP Fix stripping of word "Comment" in headlines, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org e76e6d4044 085/128: make toc-org work in derived modes, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org d992b1f76a 108/128: Update README.org, ELPA Syncer, 2022/01/02