summaryrefslogtreecommitdiff
path: root/modules/org-capture-config.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-10-20 12:56:32 -0500
committerCraig Jennings <c@cjennings.net>2025-10-20 12:56:32 -0500
commit92f8c8e9c773bfafc06c47a4e7d8aaaae7b83c3c (patch)
tree17c5f7e68c0a2a9e1e034e99dbdc7d06b0f4dc0c /modules/org-capture-config.el
parentbd45daa2e79fe148465304f0d469842e2047403d (diff)
feat: org-capture: Add drill capture helpers and templates
Introduce functions `cj/drill-source-link` and `cj/drill-answer-content` for generating source links and content in org-drill captures. Expand org-capture-templates with new entries for drill questions and PDF captures. Adjust key mappings with `keymap-global-set` for task capture. Enhance the org-drill configuration with new keybindings using `keymap-set`. Remove old capture template setup and update initialization sequences.
Diffstat (limited to 'modules/org-capture-config.el')
-rw-r--r--modules/org-capture-config.el58
1 files changed, 57 insertions, 1 deletions
diff --git a/modules/org-capture-config.el b/modules/org-capture-config.el
index b9ee84c5..ef3b63f3 100644
--- a/modules/org-capture-config.el
+++ b/modules/org-capture-config.el
@@ -17,6 +17,9 @@
;;; Code:
(require 'user-constants)
+
+(eval-when-compile (defvar drill-dir))
+
;; -------------------------- Event Capture Formatting -------------------------
;; Formats event headlines with YY-MM-DD prefix extracted from the scheduled date
@@ -76,6 +79,43 @@ Intended to be called within an org capture template."
(car (pdf-view-active-region-text)))
(user-error "Buffer %S not alive" pdf-buf-name))))
+;; ----------------------- Org Drill Capture Helpers -----------------------
+
+(defun cj/drill-source-link ()
+ "Generate appropriate source link based on capture context."
+ (cond
+ ;; org-protocol capture (bookmarklet from web)
+ ((org-capture-get :link)
+ (format "Source: [[%s][%s]]"
+ (org-capture-get :link)
+ (org-capture-get :description)))
+ ;; PDF capture
+ ((with-current-buffer (org-capture-get :original-buffer)
+ (derived-mode-p 'pdf-view-mode))
+ (format "Source: [[%s][%s]]"
+ (org-capture-get :annotation)
+ (buffer-name (org-capture-get :original-buffer))))
+ ;; EPUB or other
+ (t
+ (format "Source: [[%s][%s]]"
+ (or (org-capture-get :link) "")
+ (buffer-name (org-capture-get :original-buffer))))))
+
+(defun cj/drill-answer-content ()
+ "Get answer content, using PDF active region for PDF captures."
+ (cond
+ ;; PDF capture - use PDF active region
+ ((and (org-capture-get :original-buffer)
+ (with-current-buffer (org-capture-get :original-buffer)
+ (derived-mode-p 'pdf-view-mode)))
+ (cj/org-capture-pdf-active-region))
+ ;; org-protocol capture - initial content is in a plist property
+ ((plist-get org-store-link-plist :initial)
+ (plist-get org-store-link-plist :initial))
+ ;; Regular capture with %i expansion
+ (t
+ (or (org-capture-get :initial) ""))))
+
;; --------------------------- Org-Capture Templates ---------------------------
;; you can bring up the org capture menu with C-c c
@@ -132,13 +172,29 @@ Captured On: %U\n" :prepend t :immediate-finish t)
Captured On: %U"
:prepend t)
+ ("d" "Drill Question" entry
+ (file (lambda ()
+ (let ((files (directory-files drill-dir nil "^[^.].*\\.org$")))
+ (expand-file-name
+ (completing-read "Choose file: " files)
+ drill-dir))))
+ "* Item :drill:\n%?\n** Answer\n%i\nSource: [[%:link][%:description]]\nCaptured On: %U" :prepend t)
+
+ ("f" "Drill Question - PDF" entry
+ (file (lambda ()
+ (let ((files (directory-files drill-dir nil "^[^.].*\\.org$")))
+ (expand-file-name
+ (completing-read "Choose file: " files)
+ drill-dir))))
+ "* Item :drill:\n%?\n** Answer\n%(cj/org-capture-pdf-active-region)\nSource: [[%L][%(buffer-name (org-capture-get :original-buffer))]]\nCaptured On: %U" :prepend t)
+
)) ;; end setq
) ;; end use-package org-protocol
;; ---------------------------- Simple Task Capture ----------------------------
;; the simplest way to capture a task. Also a simple way to write this function.
-(define-key global-map (kbd "C-S-t") (kbd "C-c c t"))
+(keymap-global-set "C-T" (lambda () (interactive) (org-capture nil "t")))
(provide 'org-capture-config)
;;; org-capture-config.el ends here.