diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-26 14:00:35 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-26 14:00:35 -0500 |
| commit | 6319274992aaa88b820c98d8c06b93717105f183 (patch) | |
| tree | 0324cc90a52fc6ede62c4ae19a93499c593e50c3 /tests | |
| parent | db83a4975be50b5c579b0a075acd952f8135a73f (diff) | |
| download | dotemacs-6319274992aaa88b820c98d8c06b93717105f183.tar.gz dotemacs-6319274992aaa88b820c98d8c06b93717105f183.zip | |
feat(org): right-align headline tags to the window edge
org-tags-column only right-aligns tags to a fixed column, and it does so by baking literal spaces into the file, so it can't track window width or splits. I set it to 0 (org keeps a single space, no padding) and add a font-lock rule that stretches that space with a display property pinned to the window's right edge via :align-to. That value resolves at redisplay, so the tags follow the window width and adapt to splits live, and nothing alignment-specific is written to disk.
The tags stop one column short of the edge on purpose. A glyph filling the final column wraps a non-truncated line, which dropped every tagged heading's tags onto the next line in the first cut. org-agenda-tags-column gets 'auto, the native equivalent for agenda views. Tests cover the heading regexp and the align-spec helper.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-org-config-tag-alignment.el | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test-org-config-tag-alignment.el b/tests/test-org-config-tag-alignment.el new file mode 100644 index 00000000..e999f261 --- /dev/null +++ b/tests/test-org-config-tag-alignment.el @@ -0,0 +1,48 @@ +;;; test-org-config-tag-alignment.el --- Right-aligned org tags -*- lexical-binding: t; -*- + +;;; Commentary: +;; cj/org-tag-line-re and cj/org--tag-align-spec drive the display-property +;; right-alignment of org headline tags (org-config.el). The regexp isolates +;; the gap before the tags (group 1) and the tag string (group 2); the spec +;; helper turns a tag string into the (space :align-to (- right WIDTH)) display +;; spec that pins the tags to the window's right edge. These exercise the pure +;; logic directly, without driving font-lock. + +;;; Code: + +(require 'ert) +(require 'org-config) + +(ert-deftest test-org-config-tag-align-spec-single-tag () + "Normal: the spec pins a tag to the right edge less its width plus margin." + (should (equal (cj/org--tag-align-spec ":work:") + `(space :align-to (- right ,(+ 6 cj/org-tag-right-margin)))))) + +(ert-deftest test-org-config-tag-align-spec-widths () + "Boundary: shortest and multi-tag strings carry their width plus the margin." + (should (equal (cj/org--tag-align-spec ":a:") + `(space :align-to (- right ,(+ 3 cj/org-tag-right-margin))))) + (should (equal (cj/org--tag-align-spec ":a:b:") + `(space :align-to (- right ,(+ 5 cj/org-tag-right-margin)))))) + +(ert-deftest test-org-config-tag-line-re-matches-tagged-heading () + "Normal: a tagged headline matches with the gap and tags captured." + (let ((line "** TODO Something :work:")) + (should (string-match cj/org-tag-line-re line)) + (should (equal (match-string 1 line) " ")) + (should (equal (match-string 2 line) ":work:")))) + +(ert-deftest test-org-config-tag-line-re-captures-last-gap-with-padding () + "Boundary: with baked padding, group 1 is the single space before the tags." + (let ((line "*** TODO [#C] Foo :a:b:")) + (should (string-match cj/org-tag-line-re line)) + (should (equal (match-string 1 line) " ")) + (should (equal (match-string 2 line) ":a:b:")))) + +(ert-deftest test-org-config-tag-line-re-rejects-untagged-and-non-heading () + "Error: an untagged heading and a non-heading line do not match." + (should-not (string-match cj/org-tag-line-re "** TODO Foo")) + (should-not (string-match cj/org-tag-line-re "not a heading :work:"))) + +(provide 'test-org-config-tag-alignment) +;;; test-org-config-tag-alignment.el ends here |
