summaryrefslogtreecommitdiff
path: root/modules/org-capture-config.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-26 12:41:45 -0500
committerCraig Jennings <c@cjennings.net>2024-04-26 12:41:45 -0500
commitab05460d1c89f5e6c3c060768e5e7e3003ad6dfc (patch)
tree4bbfa42b379c335547168a5b9f55d852c1fec681 /modules/org-capture-config.el
parent692b44d648472fdf52048f6040d223ea7befe755 (diff)
Web Page Clipper now saves articles under "To Read" heading in inbox
Diffstat (limited to 'modules/org-capture-config.el')
-rw-r--r--modules/org-capture-config.el94
1 files changed, 38 insertions, 56 deletions
diff --git a/modules/org-capture-config.el b/modules/org-capture-config.el
index 469abf52..6a2f9397 100644
--- a/modules/org-capture-config.el
+++ b/modules/org-capture-config.el
@@ -11,67 +11,46 @@
;;; Code:
-;; ---------------------- Org-Webpage-Clipper ----------------------
-;; Saves a copy of the page eww is visiting in the 'articles'-file for offline
-;; reading. In other words, it's a "Poor Man's Pocket/Instapaper"
+;; ---------------------------- Org Webpage Clipper ----------------------------
+;; Allows saving a copy of the page eww is visiting for offline reading.
+;; In other words, it's a "Pocket/Instapaper" that keeps the article in Emacs.
+;; Used in conjuction with org-capture-template "w" "Web Page Clipper" below.
+
(defun cj/org-webpage-clipper ()
"Capture a web page for later viewing in an org-file.
-Encodes all links and marks that may interfere with org mode
-display, then inserts the content into a file for later offline use.
-This is meant to be used in coordination with an org-capture-template.
-
-Example Template:
-
-,@
-(\"w\" \"Website\" plain (function cj/org-webpage-clipper)
-\"* %a\\nArticle Link: %L\\nCaptured On: %U\\n\\n\" :immediate-finish t)
-'@"
+ and Returns the yanked content as a string."
(interactive)
-
- ;; Ensure valid major mode before encoding
- (cond
- ((eq major-mode 'w3m-mode)
- (org-w3m-copy-for-org-mode))
- ((eq major-mode 'eww-mode)
- (org-eww-copy-for-org-mode))
- (t
- (error "Not valid -- must be in w3m or eww mode")))
-
- ;; Check for full path to the archive file. Create missing directories.
- (unless (file-exists-p article-file)
- (let ((dir (file-name-directory article-file)))
- (unless (file-exists-p dir)
- (make-directory dir))))
-
- ;; Move to end of file and insert blank line for org-capture to add timestamp, etc.
- (find-file article-file)
- (goto-char (point-max))
- (insert "\n\n\n\n\n")
-
- ;; Insert the web content keeping our place.
- (save-excursion (yank))
-
- ;; Remove page info from kill ring. Also, fix the yank pointer.
- (setq kill-ring (cdr kill-ring))
- (setq kill-ring-yank-pointer kill-ring)
-
- ;; Final repositioning.
- (forward-line -1))
-
-;;;; --------------------------------- Functions -------------------------------
+ (let* ((source-buffer (org-capture-get :original-buffer))
+ (source-mode (with-current-buffer source-buffer major-mode)))
+ (cond
+ ((eq source-mode 'w3m-mode)
+ (with-current-buffer source-buffer
+ (org-w3m-copy-for-org-mode)))
+ ((eq source-mode 'eww-mode)
+ (with-current-buffer source-buffer
+ (org-eww-copy-for-org-mode)))
+ (t
+ (error "Not valid -- must be in w3m or eww mode")))
+ ;; extract the webpage content from the kill ring
+ (car kill-ring)))
+
+
+;; ----------------------- 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))))
+ (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 -------------------------
+;; --------------------------- Org-Capture Templates ---------------------------
+;; you can bring up the org capture menu with C-c c
(use-package org-protocol
:ensure nil ;; built-in
@@ -93,7 +72,7 @@ Intended to be called within an org capture template."
Source: [[%:link][%(buffer-name (org-capture-get :original-buffer))]]
Captured On: %U" :prepend t)
- ;; requires cj/org-capture-pdf-active-region function defined above
+ ;; requires cj/org-capture-pdf-active-region function defined above
("P" "PDF Text" entry (file+headline inbox-file "Inbox")
"* %?
#+BEGIN_QUOTE\n%(cj/org-capture-pdf-active-region)\n#+END_QUOTE
@@ -123,10 +102,13 @@ Captured On: %U"
("s" "Shopping List Entry" entry
(file+headline inbox-file "Shopping List") "* %?")
- ;; requires cj/org-web-clipper function defined above
- ("w" "Web Page Clipper" plain
- (function cj/org-webpage-clipper)
- "* %a\nArticle Link: %L\nCaptured On: %U\n\n" :immediate-finish t))))
+ ;; requires cj/org-web-clipper function defined above
+ ("w" "Web Page Clipper" entry
+ (file+headline inbox-file "To Read")
+ "* %a\nURL: %L\nCaptured On:%U\n%(cj/org-webpage-clipper)\n"
+ :prepend t :immediate-finish 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.