如何在组织模式文件中生成所有标记的枚举列表(例如:tag:
)?说我有一个表格列表:
* Head1 :foo:bar:
** Subhead1 :foo:
* Head2
** Subhead2 :foo:bar:
我想生成此文件中所有标记的列表以及每个标记的使用次数。说些什么,
:foo: 3
:bar: 2
答案 0 :(得分:3)
这是一个较短的版本。
(defun get-tag-counts ()
(let ((all-tags '()))
(org-map-entries
(lambda ()
(let ((tag-string (car (last (org-heading-components)))))
(when tag-string
(setq all-tags
(append all-tags (split-string tag-string ":" t)))))))
;; now get counts
(loop for tag in (-uniq all-tags)
collect (cons tag (cl-count tag all-tags :test 'string=)))))
答案 1 :(得分:0)
这是一种方法。
(setq my-hash (make-hash-table :test 'equal))
(org-map-entries
(lambda ()
(let ((tag-string (car (last (org-heading-components))))
(current-count))
(when tag-string
(dolist (tag (split-string tag-string ":" t))
(setq current-count (gethash tag my-hash))
(if current-count;
(puthash tag (+ 1 current-count) my-hash)
(puthash tag 1 my-hash))
)
)
)
)
)
;; https://github.com/Wilfred/ht.el
(require 'ht)
(ht-map
(lambda (key value)
(list key value))
my-hash)
答案 2 :(得分:0)
我无法使用John Kitchin发布的代码,因为它需要交互功能。来自 IRC freenode /#emacs 的 bpalmer 很乐意帮助我。请找到一个工作示例,将相应标签下的所有标签都显示出来。
; use this in order to be able to use loop on its own
(require 'cl)
;; count tags (see John's answer)
(defun get-tag-counts ()
(let ((all-tags '()))
(org-map-entries
(lambda ()
(let ((tag-string (car (last (org-heading-components)))))
(when tag-string
(setq all-tags
(append all-tags (split-string tag-string ":" t)))))))
;; now get counts
(loop for tag in (seq-uniq all-tags)
collect (cons tag (cl-count tag all-tags :test 'string=)))))
;; wrap get-tag-counts in an interactive function
(defun create-tag-counts-buffer () (interactive)
(let
((tags (get-tag-counts)) (b (get-buffer-create "*Org Tag Count*")))
(dolist (tag tags) (insert (car tag)) (insert "\n")) (display-buffer b)))
请注意,由于我的声誉太低,我无法发表评论John的答案。