summaryrefslogtreecommitdiff
path: root/modules/org-capture-config.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-02-15 19:58:15 -0600
committerCraig Jennings <c@cjennings.net>2026-02-15 19:58:15 -0600
commit61bfb79f2c55983697f87b9ba3961a9fb46de2fe (patch)
tree6a9ebc025dcd71cba68f4612aef7b658781f4b8f /modules/org-capture-config.el
parent8eab9ccde339829c1866a40f51f942a6b36f2b02 (diff)
test: add 86 new tests, fix 3 production bugs, fix 8 stale tests
New test coverage (86 tests across 7 files): - custom-case: 43 tests (title-case-region, upcase-dwim, downcase-dwim) - custom-datetime: 10 tests (all insert methods with mocked time) - config-utilities: 11 tests (format-build-time type branching) - org-capture-config: 22 tests (date-prefix + event-content) Production bugs found and fixed: - custom-case: title-case-region crashes on whitespace/punctuation-only input (char-after returns nil when no word chars found) - org-capture-config: browser branch missing empty-string guard on :initial plist value, producing stray newline in capture output - mousetrap-mode: keymap never registered in minor-mode-map-alist, so mode was silently not blocking any mouse events. Now pushes/removes on toggle. Additional fixes: - local-repository: fix cons cell syntax bug in localrepo-initialize (was calling vars as functions instead of using cons) - dupre-theme tests: update rainbow-delimiter color expectations - mousetrap tests: update dashboard profile (primary-click → scroll+primary) - music completion test: bind completion-ignore-case to prevent pollution - Delete redundant interactive recording test (duplicate of ERT version) Refactoring: - org-capture-config: extract cj/org-capture--date-prefix pure function from cj/org-capture-format-event-headline for testability Test checklist: todo.org updated to [11/25], removed untestable modules
Diffstat (limited to 'modules/org-capture-config.el')
-rw-r--r--modules/org-capture-config.el34
1 files changed, 18 insertions, 16 deletions
diff --git a/modules/org-capture-config.el b/modules/org-capture-config.el
index 5d569002..755eecaf 100644
--- a/modules/org-capture-config.el
+++ b/modules/org-capture-config.el
@@ -24,6 +24,17 @@
;; -------------------------- Event Capture Formatting -------------------------
+ (defun cj/org-capture--date-prefix (timestamp)
+ "Return \"YY-MM-DD: \" prefix from org TIMESTAMP string, or nil if unparseable."
+ (when-let ((parsed (ignore-errors (org-parse-time-string timestamp))))
+ (let ((year (nth 5 parsed))
+ (month (nth 4 parsed))
+ (day (nth 3 parsed)))
+ (when (and year month day
+ (> year 0) (> month 0) (> day 0))
+ (format "%02d-%02d-%02d: "
+ (mod year 100) month day)))))
+
(defun cj/org-capture-format-event-headline ()
"Format the event headline with YY-MM-DD prefix from the WHEN timestamp.
This function is called during `org-capture' finalization to prepend the date
@@ -31,22 +42,12 @@ to the event title for better organization in the schedule file."
(when (string= (plist-get org-capture-plist :key) "e")
(save-excursion
(goto-char (point-min))
- ;; Find the WHEN: line with timestamp
(when (re-search-forward "^WHEN: \\(<[^>]+>\\)" nil t)
- (let* ((timestamp (match-string 1))
- ;; Parse the timestamp to extract date components
- (parsed (org-parse-time-string timestamp))
- (year (nth 5 parsed))
- (month (nth 4 parsed))
- (day (nth 3 parsed))
- ;; Format as YY-MM-DD
- (date-prefix (format "%02d-%02d-%02d: "
- (mod year 100) month day)))
- ;; Go back to the headline
- (goto-char (point-min))
- ;; Insert date prefix after the asterisks
- (when (looking-at "^\\(\\*+ \\)\\(.*\\)$")
- (replace-match (concat "\\1" date-prefix "\\2"))))))))
+ (let ((date-prefix (cj/org-capture--date-prefix (match-string 1))))
+ (when date-prefix
+ (goto-char (point-min))
+ (when (looking-at "^\\(\\*+ \\)\\(.*\\)$")
+ (replace-match (concat "\\1" date-prefix "\\2")))))))))
(defun cj/org-capture-event-content ()
"Get the appropriate content for event capture based on context.
@@ -56,7 +57,8 @@ formatted appropriately for insertion into the capture template."
;; If called from org-protocol (browser), get the initial from org-store-link-plist
((and (boundp 'org-store-link-plist)
org-store-link-plist
- (plist-get org-store-link-plist :initial))
+ (let ((val (plist-get org-store-link-plist :initial)))
+ (and (stringp val) (not (string-empty-p val)))))
(concat "\n" (plist-get org-store-link-plist :initial)))
;; If there's a selected region in Emacs, use it from capture plist
((and (stringp (plist-get org-capture-plist :initial))