summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/org-capture-config.el177
1 files changed, 69 insertions, 108 deletions
diff --git a/modules/org-capture-config.el b/modules/org-capture-config.el
index ef3b63f3..7b06db3c 100644
--- a/modules/org-capture-config.el
+++ b/modules/org-capture-config.el
@@ -2,11 +2,8 @@
;; author: Craig Jennings <c@cjennings.net>
;;; Commentary:
-;; Customizations related to org-capture and org-refile is here.
-;; This includes 'cj/org-webpage-clipper' functionality.
-
-;; To ensure the code below is only loaded after org-mode, all code is wrapped in an
-;; eval-after-load function.
+;; Customizations related to org-capture and org-refile.
+;; Includes capture templates for tasks, links, PDFs, EPUBs, emails, and drill questions.
;; bookmarklet code:
;; text
@@ -16,114 +13,83 @@
;; javascript:location.href='org-protocol://capture?template=p&url=%27+encodeURIComponent(location.href)+%27&title=%27+encodeURIComponent(document.title)+%27&body=%27+encodeURIComponent(window.getSelection())
;;; Code:
-(require 'user-constants)
(eval-when-compile (defvar drill-dir))
+(eval-when-compile (defvar inbox-file))
+(eval-when-compile (defvar gcal-file))
+(eval-when-compile (defvar schedule-file))
-;; -------------------------- Event Capture Formatting -------------------------
-
-;; Formats event headlines with YY-MM-DD prefix extracted from the scheduled date
-
-(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
-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"))))))))
-
-(defun cj/org-capture-event-content ()
- "Get the appropriate content for event capture based on context.
-Returns the selected text from either Emacs or browser (via org-protocol)
-formatted appropriately for insertion into the capture template."
- (cond
- ;; 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))
- (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))
- (not (string= (plist-get org-capture-plist :initial) "")))
- (concat "\n" (plist-get org-capture-plist :initial)))
- ;; Otherwise, return empty string
- (t "")))
-
-;; ----------------------- Org Capture PDF Active Region -----------------------
-;; allows capturing the selected region from within a PDF file.
-
-(defun cj/org-capture-pdf-active-region ()
- "Capture the active region of the pdf-view buffer.
-
-Intended to be called within an org capture template."
- (let* ((pdf-buf-name (plist-get org-capture-plist :original-buffer))
- (pdf-buf (get-buffer pdf-buf-name)))
- (if (buffer-live-p pdf-buf)
- (with-current-buffer pdf-buf
- (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) ""))))
+(defvar org-capture-plist)
+(defvar org-store-link-plist)
+(defvar org-capture-templates)
+(declare-function org-parse-time-string "org")
+(declare-function org-capture-get "org-capture")
+(declare-function pdf-view-active-region-text "pdf-view")
;; --------------------------- Org-Capture Templates ---------------------------
;; you can bring up the org capture menu with C-c c
(use-package org-protocol
:ensure nil ;; built-in
- :defer .5
:after org
:config
+
+ ;; -------------------------- Event Capture Formatting -------------------------
+
+ (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
+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"))))))))
+
+ (defun cj/org-capture-event-content ()
+ "Get the appropriate content for event capture based on context.
+Returns the selected text from either Emacs or browser (via org-protocol)
+formatted appropriately for insertion into the capture template."
+ (cond
+ ;; 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))
+ (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))
+ (not (string= (plist-get org-capture-plist :initial) "")))
+ (concat "\n" (plist-get org-capture-plist :initial)))
+ ;; Otherwise, return empty string
+ (t "")))
+
+ ;; ----------------------- Org Capture PDF Active Region -----------------------
+
+ (defun cj/org-capture-pdf-active-region ()
+ "Capture the active region of the pdf-view buffer.
+
+Intended to be called within an org capture template."
+ (let* ((pdf-buf-name (plist-get org-capture-plist :original-buffer))
+ (pdf-buf (get-buffer pdf-buf-name)))
+ (if (buffer-live-p pdf-buf)
+ (with-current-buffer pdf-buf
+ (car (pdf-view-active-region-text)))
+ (user-error "Buffer %S not alive" pdf-buf-name))))
+
;; ORG-CAPTURE TEMPLATES
(setq org-protocol-default-template-key "L")
(setq org-capture-templates
@@ -152,7 +118,7 @@ Captured On: %U" :prepend t)
("P" "PDF Text" entry (file+headline inbox-file "Inbox")
"* %?
#+BEGIN_QUOTE\n%(cj/org-capture-pdf-active-region)\n#+END_QUOTE
-Source:[[%L][%(buffer-name (org-capture-get :original-buffer))]]
+Source: [[%L][%(buffer-name (org-capture-get :original-buffer))]]
Captured On: %U" :prepend t)
("p" "Link with Selection" entry (file+headline inbox-file "Inbox")
@@ -191,10 +157,5 @@ Captured On: %U"
)) ;; 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.
-
-(keymap-global-set "C-T" (lambda () (interactive) (org-capture nil "t")))
-
(provide 'org-capture-config)
;;; org-capture-config.el ends here.