summaryrefslogtreecommitdiffhomepage
path: root/init.org
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2021-03-26 00:13:59 +0000
committerjao <jao@gnu.org>2021-03-26 00:13:59 +0000
commit9d0308a91baea467e69916381c0f62925218387a (patch)
tree7bd0383d37067ed30bfb478a30b040c6330ba989 /init.org
parenta3ee0744482ff9a6fb78a9c8e0067f863720ef47 (diff)
downloadelibs-9d0308a91baea467e69916381c0f62925218387a.tar.gz
elibs-9d0308a91baea467e69916381c0f62925218387a.tar.bz2
RSS subscription generalised
Diffstat (limited to 'init.org')
-rw-r--r--init.org60
1 files changed, 55 insertions, 5 deletions
diff --git a/init.org b/init.org
index 94f115f..dc0148d 100644
--- a/init.org
+++ b/init.org
@@ -2055,11 +2055,14 @@
#+end_src
*** Helpers
#+BEGIN_SRC emacs-lisp
- (defun jao-url-around-point ()
- (or (and (fboundp 'w3m-anchor) (w3m-anchor))
- (shr-url-at-point nil)
- (ffap-url-at-point)
- (thing-at-point 'url)))
+ (defun jao-url-around-point (&optional current-url)
+ (or (and (fboundp 'w3m-anchor) (w3m-anchor))
+ (shr-url-at-point nil)
+ (ffap-url-at-point)
+ (thing-at-point 'url)
+ (when current-url
+ (or (and (fboundp 'w3m-anchor) (w3m-anchor))
+ (and (derived-mode-p 'eww-mode) (plist-get eww-data :url))))))
(defun jao--fln (url)
(shell-quote-argument
@@ -2218,6 +2221,50 @@
(setq browse-url-browser-function jao-browse-url-function)
#+END_SRC
+*** Subscribe rss using r2e
+ #+begin_src emacs-lisp
+ (defconst jao-rss--rss-rx
+ (concat "type=\"application/\\(?:atom\\|rss\\)\\+xml\" +"
+ "\\(?:title=\"\\([^\n\"]+\\)\" +\\)?href=\"\\([^\n\"]+\\)\""))
+
+ (autoload 'View-quit "view")
+
+ (defun jao-rss--find-url ()
+ (when (derived-mode-p 'w3m-mode 'eww-mode)
+ (save-excursion
+ (if (derived-mode-p 'w3m-mode)
+ (w3m-view-source)
+ (eww-view-source))
+ (goto-char (point-min))
+ (let* ((m (re-search-forward jao-rss--rss-rx nil t))
+ (url (and m (match-string 2)))
+ (title (and m (match-string 1))))
+ (if (derived-mode-p 'w3m-mode)
+ (w3m-view-source)
+ (View-quit))
+ (when url (cons url (or title "")))))))
+
+ (defun jao-rss-subscribe ()
+ (interactive)
+ (let* ((url (or (jao-rss--find-url)
+ (jao-url-around-point)
+ (read-string "Feed URL: ")))
+ (url+title (if url (cons url "") (jao-rss--find-url)))
+ (url (car url+title))
+ (title (cdr url+title)))
+ (if url
+ (let ((url (if (string-match "^feed:" url)
+ (substring url 5) url)))
+ (when (y-or-n-p (format "Subscribe to <%s>? " url))
+ (let* ((name (read-string "Name: " title))
+ (cat (completing-read "Category: "
+ (jao-list-mailboxes "feeds")
+ nil t)))
+ (shell-command
+ (format "r2e add %s %s jao+feeds_%s@localhost && r2e run %s"
+ name url cat name)))))
+ (message "No feeds found"))))
+ #+end_src
*** emacs-w3m
#+begin_src emacs-lisp
(jao-load-org "w3m")
@@ -2228,6 +2275,9 @@
:custom ((jao-eww-session-duplicate-tabs 'ask)
(jao-eww-session-file "~/.emacs.d/eww-session.el")))
+ (require 'eww)
+ (define-key eww-mode-map "x" #'jao-rss-subscribe)
+
(defun jao-eww-browse-url (url &rest r)
"Browse URL using eww."
(jao-afio--goto-www)