summaryrefslogtreecommitdiff
path: root/modules/org-config.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-11-08 16:11:58 -0600
committerCraig Jennings <c@cjennings.net>2025-11-08 16:11:58 -0600
commit8176eff73b826f7fec9d7f458f7d2f36f4d12e58 (patch)
tree3e73394b689f0e32dce6930431d9060d946b0b79 /modules/org-config.el
parentd093a4a96c653d3f9adcbba17b4094d6d9a5a85a (diff)
feat: Fix modeline lag and add org multi-level sort with comprehensive tests
Performance improvement and new feature with full test coverage. ## Changes ### 1. Fix modeline line/column position lag (#A priority) - Replace expensive line-number-at-pos with cached %l/%c format specifiers - Enable line-number-mode explicitly for caching - Result: Instant modeline updates, zero performance overhead - Files: modules/modeline-config.el:81-83, modules/ui-config.el:53 ### 2. Implement multi-level org sorting - New function: cj/org-sort-by-todo-and-priority - Sorts by TODO status (TODO before DONE) AND priority (A→B→C→D) - Uses stable sorting: priority first, then TODO state - Gracefully handles empty sections (no error) - Bound to C-; o o (ordering → org sort) - Files: modules/org-config.el:278-299, modules/custom-ordering.el:253,267 ### 3. Comprehensive ERT test suite (12/12 passing) - Normal cases: Mixed TODO/DONE, multiple of same type, same priority - Boundary cases: Empty sections, single entries, no priorities - Error cases: Non-org-mode buffer - Test file: tests/test-org-sort-by-todo-and-priority.el ### 4. Testing improvements discovered - Disable org-mode hooks to avoid package dependencies in batch mode - org-sort-entries must be called from parent heading - Preserve priority cookie in org-get-heading (t t nil t) - Add condition-case to handle "Nothing to sort" gracefully ### 5. Minor cleanup - Comment out chime-debug setting (org-agenda-config.el:267) - Mark modeline lag task as DONE in todo.org ## Technical Details Modeline optimization: - line-number-at-pos is O(n) where n = current line - %l and %c are O(1) lookups from cached values Org sorting algorithm uses stable sort: 1. Sort by priority (A, B, C, D, unprioritized) 2. Sort by TODO status (preserves priority order within groups) Result: TODO [#A], TODO [#B], DONE [#A], DONE [#B], etc. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'modules/org-config.el')
-rw-r--r--modules/org-config.el24
1 files changed, 24 insertions, 0 deletions
diff --git a/modules/org-config.el b/modules/org-config.el
index 75d4c7db..5cae1d0e 100644
--- a/modules/org-config.el
+++ b/modules/org-config.el
@@ -225,6 +225,7 @@
(use-package org-appear
:hook (org-mode . org-appear-mode)
+ :disabled t
:custom
(org-appear-autoemphasis t) ;; Show * / _ when cursor is on them
(org-appear-autolinks t) ;; Also works for links
@@ -274,6 +275,29 @@ the current buffer's cache. Useful when encountering parsing errors like
(message "Cleared org-element cache for current buffer"))
(user-error "Current buffer is not in org-mode"))))
+;; ----------------------- Org Multi-Level Sorting -----------------------------
+
+(defun cj/org-sort-by-todo-and-priority ()
+ "Sort org entries by TODO status (TODO before DONE) and priority (A to D).
+Sorts the current level's entries. Within each TODO state group, entries are
+sorted by priority. Uses stable sorting: sort by priority first, then by TODO
+status to preserve priority ordering within TODO groups."
+ (interactive)
+ (unless (derived-mode-p 'org-mode)
+ (user-error "Current buffer is not in org-mode"))
+ (save-excursion
+ ;; First sort by priority (A, B, C, D, then no priority)
+ ;; Ignore "Nothing to sort" errors for empty sections
+ (condition-case nil
+ (org-sort-entries nil ?p)
+ (user-error nil))
+ ;; Then sort by TODO status (TODO before DONE)
+ ;; This preserves the priority ordering within each TODO group
+ (condition-case nil
+ (org-sort-entries nil ?o)
+ (user-error nil)))
+ (message "Sorted entries by TODO status and priority"))
+
;; which-key labels for org-table-map
(with-eval-after-load 'which-key
(which-key-add-key-based-replacements