From 9d0308a91baea467e69916381c0f62925218387a Mon Sep 17 00:00:00 2001 From: jao Date: Fri, 26 Mar 2021 00:13:59 +0000 Subject: RSS subscription generalised --- init.org | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----- w3m.org | 38 +------------------------------------- 2 files changed, 56 insertions(+), 42 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) diff --git a/w3m.org b/w3m.org index a66dd41..fd6e8da 100644 --- a/w3m.org +++ b/w3m.org @@ -185,42 +185,6 @@ (setq w3m-goto-article-function 'jao-w3m-browse-url) #+END_SRC -* Subscribe rss using r2e - #+begin_src emacs-lisp - (defconst jao-w3m-rss-rx - (concat "type=\"application/\\(?:atom\\|rss\\)\\+xml\" +" - "\\(?:title=\"\\([^\n\"]+\\)\" +\\)?href=\"\\([^\n\"]+\\)\"")) - - (defun jao-w3m-find-rss () - (when (eq major-mode 'w3m-mode) - (save-excursion - (w3m-view-source) - (goto-char (point-min)) - (let* ((m (re-search-forward jao-w3m-rss-rx nil t)) - (url (and m (match-string 2))) - (title (and m (match-string 1)))) - (w3m-view-source) - (cons url (or title "")))))) - - (defun jao-w3m-subscribe-rss () - (interactive) - (let* ((url (or (w3m-anchor) (ffap-url-at-point))) - (url+title (if url (cons url "") (jao-w3m-find-rss))) - (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 * Tweeting and tooting #+BEGIN_SRC emacs-lisp (defun jao-w3m--toot-text (from to title) @@ -365,6 +329,6 @@ (define-key w3m-mode-map "c" 'w3m-print-this-url) (define-key w3m-mode-map "v" 'jao-view-video) (define-key w3m-mode-map "V" 'w3m-download) - (define-key w3m-mode-map "x" 'jao-w3m-subscribe-rss) + (define-key w3m-mode-map "x" 'jao-rss-subscribe-rss) (define-key w3m-mode-map "Y" 'w3m-print-current-url) #+END_SRC -- cgit v1.2.3