summaryrefslogtreecommitdiff
path: root/modules
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
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')
-rw-r--r--modules/org-capture-config.el58
-rw-r--r--modules/org-drill-config.el79
2 files changed, 88 insertions, 49 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.
diff --git a/modules/org-drill-config.el b/modules/org-drill-config.el
index b678a813..dff132e2 100644
--- a/modules/org-drill-config.el
+++ b/modules/org-drill-config.el
@@ -5,24 +5,33 @@
;; Notes: Org-Drill
;; Start out your org-drill with C-d s, then select your file.
-;; the javascript bookmark I use to capture information from the web for org-drill files:
+;; Capture templates:
+;; - "d" for web/EPUB drill captures (uses %i for selected text, %:link for source)
+;; - "f" for PDF drill captures (uses special PDF region extraction)
+
+;; The javascript bookmarklet for capturing from web to org-drill:
;; javascript:location.href='org-protocol://capture?template=d&url=%27+encodeURIComponent(location.href)+%27&title=%27+encodeURIComponent(document.title)+%27&body=%27+encodeURIComponent(window.getSelection());void(0);
-;; create a new bookmark and add "Drill Entry" to the name field and the above
-;; snippet to the URL field.
+;; Create a bookmark, add "Drill Entry" to the name field and the above snippet to the URL field.
;;; Code:
-(require 'user-constants)
-(require 'org-capture-config) ;; for adding org-capture-templates
-(require 'cl-lib)
+(eval-when-compile (defvar drill-dir))
+(eval-when-compile (defvar cj/custom-keymap))
+
+(defvar cj/drill-map)
+(declare-function org-drill-resume "org-drill")
+(declare-function cj/drill-map "org-drill-config")
+(declare-function cj/drill-start "org-drill-config")
+(declare-function cj/drill-edit "org-drill-config")
+(declare-function cj/drill-capture "org-drill-config")
+(declare-function cj/drill-refile "org-drill-config")
;; --------------------------------- Org Drill ---------------------------------
(use-package org-drill
- :after org
+ :after (org org-capture)
:commands org-drill
- :defer 0.5
:config
(setq org-drill-leech-failure-threshold 50) ;; leech cards = 50 wrong anwers
(setq org-drill-leech-method 'warn) ;; leech cards show warnings
@@ -43,8 +52,9 @@
(defun cj/drill-edit ()
"Prompts the user to pick a drill org file, then opens it for editing."
(interactive)
- (let* ((choices (directory-files drill-dir nil "^[^.].*\\.org$")))
- (find-file chosen-drill-file)))
+ (let* ((choices (directory-files drill-dir nil "^[^.].*\\.org$"))
+ (chosen-drill-file (completing-read "Choose Flashcard File:" choices)))
+ (find-file (concat drill-dir chosen-drill-file))))
(defun cj/drill-capture ()
"Quickly capture a drill question."
@@ -58,44 +68,17 @@
(drill-dir :maxlevel . 1)))
(call-interactively 'org-refile))
- ;; add useful org drill capture templates
- (setq org-capture-templates
- (append org-capture-templates
- '(("d" "Drill Question - Web" 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)
-
- ("b" "Drill Question - EPUB" 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][%(buffer-name (org-capture-get :original-buffer))]]\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)))))
-
-;; ------------------------------ Org Drill Keymap -----------------------------
-
-;; Buffer & file operations prefix and keymap
-(define-prefix-command 'cj/drill-map nil
- "Keymap for org-drill.")
-(define-key cj/custom-keymap "D" 'cj/drill-map)
-(define-key cj/drill-map "s" 'cj/drill-start)
-(define-key cj/drill-map "e" 'cj/drill-edit)
-(define-key cj/drill-map "c" 'cj/drill-capture)
-(define-key cj/drill-map "r" 'cj/drill-refile)
-(define-key cj/drill-map "R" 'org-drill-resume)
+ ;; ------------------------------ Org Drill Keymap -----------------------------
+
+ ;; Buffer & file operations prefix and keymap
+ (define-prefix-command 'cj/drill-map nil
+ "Keymap for org-drill.")
+ (keymap-set cj/custom-keymap "D" #'cj/drill-map)
+ (keymap-set cj/drill-map "s" #'cj/drill-start)
+ (keymap-set cj/drill-map "e" #'cj/drill-edit)
+ (keymap-set cj/drill-map "c" #'cj/drill-capture)
+ (keymap-set cj/drill-map "r" #'cj/drill-refile)
+ (keymap-set cj/drill-map "R" #'org-drill-resume))
(provide 'org-drill-config)
;;; org-drill-config.el ends here.