elfeed-link.el (2988B)
1 ;;; elfeed-link.el --- misc functions for elfeed -*- lexical-binding: t; -*- 2 3 ;; This is free and unencumbered software released into the public domain. 4 5 ;;; Commentary: 6 7 ;; Code for integration with org-mode. 8 9 ;; To use, add (require 'elfeed-link) somewhere in your configuration. 10 11 ;;; Code: 12 13 (require 'org) 14 (require 'cl-lib) 15 (require 'elfeed-db) 16 (require 'elfeed-show) 17 (require 'elfeed-search) 18 19 ;;;###autoload 20 (defun elfeed-link-store-link () 21 "Store a link to an elfeed search or entry buffer. 22 23 When storing a link to an entry, automatically extract all the 24 entry metadata. These can be used in the capture templates as 25 %:elfeed-entry-<prop>. See `elfeed-entry--create' for the list 26 of available props." 27 (cond ((derived-mode-p 'elfeed-search-mode) 28 (funcall (if (fboundp 'org-link-store-props) 29 #'org-link-store-props 30 (with-no-warnings #'org-store-link-props)) 31 :type "elfeed" 32 :link (format "elfeed:%s" elfeed-search-filter) 33 :description elfeed-search-filter)) 34 ((derived-mode-p 'elfeed-show-mode) 35 (apply 36 'org-store-link-props 37 :type "elfeed" 38 :link (format "elfeed:%s#%s" 39 (car (elfeed-entry-id elfeed-show-entry)) 40 (cdr (elfeed-entry-id elfeed-show-entry))) 41 :description (elfeed-entry-title elfeed-show-entry) 42 (cl-loop for prop in 43 (list 'id 'title 'link 'date 'content 'content-type 'enclosures 'tags 'feed-id 'meta) 44 nconc (list 45 (intern (concat ":elfeed-entry-" (symbol-name prop))) 46 (funcall 47 (intern (concat "elfeed-entry-" (symbol-name prop))) 48 elfeed-show-entry))))))) 49 50 ;;;###autoload 51 (defun elfeed-link-open (filter-or-id) 52 "Jump to an elfeed entry or search. 53 54 Depending on what FILTER-OR-ID looks like, we jump to either 55 search buffer or show a concrete entry." 56 (if (string-match "\\([^#]+\\)#\\(.+\\)" filter-or-id) 57 (elfeed-show-entry (elfeed-db-get-entry 58 (cons (match-string 1 filter-or-id) 59 (match-string 2 filter-or-id)))) 60 (elfeed) 61 (elfeed-search-set-filter filter-or-id))) 62 63 ;;;###autoload 64 (eval-after-load 'org 65 `(funcall 66 ;; The extra quote below is necessary because uncompiled closures 67 ;; do not evaluate to themselves. The quote is harmless for 68 ;; byte-compiled function objects. 69 ',(lambda () 70 (if (version< (org-version) "9.0") 71 (with-no-warnings 72 (org-add-link-type "elfeed" #'elfeed-link-open) 73 (add-hook 'org-store-link-functions #'elfeed-link-store-link)) 74 (with-no-warnings 75 (org-link-set-parameters 76 "elfeed" 77 :follow #'elfeed-link-open 78 :store #'elfeed-link-store-link)))))) 79 80 (provide 'elfeed-link) 81 82 ;;; elfeed-link.el ends here