Skip to content

Commit 71b582d

Browse files
committed
make function to count the number of sub-entries in org-mode
1 parent 5f9e393 commit 71b582d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

user.el

+22
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,28 @@
4242
(setq calendar-longitude -103.35)
4343
(setq wttrin-default-cities '("Seoul, Korea"))
4444

45+
(defun jj/org-number-of-subentries (&optional pos match scope level)
46+
"Return number of subentries for entry at POS.
47+
MATCH and SCOPE are the same as for `org-map-entries', but
48+
SCOPE defaults to 'tree.
49+
By default, all subentries are counted; restrict with LEVEL."
50+
(interactive)
51+
(save-excursion
52+
(goto-char (or pos (point)))
53+
;; If we are in the middle ot an entry, use the current heading.
54+
(org-back-to-heading t)
55+
(let ((maxlevel (when (and level (org-current-level))
56+
(+ level (org-current-level)))))
57+
(message "%s subentries"
58+
(1- (length
59+
(delq nil
60+
(org-map-entries
61+
(lambda ()
62+
;; Return true, unless below maxlevel.
63+
(or (not maxlevel)
64+
(<= (org-current-level) maxlevel)))
65+
match (or scope 'tree)))))))))
66+
4567
(defun jj/delete-backward-char (n &optional killflag)
4668
"Delete the previous N characters (following if N is negative).
4769
If Transient Mark mode is enabled, the mark is active, and N is 1,

0 commit comments

Comments
 (0)