diff options
| author | Craig Jennings <c@cjennings.net> | 2025-11-08 16:11:58 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-11-08 16:11:58 -0600 |
| commit | 8176eff73b826f7fec9d7f458f7d2f36f4d12e58 (patch) | |
| tree | 3e73394b689f0e32dce6930431d9060d946b0b79 /modules/custom-ordering.el | |
| parent | d093a4a96c653d3f9adcbba17b4094d6d9a5a85a (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/custom-ordering.el')
| -rw-r--r-- | modules/custom-ordering.el | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/modules/custom-ordering.el b/modules/custom-ordering.el index 7d906e75..f6972910 100644 --- a/modules/custom-ordering.el +++ b/modules/custom-ordering.el @@ -249,7 +249,8 @@ Returns the transformed string without modifying the buffer." "r" #'cj/reverse-lines "n" #'cj/number-lines "A" #'cj/alphabetize-region - "L" #'cj/comma-separated-text-to-lines) + "L" #'cj/comma-separated-text-to-lines + "o" #'cj/org-sort-by-todo-and-priority) (keymap-set cj/custom-keymap "o" cj/ordering-map) (with-eval-after-load 'which-key @@ -262,7 +263,8 @@ Returns the transformed string without modifying the buffer." "C-; o r" "reverse lines" "C-; o n" "number lines" "C-; o A" "alphabetize" - "C-; o L" "comma to lines")) + "C-; o L" "comma to lines" + "C-; o o" "org: sort by TODO+priority")) (provide 'custom-ordering) ;;; custom-ordering.el ends here. |
