diff options
author | Kyle Meyer <kyle@kyleam.com> | 2014-03-31 20:16:37 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2014-03-31 20:16:37 -0400 |
commit | 128173bca68b579499a2b01a9e7d64fa96a9b192 (patch) | |
tree | 30d13b08f8c9db82f5a6b661bad091130d91867e /bog.el | |
parent | 4e240bd6f1569d9c304567992529f949b880fb04 (diff) | |
download | bog-128173bca68b579499a2b01a9e7d64fa96a9b192.tar.gz |
Add functions to sort topic headings
Diffstat (limited to 'bog.el')
-rw-r--r-- | bog.el | 40 |
1 files changed, 39 insertions, 1 deletions
@@ -171,7 +171,15 @@ It should contain the placeholder \"%s\" for the query." :group 'bog :type 'string) -(defcustom bog-refile-maxlevel 1 +(defcustom bog-topic-heading-level 1 + "Consider headings at this level to be topic headings. +Topic headings for studies may be at any level, but +`bog-sort-topic-headings' uses this variable to determine what +level to operate on." + :group 'bog + :type 'integer) + +(defcustom bog-refile-maxlevel bog-topic-heading-level "Consider up to this level when refiling with `bog-refile'." :group 'bog :type 'integer) @@ -252,6 +260,11 @@ year, and the first meaningful word in the title)." (error "Citekey not found")) citekey)))) +(defun bog-citekey-heading-p () + (let ((heading (org-no-properties (org-get-heading t t)))) + (or (bog-citekey-only-p heading) + (org-entry-get (point) bog-citekey-property)))) + (defun bog-citekey-p (text) "Indicate if TEXT matches `bog-citekey-format'." (when (string-match bog-citekey-format text) @@ -561,6 +574,31 @@ With prefix argument TODO-ONLY, only TODO entries are searched." (put 'org-agenda-redo-command 'org-lprops lprops) (org-let lprops '(org-search-view todo-only citekey)))) +(defun bog-sort-topic-headings-in-buffer (&optional sorting-type) + "Sort topic headings in this buffer. +SORTING-TYPE is a character passed to `org-sort-entries'. If nil, +?a is used. The level to sort is determined by +`bog-topic-heading-level'." + (interactive) + (org-map-entries '(lambda () (bog-sort-if-topic-header sorting-type)))) + +(defun bog-sort-topic-headings-in-notes (&optional sorting-type) + "Sort topic headings in notes. +Unlike `bog-sort-topic-headings-in-buffer', sort topic headings +in all Bog notes." + (interactive) + (org-map-entries '(lambda () (bog-sort-if-topic-header sorting-type)) + nil (bog-notes-files))) + +(defun bog-sort-if-topic-header (sorting-type) + "Sort heading with `org-sort-entries' according to SORTING-TYPE. +Sorting is only done if the heading's level matches +`bog-topic-heading-level' and it isn't a citekey heading." + (let ((sorting-type (or sorting-type ?a))) + (when (and (= (org-current-level) bog-topic-heading-level) + (not (bog-citekey-heading-p))) + (org-sort-entries nil sorting-type)))) + ;;; Font-lock |