2012-07-25 01:49:02 +02:00
|
|
|
;;; avandu.el --- Gateway to Tiny Tiny RSS
|
|
|
|
|
|
|
|
;; Copyright (C) 2012 Tom Willemsen <tom@ryuslash.org>
|
|
|
|
|
|
|
|
;; Author: Tom Willemsen <tom@ryuslash.org>
|
|
|
|
;; Created: Jul 22, 2012
|
|
|
|
;; Version: 0
|
|
|
|
;; Keywords: net
|
|
|
|
|
|
|
|
;; Permission to use, copy, modify, and distribute this software for any
|
|
|
|
;; purpose with or without fee is hereby granted, provided that the
|
|
|
|
;; above copyright notice and this permission notice appear in all
|
|
|
|
;; copies.
|
|
|
|
|
|
|
|
;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
|
|
|
;; WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
|
|
|
;; WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
|
|
|
;; AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
|
|
|
|
;; CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
|
|
;; OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
;; NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
;; CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
2012-08-22 12:44:50 +02:00
|
|
|
;; Avandu is an emacs mode that connects to a Tiny Tiny RSS
|
|
|
|
;; (http://tt-rss.org) instance and allows you to read the feeds it
|
|
|
|
;; has gathered.
|
2012-08-02 22:22:34 +02:00
|
|
|
|
|
|
|
;; The simplest way to install it is to use package.el:
|
|
|
|
|
|
|
|
;; (package-install-file "/path/to/avandu.el")
|
|
|
|
|
|
|
|
;; For further information I would like to refer you to the avandu
|
|
|
|
;; info file.
|
|
|
|
|
|
|
|
;; Once installation is out of the way, it should get a value for
|
|
|
|
;; `avandu-tt-rss-api-url' (for example: http://tt-rss.org/demo/api/)
|
2012-08-04 16:10:42 +02:00
|
|
|
;; and then run `avandu-overview'.
|
2012-08-02 22:22:34 +02:00
|
|
|
|
|
|
|
;; Once in avandu:overview mode some key bindings will be:
|
|
|
|
|
|
|
|
;; - `r' :: Mark article at point as read.
|
|
|
|
;; - `o' :: Open article at point in a browser. Uses `browse-url'.
|
|
|
|
;; - `n' :: Next article.
|
|
|
|
;; - `p' :: Previous article.
|
2012-07-25 01:49:02 +02:00
|
|
|
|
|
|
|
;;; Code:
|
2014-02-15 16:39:09 +01:00
|
|
|
|
2012-08-07 09:47:43 +02:00
|
|
|
(require 'auth-source)
|
2012-07-25 01:49:02 +02:00
|
|
|
(require 'json)
|
2012-08-02 22:24:45 +02:00
|
|
|
(require 'simple)
|
2012-08-07 09:47:43 +02:00
|
|
|
(require 'url)
|
2014-02-15 16:39:09 +01:00
|
|
|
(require 'view)
|
2012-07-25 01:49:02 +02:00
|
|
|
|
2012-08-03 22:46:15 +02:00
|
|
|
(defconst avandu-entity-replacement-alist
|
|
|
|
'(("hellip" . 8230)
|
|
|
|
("qout" . 34)
|
|
|
|
("amp" . 38)
|
|
|
|
("nbsp" . 32))
|
2014-02-14 01:17:11 +01:00
|
|
|
"What to replace certain HTML entities with.")
|
2012-08-03 22:46:15 +02:00
|
|
|
|
2012-08-04 00:30:15 +02:00
|
|
|
(defconst avandu-overview-mode-name "Avandu:Overview"
|
|
|
|
"The default name for `avandu-overview-mode'.")
|
|
|
|
|
2012-08-03 23:58:15 +02:00
|
|
|
(defconst avandu-version 0
|
|
|
|
"The current version of avandu.")
|
|
|
|
|
2012-08-03 22:46:15 +02:00
|
|
|
;; Customization
|
2012-07-25 01:49:02 +02:00
|
|
|
(defgroup avandu nil
|
2012-07-26 00:43:30 +02:00
|
|
|
"Tiny Tiny RSS interface for emacs."
|
2012-07-25 01:49:02 +02:00
|
|
|
:group 'applications)
|
|
|
|
|
2012-08-03 22:46:15 +02:00
|
|
|
;; Faces
|
|
|
|
(defface avandu-overview-excerpt
|
|
|
|
'((t (:inherit shadow :slant italic)))
|
|
|
|
"Face for article excerpts in avandu overview."
|
|
|
|
:group 'avandu)
|
|
|
|
|
2012-07-25 01:49:02 +02:00
|
|
|
(defface avandu-overview-feed
|
|
|
|
'((((class color)
|
|
|
|
(background dark))
|
|
|
|
(:foreground "white" :height 1.2 :bold t :family "sans"))
|
|
|
|
(((class color)
|
|
|
|
(background light))
|
|
|
|
(:foreground "black" :height 1.2 :bold t :family "sans")))
|
|
|
|
"Face for feed titles in avandu overview."
|
|
|
|
:group 'avandu)
|
|
|
|
|
|
|
|
(defface avandu-overview-read-article
|
|
|
|
'((((class color)
|
|
|
|
(background dark))
|
|
|
|
(:foreground "white" :weight normal :family "sans"))
|
|
|
|
(((class color)
|
|
|
|
(background light))
|
|
|
|
(:foreground "black" :weight normal :family "sans")))
|
|
|
|
"Face for read article titles in avandu overview."
|
|
|
|
:group 'avandu)
|
|
|
|
|
2012-08-03 22:46:15 +02:00
|
|
|
(defface avandu-overview-unread-article
|
|
|
|
'((((class color)
|
|
|
|
(background dark))
|
|
|
|
(:foreground "orange3" :weight bold :family "sans"))
|
|
|
|
(((class color)
|
|
|
|
(background light))
|
|
|
|
(:foregroung "red4" :weight bold :family "sans")))
|
|
|
|
"Face for unread article titles in avandu overview."
|
2012-07-26 00:49:18 +02:00
|
|
|
:group 'avandu)
|
|
|
|
|
2012-08-22 12:44:50 +02:00
|
|
|
(defface avandu-article-title
|
|
|
|
'((((class color)
|
|
|
|
(background dark))
|
|
|
|
(:foreground "orange3" :weight bold :family "sans"))
|
|
|
|
(((class color)
|
|
|
|
(background light))
|
|
|
|
(:foreground "red4" :weight bold :family "sans")))
|
|
|
|
"Face for titles in avandu article view."
|
|
|
|
:group 'avandu)
|
|
|
|
|
|
|
|
(defface avandu-article-author
|
|
|
|
'((t (:inherit shadow :slant italic :height 0.9)))
|
|
|
|
"Face for the author's name in avandu article view."
|
|
|
|
:group 'avandu)
|
|
|
|
|
2012-08-03 22:46:15 +02:00
|
|
|
;; User options
|
2014-02-15 13:55:59 +01:00
|
|
|
(defcustom avandu-article-render-function #'shr-render-region
|
2012-08-22 23:08:42 +02:00
|
|
|
"A function to call that will render the content of an article."
|
|
|
|
:group 'avandu
|
|
|
|
:type 'function)
|
|
|
|
|
2012-08-02 22:24:11 +02:00
|
|
|
(defcustom avandu-tt-rss-api-url nil
|
2014-02-14 01:17:11 +01:00
|
|
|
"URL of your Tiny Tiny RSS instance.
|
|
|
|
|
|
|
|
For example: http://tt-rss.org/demo/api/"
|
2012-08-02 22:24:11 +02:00
|
|
|
:group 'avandu
|
|
|
|
:type 'string)
|
|
|
|
|
2012-08-22 23:08:42 +02:00
|
|
|
(defcustom avandu-html2text-command nil
|
|
|
|
"Shell command to call to change HTML to plain text."
|
2012-08-03 23:37:27 +02:00
|
|
|
:group 'avandu
|
|
|
|
:type 'string)
|
|
|
|
|
2012-08-22 23:08:42 +02:00
|
|
|
(defcustom avandu-user nil
|
|
|
|
"Username of your Tiny Tiny RSS account."
|
2012-08-22 12:44:50 +02:00
|
|
|
:group 'avandu
|
|
|
|
:type 'string)
|
|
|
|
|
2014-02-15 16:38:54 +01:00
|
|
|
(defcustom avandu-next-button-fallback-function #'shr-next-link
|
|
|
|
"The fallback function to use when `avandu-next-button' fails.
|
|
|
|
|
|
|
|
Your HTML renderer might not create links the same way avandu
|
|
|
|
does, as is the case with `shr'. This will try the specified
|
|
|
|
function, if avandu can't find a next link, before giving up.
|
|
|
|
|
|
|
|
The specified value should be a function that can take 0
|
|
|
|
arguments."
|
|
|
|
:group 'avandu
|
|
|
|
:type 'function)
|
|
|
|
|
|
|
|
(defcustom avandu-previous-button-fallback-function #'shr-previous-link
|
|
|
|
"The fallback function to use when `avandu-previous-button' fails.
|
|
|
|
|
|
|
|
Your HTML renderer might not create links the same way avandu
|
|
|
|
does, as is the case with `shr'. This will try the specified
|
|
|
|
function, if avandu can't find a next link, before giving up.
|
|
|
|
|
|
|
|
The specified value should be a function that can take 0
|
|
|
|
arguments."
|
|
|
|
:group 'avandu
|
|
|
|
:type 'function)
|
|
|
|
|
2012-08-03 22:46:15 +02:00
|
|
|
;; Variables
|
2012-07-25 01:49:02 +02:00
|
|
|
(defvar avandu--session-id nil
|
2014-02-14 01:17:11 +01:00
|
|
|
"*Internal* Session id for avandu.")
|
2012-07-25 01:49:02 +02:00
|
|
|
|
|
|
|
(defvar avandu-article-button-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(set-keymap-parent map button-map)
|
|
|
|
(define-key map "o" 'avandu-browse-article)
|
2012-08-22 12:44:50 +02:00
|
|
|
(define-key map "r" #'(lambda ()
|
|
|
|
(interactive)
|
|
|
|
(let ((button (button-at (point))))
|
|
|
|
(avandu-mark-article-read
|
|
|
|
(button-get button 'article-id))
|
|
|
|
(avandu-ui-mark-article-read button))))
|
2016-12-26 16:07:21 +01:00
|
|
|
(define-key map "u" #'(lambda ()
|
|
|
|
(interactive)
|
|
|
|
(let ((button (button-at (point))))
|
|
|
|
(avandu-mark-article-unread
|
|
|
|
(button-get button 'article-id))
|
|
|
|
(avandu-ui-mark-article-unread button))))
|
2012-07-25 01:49:02 +02:00
|
|
|
map)
|
2012-07-26 00:43:30 +02:00
|
|
|
"Keymap for articles in `avandu-overview-mode'.")
|
2012-07-25 01:49:02 +02:00
|
|
|
|
2012-08-03 22:46:15 +02:00
|
|
|
(defvar avandu-feed-button-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(set-keymap-parent map button-map)
|
|
|
|
(define-key map "c" 'avandu-feed-catchup)
|
|
|
|
map)
|
|
|
|
"Keymap for feeds in `avandu-overview-mode'.")
|
|
|
|
|
2012-07-25 01:49:02 +02:00
|
|
|
(defvar avandu-overview-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(set-keymap-parent map special-mode-map)
|
|
|
|
(define-key map "n" 'avandu-next-article)
|
|
|
|
(define-key map "N" 'avandu-next-feed)
|
|
|
|
(define-key map "p" 'avandu-previous-article)
|
|
|
|
(define-key map "P" 'avandu-previous-feed)
|
|
|
|
map)
|
2012-07-26 00:43:30 +02:00
|
|
|
"Keymap for `avandu-overview-mode'.")
|
2012-07-25 01:49:02 +02:00
|
|
|
|
2014-02-15 16:38:54 +01:00
|
|
|
(defvar avandu-article-mode-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
2014-03-03 21:45:24 +01:00
|
|
|
(set-keymap-parent map special-mode-map)
|
2014-02-15 16:38:54 +01:00
|
|
|
(define-key map (kbd "TAB") #'avandu-next-button)
|
|
|
|
(define-key map (kbd "<backtab>") #'avandu-previous-button)
|
|
|
|
map)
|
|
|
|
"Keymap for `avandu-atricle-mode'.")
|
|
|
|
|
2012-08-03 22:46:15 +02:00
|
|
|
(defvar avandu-password nil
|
|
|
|
"Password for your Tiny Tiny RSS account.")
|
2012-07-27 01:44:14 +02:00
|
|
|
|
2012-08-03 22:46:15 +02:00
|
|
|
;; Macros
|
|
|
|
(defmacro avandu--next-button-of-type (direction type)
|
|
|
|
"Go DIRECTION and find the next button of a TYPE."
|
2014-03-05 22:43:52 +01:00
|
|
|
(let ((prop (cl-case type
|
2012-08-03 22:46:15 +02:00
|
|
|
(feed 'feed-id)
|
|
|
|
(article 'article-id)
|
|
|
|
(t (error "Invalid type"))))
|
2014-03-05 22:43:52 +01:00
|
|
|
(next-point-function (cl-case direction
|
2012-08-03 22:46:15 +02:00
|
|
|
(forward 'point-min)
|
|
|
|
(backward 'point-max)
|
|
|
|
(t (error "Invalid direction"))))
|
2014-03-05 22:43:52 +01:00
|
|
|
(next-button-function (cl-case direction
|
2012-08-03 22:46:15 +02:00
|
|
|
(forward 'next-button)
|
|
|
|
(backward 'previous-button)
|
|
|
|
(t (error "Invalid direction")))))
|
|
|
|
`(let ((pos (point))
|
|
|
|
found-value)
|
|
|
|
(while (not found-value)
|
|
|
|
(let ((button (,next-button-function pos)))
|
|
|
|
(unless button
|
|
|
|
(setq pos (,next-point-function)
|
|
|
|
button (or (button-at pos)
|
|
|
|
(,next-button-function pos))))
|
|
|
|
(setq found-value (button-get button ',prop)
|
|
|
|
pos (overlay-start button))))
|
|
|
|
(goto-char pos))))
|
2012-07-26 00:43:30 +02:00
|
|
|
|
2012-08-03 22:46:15 +02:00
|
|
|
(defmacro avandu-getset (var prompt &optional passwdp)
|
2014-02-14 01:17:11 +01:00
|
|
|
"Ask the user for VAR with PROMPT.
|
|
|
|
|
|
|
|
After getting the answer from the user save the value. Use
|
2012-08-03 22:46:15 +02:00
|
|
|
`read-passwd' if PASSWDP and `read-string' otherwise."
|
|
|
|
`(or ,var (setq ,var (,(if passwdp 'read-passwd 'read-string)
|
|
|
|
,prompt))))
|
|
|
|
|
2012-08-22 12:44:50 +02:00
|
|
|
(defmacro avu-prop (element property)
|
2014-02-14 01:17:11 +01:00
|
|
|
"Look in ELEMENT for PROPERTY."
|
2012-08-22 12:44:50 +02:00
|
|
|
`(cdr (assq (quote ,property) ,element)))
|
|
|
|
|
2012-08-03 22:46:15 +02:00
|
|
|
;; Internal
|
|
|
|
(defun avandu--check-login ()
|
2014-02-14 01:17:11 +01:00
|
|
|
"Check to see if we're (still) logged in.
|
|
|
|
|
|
|
|
Try to login otherwise. Signals an error if we're not logged in
|
|
|
|
*and* login was unsuccesful."
|
2012-08-03 22:46:15 +02:00
|
|
|
(unless (or (and avandu--session-id (avandu-logged-in-p))
|
|
|
|
(avandu-login))
|
|
|
|
(avandu--clear-data)
|
|
|
|
(error "Could not log in to tt-rss")))
|
|
|
|
|
|
|
|
(defun avandu--clean-text (text)
|
2014-02-14 01:17:11 +01:00
|
|
|
"Go through TEXT and remove any trailing and leading whitespace.
|
|
|
|
|
|
|
|
Then look for any HTML entities and either replace them with
|
|
|
|
their char value or with the value in
|
2012-08-03 22:46:15 +02:00
|
|
|
`avandu-entity-replacement-alist'."
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert text)
|
|
|
|
(while (re-search-forward
|
|
|
|
"\\`[[:space:][:cntrl:]]+\\|[[:space:][:cntrl:]]+\\'" nil t)
|
|
|
|
(replace-match ""))
|
|
|
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (search-forward "&" nil t)
|
|
|
|
(let ((pos (point)))
|
|
|
|
(save-excursion
|
|
|
|
(when (search-forward ";" nil t)
|
|
|
|
(let* ((sstring (buffer-substring pos (1- (point))))
|
|
|
|
(char-code
|
|
|
|
(if (= (char-after pos) ?#)
|
|
|
|
(unless (string-match-p "[^[:digit:]]"
|
|
|
|
(substring sstring 1))
|
|
|
|
(string-to-number (substring sstring 1)))
|
|
|
|
(assoc sstring avandu-entity-replacement-alist))))
|
|
|
|
(when char-code
|
|
|
|
(delete-region (1- pos) (point))
|
|
|
|
(insert-char (if (consp char-code)
|
|
|
|
(cdr char-code)
|
|
|
|
char-code) 1)))))))
|
|
|
|
|
|
|
|
(setq text (buffer-string)))
|
|
|
|
text)
|
2012-07-25 01:49:02 +02:00
|
|
|
|
2012-07-28 22:49:18 +02:00
|
|
|
(defun avandu--clear-data ()
|
2014-02-14 01:17:11 +01:00
|
|
|
"Clean up login data. Clean the slate for next time."
|
2012-07-28 22:49:18 +02:00
|
|
|
(setq avandu-user nil
|
2012-08-03 22:46:15 +02:00
|
|
|
avandu--session-id nil)
|
2012-08-06 21:07:33 +02:00
|
|
|
|
|
|
|
(if (stringp avandu-password)
|
|
|
|
(clear-string avandu-password)
|
|
|
|
(setq avandu-password nil)))
|
|
|
|
|
|
|
|
(defun avandu--get-credentials ()
|
2014-02-14 01:17:11 +01:00
|
|
|
"Get a username and password for Tiny Tiny RSS.
|
|
|
|
|
|
|
|
Try it first with `auth-source-search' and then by asking the
|
|
|
|
user."
|
2012-08-06 21:07:33 +02:00
|
|
|
(let ((credentials (auth-source-search :max 1
|
|
|
|
:host avandu-tt-rss-api-url
|
|
|
|
:type 'netrc
|
|
|
|
:require '(:user :secret)
|
|
|
|
:user avandu-user)))
|
|
|
|
(if credentials
|
|
|
|
(setq avandu-user (plist-get (car credentials) :user)
|
|
|
|
avandu-password (plist-get (car credentials) :secret))
|
|
|
|
(avandu-getset avandu-user "Username: ")
|
|
|
|
(avandu-getset avandu-password "Password: " t))))
|
2012-08-03 22:46:15 +02:00
|
|
|
|
|
|
|
(defun avandu--get-session-id (results)
|
|
|
|
"Get the session id from RESULTS."
|
2012-08-22 12:44:50 +02:00
|
|
|
(avu-prop (assq 'content results) session_id))
|
2012-07-28 22:49:18 +02:00
|
|
|
|
2012-07-25 01:49:02 +02:00
|
|
|
(defun avandu--get-status-id (results)
|
|
|
|
"Get the status id from RESULTS."
|
2012-08-22 12:44:50 +02:00
|
|
|
(avu-prop results status))
|
2012-07-25 01:49:02 +02:00
|
|
|
|
2012-08-03 22:46:15 +02:00
|
|
|
(defun avandu--insert-article-excerpt (excerpt)
|
2014-02-14 01:17:11 +01:00
|
|
|
"Insert EXCERPT of an article."
|
2012-08-03 22:46:15 +02:00
|
|
|
(let ((start-pos (point))
|
|
|
|
end-pos
|
2012-08-07 09:49:08 +02:00
|
|
|
(text (avandu--oneline excerpt)))
|
2012-08-03 22:46:15 +02:00
|
|
|
(unless (or (not text) (string= text ""))
|
|
|
|
(insert
|
|
|
|
(propertize
|
|
|
|
text
|
|
|
|
'face 'avandu-overview-excerpt))
|
|
|
|
(indent-region start-pos (point) tab-width)
|
|
|
|
(fill-region start-pos (point))
|
|
|
|
(insert-char ?\n 1))))
|
2012-07-25 01:49:02 +02:00
|
|
|
|
2012-08-03 22:46:15 +02:00
|
|
|
(defun avandu--insert-article-title (id link title)
|
2014-02-14 01:17:11 +01:00
|
|
|
"Insert a button.
|
|
|
|
|
|
|
|
Store ID and LINK in the `article-id' and `link' properties
|
|
|
|
respectively, use TITLE as the text for the button."
|
2012-08-07 10:57:23 +02:00
|
|
|
(let ((pos (point)))
|
|
|
|
(insert-button
|
|
|
|
(avandu--oneline title)
|
|
|
|
'face 'avandu-overview-unread-article
|
|
|
|
'article-id id
|
|
|
|
'link link
|
|
|
|
'keymap avandu-article-button-map
|
|
|
|
'action #'(lambda (button)
|
2012-08-22 12:44:50 +02:00
|
|
|
(avandu-view-article (button-get button 'article-id))))
|
|
|
|
|
2012-08-07 10:57:23 +02:00
|
|
|
(fill-region pos (point))
|
|
|
|
(insert-char ?\n 1)))
|
2012-07-25 01:49:02 +02:00
|
|
|
|
2012-08-03 22:46:15 +02:00
|
|
|
(defun avandu--insert-feed-title (id title)
|
2014-02-14 01:17:11 +01:00
|
|
|
"Insert a button.
|
|
|
|
|
|
|
|
Store ID in the `feed-id' property and use TITLE as the text of
|
|
|
|
the button."
|
2012-08-03 22:46:15 +02:00
|
|
|
(unless (eq (point) (point-min)) (insert-char ?\n 1))
|
2012-08-07 10:57:23 +02:00
|
|
|
|
|
|
|
(let ((pos (point)))
|
|
|
|
(insert-button
|
|
|
|
(avandu--oneline title)
|
|
|
|
'face 'avandu-overview-feed
|
|
|
|
'feed-id id
|
|
|
|
'keymap avandu-feed-button-map
|
|
|
|
'action #'(lambda (button)
|
|
|
|
(message "%s" (button-label button))))
|
|
|
|
(fill-region pos (point))
|
|
|
|
(insert-char ?\n 2)))
|
2012-07-25 01:49:02 +02:00
|
|
|
|
2012-08-07 09:49:08 +02:00
|
|
|
(defun avandu--oneline (text)
|
|
|
|
"Make a single line out of and clean up TEXT."
|
|
|
|
(replace-regexp-in-string "[ \n\t]*$" "" (avandu--clean-text text)))
|
|
|
|
|
2012-08-06 21:07:33 +02:00
|
|
|
(defun avandu--password ()
|
2014-02-14 01:17:11 +01:00
|
|
|
"Get the password.
|
|
|
|
|
|
|
|
This means either return `avandu-password' as-is, or if it's a
|
|
|
|
function return the result of that function."
|
2012-08-06 21:07:33 +02:00
|
|
|
(if (functionp avandu-password)
|
|
|
|
(funcall avandu-password)
|
|
|
|
avandu-password))
|
|
|
|
|
2012-08-22 22:05:16 +02:00
|
|
|
(defun avandu--prep-params (data)
|
|
|
|
"Prepare DATA to be sent to Tiny Tiny RSS."
|
|
|
|
(json-encode (if avandu--session-id
|
|
|
|
(append `((sid . ,avandu--session-id))
|
|
|
|
data)
|
|
|
|
data)))
|
|
|
|
|
|
|
|
(defun avandu--send-command-async (data func)
|
|
|
|
"Send a command with parameters DATA to tt-rss asynchronously.
|
2014-02-14 01:17:11 +01:00
|
|
|
|
|
|
|
The current session-id is added to the request and then DATA is
|
|
|
|
passed on to `json-encode'.
|
2012-08-22 22:05:16 +02:00
|
|
|
|
|
|
|
DATA should be an association list with at least an OP value.
|
|
|
|
|
|
|
|
FUNC should be a callback function as defined by
|
|
|
|
`url-retrieve'."
|
|
|
|
(let* ((url-request-data (avandu--prep-params data))
|
|
|
|
(url-request-method "POST"))
|
|
|
|
(unless (url-retrieve avandu-tt-rss-api-url func)
|
|
|
|
(message "Complete."))))
|
|
|
|
|
2012-08-23 09:21:47 +02:00
|
|
|
(defun avandu--send-command-sync (data &optional raw)
|
2014-02-14 01:17:11 +01:00
|
|
|
"Send a command with parameters DATA to tt-rss.
|
|
|
|
|
|
|
|
The current session-id is added to the request and then DATA is
|
|
|
|
passed on to `json-encode'.
|
2012-07-26 00:43:30 +02:00
|
|
|
|
|
|
|
DATA should be an association list with at least an OP value.
|
|
|
|
For example:
|
|
|
|
|
2012-08-22 22:05:16 +02:00
|
|
|
(avandu--send-command-sync '((op . \"isLoggedIn\")))
|
2012-07-26 00:43:30 +02:00
|
|
|
|
2012-08-23 09:21:47 +02:00
|
|
|
This function returns the content part of the result of
|
|
|
|
`json-read' passed over the returned json, unless RAW is non-nil,
|
|
|
|
in which case the result is returned as-is."
|
2012-08-22 22:05:16 +02:00
|
|
|
(let* ((url-request-data (avandu--prep-params data))
|
2012-07-25 01:49:02 +02:00
|
|
|
(url-request-method "POST")
|
|
|
|
(buffer (url-retrieve-synchronously avandu-tt-rss-api-url))
|
|
|
|
result)
|
|
|
|
(with-current-buffer buffer
|
|
|
|
(goto-char (point-min))
|
|
|
|
(search-forward "\n\n")
|
|
|
|
(setq result (json-read)))
|
|
|
|
(kill-buffer buffer)
|
2012-08-23 09:21:47 +02:00
|
|
|
(if (not raw)
|
|
|
|
(avu-prop result content)
|
|
|
|
result)))
|
2012-07-25 01:49:02 +02:00
|
|
|
|
2012-08-04 02:28:18 +02:00
|
|
|
(defun avandu-categories (&optional unread)
|
2014-02-14 01:17:11 +01:00
|
|
|
"Get the created categories.
|
|
|
|
|
|
|
|
If UNREAD is non-nil only get categories with feeds with unread
|
|
|
|
articles in them."
|
2014-04-12 22:49:31 +02:00
|
|
|
(let ((hash (make-hash-table :test 'equal)))
|
|
|
|
(mapc (lambda (category)
|
|
|
|
(setf (gethash (cdr (assq 'title category)) hash)
|
|
|
|
(cdr (assq 'id category))))
|
|
|
|
(avandu--send-command-sync
|
|
|
|
`((op . "getCategories")
|
|
|
|
,@(when unread `((unread_only . ,unread))))))
|
|
|
|
hash))
|
2012-07-25 01:49:02 +02:00
|
|
|
|
2012-08-04 01:31:55 +02:00
|
|
|
(defun avandu-feeds (&optional category unread limit offset)
|
2014-02-14 01:17:11 +01:00
|
|
|
"Get the subscribed feeds.
|
|
|
|
|
|
|
|
If CATEGORY has been specified show only the feeds in CATEGORY.
|
|
|
|
If UNREAD has been specified only show feeds with unread articles
|
|
|
|
in them. Only fets LIMIT number of feeds, starting from OFFSET.
|
2012-08-04 01:31:55 +02:00
|
|
|
|
|
|
|
There are a number of special category IDs:
|
|
|
|
0 -- Uncategorized feeds
|
|
|
|
-1 -- Special (e.g. Starred, Published, Archived, etc.) feeds
|
|
|
|
-2 -- Labels
|
|
|
|
-3 -- All feeds, excluding virtual feeds (e.g. Labels and such)
|
|
|
|
-4 -- All feeds, including virtual feeds"
|
2012-08-22 22:05:16 +02:00
|
|
|
(avandu--send-command-sync
|
2012-08-22 12:44:50 +02:00
|
|
|
`((op . "getFeeds")
|
|
|
|
,@(when category `((cat_id . ,category)))
|
|
|
|
,@(when unread `((unread_only . ,unread)))
|
|
|
|
,@(when limit `((limit . ,limit)))
|
|
|
|
,@(when offset `((offset . ,offset))))))
|
2012-08-04 01:31:55 +02:00
|
|
|
|
2014-04-12 23:26:16 +02:00
|
|
|
(defun avandu--all-feeds-hash ()
|
|
|
|
"Get a hashtable of all feeds subsrcibed to in tt-rss."
|
|
|
|
(let ((hash (make-hash-table :test 'equal)))
|
|
|
|
(mapc (lambda (feed)
|
|
|
|
(setf (gethash (cdr (assq 'title feed)) hash)
|
|
|
|
(cdr (assq 'id feed))))
|
|
|
|
(avandu-feeds -3))
|
|
|
|
hash))
|
|
|
|
|
2012-08-04 18:07:23 +02:00
|
|
|
(defun avandu-headlines (feed-id &rest plist)
|
2014-02-14 01:17:11 +01:00
|
|
|
"Get a list of headlines from Tiny Tiny RSS.
|
|
|
|
|
|
|
|
Get the ones for the feed identified by FEED-ID. Options about
|
|
|
|
what to get can be specified in the form of a property list
|
|
|
|
PLIST.
|
2012-08-04 18:07:23 +02:00
|
|
|
|
|
|
|
If `:limit' is specified only get that many headlines, and if
|
|
|
|
`:skip' has been specified skip that many headlines first.
|
|
|
|
|
|
|
|
If `:is-cat' is non-nil, that means FEED-ID is actually the ID of
|
|
|
|
a category.
|
|
|
|
|
|
|
|
When `:show-excerpt' is non-nil, send back an excerpt along with
|
|
|
|
the headline and if `:show-content' is non-nil send along the
|
|
|
|
entire article.
|
|
|
|
|
|
|
|
`:view-mode' determines what type of headlines are sent back:
|
|
|
|
|
2012-08-04 03:14:54 +02:00
|
|
|
all_articles -- All articles found are sent back.
|
|
|
|
unread -- Only unread articles are sent back.
|
|
|
|
adaptive -- ?
|
|
|
|
marked -- ?
|
|
|
|
updated -- ?
|
|
|
|
|
2012-08-04 18:07:23 +02:00
|
|
|
If `:include-attatchments' is non-nil, send along any files
|
|
|
|
enclosed in the articles.
|
2012-08-04 03:14:54 +02:00
|
|
|
|
2012-08-04 18:07:23 +02:00
|
|
|
If `:since-id' is specified, send only articles with a FEED-ID
|
2012-08-04 03:14:54 +02:00
|
|
|
greater than this.
|
|
|
|
|
2012-08-04 18:07:23 +02:00
|
|
|
There are some special feed IDs:
|
2012-08-04 03:14:54 +02:00
|
|
|
-1 -- Starred feeds
|
|
|
|
-2 -- Published feeds
|
|
|
|
-3 -- Fresh feeds (less than X hours old)
|
|
|
|
-4 -- All articles
|
|
|
|
0 -- Archived articles
|
|
|
|
IDs < -10 -- Labels"
|
2012-08-04 18:07:23 +02:00
|
|
|
(let ((limit (plist-get plist :limit))
|
|
|
|
(skip (plist-get plist :skip))
|
|
|
|
(is-cat (plist-get plist :is-cat))
|
|
|
|
(show-excerpt (plist-get plist :show-excerpt))
|
|
|
|
(show-content (plist-get plist :show-content))
|
|
|
|
(view-mode (plist-get plist :view-mode))
|
|
|
|
(include-attachments (plist-get plist :include-attachments))
|
|
|
|
(since-id (plist-get plist :since-id)))
|
2012-08-22 22:05:16 +02:00
|
|
|
(avandu--send-command-sync
|
2012-08-22 12:44:50 +02:00
|
|
|
`((op . "getHeadlines")
|
|
|
|
(feed_id . ,feed-id)
|
|
|
|
,@(when limit `((limit . ,limit)))
|
|
|
|
,@(when skip `((skip . ,skip)))
|
|
|
|
,@(when is-cat `((is_cat . ,is-cat)))
|
|
|
|
,@(when show-excerpt `((show_excerpt . ,show-excerpt)))
|
|
|
|
,@(when show-content `((show_content . ,show-content)))
|
|
|
|
,@(when view-mode `((view_mode . ,view-mode)))
|
|
|
|
,@(when include-attachments `((include_attachments
|
|
|
|
. ,include-attachments)))
|
|
|
|
,@(when since-id `((since_id . ,since-id)))))))
|
2012-08-04 03:14:54 +02:00
|
|
|
|
2012-08-04 20:39:59 +02:00
|
|
|
(defun avandu-update-article (article-ids mode field &optional data)
|
2014-02-14 01:17:11 +01:00
|
|
|
"Update the status of a field.
|
|
|
|
|
|
|
|
For each id in ARTICLE-IDS put MODE in FIELD.
|
2012-08-04 20:39:59 +02:00
|
|
|
|
|
|
|
ARTICLE-IDS should either be a single integer or a
|
|
|
|
comma-separated list of integers.
|
|
|
|
|
|
|
|
MODE should be one of:
|
|
|
|
0 -- Set to false
|
|
|
|
1 -- Set to true
|
|
|
|
2 -- Toggle
|
|
|
|
|
|
|
|
FIELD should be one of:
|
|
|
|
0 -- Starred
|
|
|
|
1 -- Published
|
|
|
|
2 -- Unread
|
|
|
|
3 -- Article Note
|
|
|
|
|
|
|
|
When updating FIELD 3 DATA functions as the note's contents."
|
2012-08-22 22:05:16 +02:00
|
|
|
(avandu--send-command-async `((op . "updateArticle")
|
|
|
|
(article_ids . ,article-ids)
|
|
|
|
(mode . ,mode)
|
|
|
|
(field . ,field)
|
|
|
|
,@(when data `((data . ,data))))
|
|
|
|
(lambda (status)
|
|
|
|
(message "Update done."))))
|
2012-08-04 20:39:59 +02:00
|
|
|
|
2012-08-22 12:44:50 +02:00
|
|
|
(defun avandu-get-article (article-ids)
|
2014-02-14 01:17:11 +01:00
|
|
|
"Get one or more articles from Tiny Tiny RSS.
|
|
|
|
|
|
|
|
Filter the articles by ARTICLE-IDS, if you're using version 1.5.0
|
|
|
|
or higher this can also be a comma-separated list of ids."
|
2012-08-22 22:05:16 +02:00
|
|
|
(avandu--send-command-sync `((op . "getArticle")
|
|
|
|
(article_id . ,article-ids))))
|
2012-08-22 12:44:50 +02:00
|
|
|
|
2012-08-04 02:28:18 +02:00
|
|
|
;; Commands
|
|
|
|
(defun avandu-browse-article ()
|
|
|
|
"Browse the current button's article url."
|
|
|
|
(interactive)
|
2012-08-07 10:17:54 +02:00
|
|
|
(let ((button (button-at (point)))
|
|
|
|
(message-truncate-lines t))
|
2012-08-04 02:28:18 +02:00
|
|
|
(browse-url (button-get button 'link))
|
2012-08-22 12:44:50 +02:00
|
|
|
(avandu-mark-article-read (button-get button 'article-id))
|
|
|
|
(avandu-ui-mark-article-read button)
|
2012-08-07 10:17:54 +02:00
|
|
|
(message "Opened: %s" (button-label button))))
|
2012-08-04 02:28:18 +02:00
|
|
|
|
|
|
|
(defun avandu-feed-catchup ()
|
2014-02-14 01:17:11 +01:00
|
|
|
"Send a request to tt-rss to \"Catch up\" with a feed.
|
|
|
|
|
|
|
|
This means that all the (unread) articles in a feed will be
|
|
|
|
marked as read. After having completed this request the overview
|
|
|
|
is reloaded."
|
2012-08-04 02:28:18 +02:00
|
|
|
(interactive)
|
|
|
|
(let* ((button (button-at (point)))
|
|
|
|
(id (button-get button 'feed-id)))
|
2012-08-22 22:05:16 +02:00
|
|
|
(avandu--send-command-async `((op . "catchupFeed")
|
|
|
|
(feed_id . ,id))
|
|
|
|
(lambda (status)
|
|
|
|
(message "Catch-up complete."))))
|
2012-08-04 02:28:18 +02:00
|
|
|
(revert-buffer))
|
|
|
|
|
2012-07-25 01:49:02 +02:00
|
|
|
(defun avandu-logged-in-p ()
|
2014-02-14 01:17:11 +01:00
|
|
|
"Send a request to tt-rss to see if we're (still) logged in.
|
|
|
|
|
|
|
|
This function returns t if we are, or nil if we're not."
|
2012-08-22 22:05:16 +02:00
|
|
|
(let* ((response (avandu--send-command-sync '((op . "isLoggedIn"))))
|
2012-08-22 12:44:50 +02:00
|
|
|
(result (avu-prop response status)))
|
2012-07-25 01:49:02 +02:00
|
|
|
(if (eq result :json-false)
|
|
|
|
nil
|
|
|
|
result)))
|
|
|
|
|
|
|
|
(defun avandu-login ()
|
2014-02-14 01:17:11 +01:00
|
|
|
"Send a request to log in to tt-rss.
|
|
|
|
|
|
|
|
If `avandu-user' or `avandu-password' have not been specified
|
|
|
|
they will be asked for and saved in memory. This function
|
|
|
|
returns t on succes, nil otherwise."
|
2012-07-25 01:49:02 +02:00
|
|
|
(interactive)
|
2012-08-06 21:07:33 +02:00
|
|
|
(unless (and avandu-user avandu-password)
|
|
|
|
(avandu--get-credentials))
|
|
|
|
|
2012-08-22 22:05:16 +02:00
|
|
|
(let ((result (avandu--send-command-sync
|
2012-07-25 01:49:02 +02:00
|
|
|
`((op . "login")
|
2012-08-06 21:07:33 +02:00
|
|
|
(user . ,avandu-user)
|
2012-08-23 09:21:47 +02:00
|
|
|
(password . ,(avandu--password))) t)))
|
2012-07-25 01:49:02 +02:00
|
|
|
(if (eq (avandu--get-status-id result) 0)
|
|
|
|
(progn
|
|
|
|
(setq avandu--session-id (avandu--get-session-id result))
|
|
|
|
t)
|
|
|
|
nil)))
|
|
|
|
|
2012-08-03 22:46:15 +02:00
|
|
|
(defun avandu-logout ()
|
|
|
|
"Logout from Tiny Tiny RSS."
|
|
|
|
(interactive)
|
2012-08-22 22:05:16 +02:00
|
|
|
(avandu--send-command-async '((op . "logout"))
|
|
|
|
(lambda (status)
|
|
|
|
(message "Logged out.")))
|
2012-08-03 22:46:15 +02:00
|
|
|
(avandu--clear-data))
|
|
|
|
|
2012-08-22 12:44:50 +02:00
|
|
|
(defun avandu-mark-article-read (id)
|
2012-08-03 22:46:15 +02:00
|
|
|
"Send a request to tt-rss to mark an article as read.
|
|
|
|
|
2014-02-14 01:17:11 +01:00
|
|
|
Update the article identified by ID."
|
2012-08-03 22:46:15 +02:00
|
|
|
(interactive)
|
2012-08-22 12:44:50 +02:00
|
|
|
(let* ((message-truncate-lines t))
|
|
|
|
(avandu-update-article id 0 2)))
|
|
|
|
|
2016-12-26 16:07:21 +01:00
|
|
|
(defun avandu-mark-article-unread (id)
|
|
|
|
"Send a request to tt-rss to mark an article as unread.
|
|
|
|
|
|
|
|
Update the article identified by ID."
|
|
|
|
(interactive)
|
|
|
|
(let* ((message-truncate-lines t))
|
|
|
|
(avandu-update-article id 1 2)))
|
|
|
|
|
2012-08-22 12:44:50 +02:00
|
|
|
(defun avandu-ui-mark-article-read (&optional button)
|
2014-02-14 01:17:11 +01:00
|
|
|
"Try to change the state of BUTTON to a read article button.
|
|
|
|
|
|
|
|
If BUTTON is nil, try to use a button at `point'."
|
2012-08-22 12:44:50 +02:00
|
|
|
(let ((button (or button (button-at (point)))))
|
|
|
|
(if button
|
|
|
|
(progn
|
|
|
|
(button-put button 'face 'avandu-overview-read-article)
|
|
|
|
(avandu-next-article))
|
2014-02-14 01:17:11 +01:00
|
|
|
(error "No button found"))))
|
2012-08-03 22:46:15 +02:00
|
|
|
|
2016-12-26 16:07:21 +01:00
|
|
|
(defun avandu-ui-mark-article-unread (&optional button)
|
|
|
|
"Try to change the state of BUTTON to an unread article button.
|
|
|
|
|
|
|
|
If BUTTON is nil, try to use a button at `point'."
|
|
|
|
(let ((button (or button (button-at (point)))))
|
|
|
|
(if button
|
|
|
|
(progn
|
|
|
|
(button-put button 'face 'avandu-overview-unread-article)
|
|
|
|
(avandu-next-article))
|
|
|
|
(error "No button found"))))
|
|
|
|
|
2012-07-25 01:49:02 +02:00
|
|
|
(defun avandu-new-articles-count ()
|
2014-02-14 01:17:11 +01:00
|
|
|
"Get the total number of unread feeds."
|
2012-07-25 01:49:02 +02:00
|
|
|
(interactive)
|
|
|
|
(avandu--check-login)
|
2012-08-22 22:05:16 +02:00
|
|
|
(let* ((result (avandu--send-command-sync '((op . "getUnread"))))
|
2012-08-22 12:44:50 +02:00
|
|
|
(count (avu-prop result unread)))
|
2012-08-04 00:30:15 +02:00
|
|
|
|
|
|
|
(when (called-interactively-p 'any)
|
|
|
|
(message "There are %s unread articles" count))
|
|
|
|
|
|
|
|
count))
|
2012-07-25 01:49:02 +02:00
|
|
|
|
|
|
|
(defun avandu-next-article ()
|
2012-07-26 00:43:30 +02:00
|
|
|
"Search forward for the next article."
|
2012-07-25 01:49:02 +02:00
|
|
|
(interactive)
|
|
|
|
(avandu--next-button-of-type forward article))
|
|
|
|
|
2014-02-15 16:38:54 +01:00
|
|
|
(defun avandu-next-button ()
|
|
|
|
"Search forward for the next button."
|
|
|
|
(interactive)
|
|
|
|
(let ((button-overlay (next-button (point))))
|
|
|
|
(if button-overlay
|
|
|
|
(goto-char (overlay-start button-overlay))
|
|
|
|
(funcall avandu-next-button-fallback-function))))
|
|
|
|
|
2012-07-25 01:49:02 +02:00
|
|
|
(defun avandu-next-feed ()
|
2012-07-26 00:43:30 +02:00
|
|
|
"Go forward and find the next feed."
|
2012-07-25 01:49:02 +02:00
|
|
|
(interactive)
|
|
|
|
(avandu--next-button-of-type forward feed))
|
|
|
|
|
2012-08-03 22:46:15 +02:00
|
|
|
(defun avandu-previous-article ()
|
|
|
|
"Go backward and find the next article."
|
|
|
|
(interactive)
|
|
|
|
(avandu--next-button-of-type backward article))
|
|
|
|
|
2014-02-15 16:38:54 +01:00
|
|
|
(defun avandu-previous-button ()
|
|
|
|
"Go backward and find the next button."
|
|
|
|
(interactive)
|
|
|
|
(let ((button-overlay (previous-button (point))))
|
|
|
|
(if button-overlay
|
|
|
|
(goto-char (overlay-start button-overlay))
|
|
|
|
(funcall avandu-previous-button-fallback-function))))
|
|
|
|
|
2012-07-25 01:49:02 +02:00
|
|
|
(defun avandu-previous-feed ()
|
2012-07-26 00:43:30 +02:00
|
|
|
"Go backward and find the next feed."
|
2012-07-25 01:49:02 +02:00
|
|
|
(interactive)
|
|
|
|
(avandu--next-button-of-type backward feed))
|
|
|
|
|
2012-08-03 23:54:35 +02:00
|
|
|
(defun avandu-tt-rss-api-level ()
|
2012-08-04 00:05:24 +02:00
|
|
|
"Get the API level of your Tiny Tiny RSS instance."
|
2012-08-03 23:54:35 +02:00
|
|
|
(interactive)
|
2012-08-22 22:05:16 +02:00
|
|
|
(let ((level (avu-prop (avandu--send-command-sync
|
|
|
|
'((op . "getApiLevel")))
|
2012-08-22 12:44:50 +02:00
|
|
|
level)))
|
2012-08-03 23:54:35 +02:00
|
|
|
(when (called-interactively-p 'any)
|
|
|
|
(message "API Level: %d" level))
|
|
|
|
|
|
|
|
level))
|
|
|
|
|
2012-08-04 00:05:24 +02:00
|
|
|
(defun avandu-tt-rss-version ()
|
|
|
|
"Get the version of your Tiny Tiny RSS instance."
|
|
|
|
(interactive)
|
2012-08-22 22:05:16 +02:00
|
|
|
(let ((version (avu-prop (avandu--send-command-sync
|
|
|
|
'((op . "getVersion")))
|
2012-08-22 12:44:50 +02:00
|
|
|
version)))
|
2012-08-04 00:05:24 +02:00
|
|
|
(when (called-interactively-p 'any)
|
|
|
|
(message "Tiny Tiny RSS Version: %s" version))
|
|
|
|
|
|
|
|
version))
|
|
|
|
|
2014-03-06 00:07:32 +01:00
|
|
|
;;;###autoload
|
2014-04-12 22:49:31 +02:00
|
|
|
(defun avandu-subscribe-to-feed (url category)
|
2014-03-06 00:07:32 +01:00
|
|
|
"Subscribe to the feed at URL optionally putting it in CATEGORY."
|
2014-04-12 22:49:31 +02:00
|
|
|
(interactive (let ((categories (avandu-categories)))
|
|
|
|
(list (read-from-minibuffer "URL: ")
|
|
|
|
(gethash (completing-read "Category: "
|
|
|
|
categories nil t)
|
|
|
|
categories))))
|
2014-03-06 00:07:32 +01:00
|
|
|
(let ((status (avu-prop (avu-prop (avandu--send-command-sync
|
|
|
|
`((op . "subscribeToFeed")
|
2014-04-12 22:49:31 +02:00
|
|
|
(feed_url . ,url)
|
|
|
|
(category_id . ,category)))
|
2014-03-06 00:07:32 +01:00
|
|
|
status)
|
|
|
|
code)))
|
|
|
|
(if (= status 1)
|
|
|
|
(message "Succesfully subscribed to feed")
|
|
|
|
(message "Could not subscribe to feed"))))
|
|
|
|
|
2014-04-12 23:26:16 +02:00
|
|
|
;;;###autoload
|
|
|
|
(defun avandu-unsubscribe-from-feed (id)
|
|
|
|
"Unsubscribe from ID."
|
|
|
|
(interactive (let ((feeds (avandu--all-feeds-hash)))
|
|
|
|
(list (gethash (completing-read "Feed: " feeds nil t)
|
|
|
|
feeds))))
|
|
|
|
(let ((status (avu-prop (avandu--send-command-sync
|
|
|
|
`((op . "unsubscribeFeed")
|
|
|
|
(feed_id . ,id))) status)))
|
|
|
|
(if (string= status "OK")
|
|
|
|
(message "Succesfully unsubscribed from feed")
|
|
|
|
(message "Could not unsubscribe from feed"))))
|
|
|
|
|
2012-08-22 23:08:42 +02:00
|
|
|
(defun avandu-view-possibly-external (start end)
|
2014-02-14 01:17:11 +01:00
|
|
|
"Maybe execute a command on the region between START and END.
|
|
|
|
|
|
|
|
If `avandu-html2text-command' has been specified use that on the
|
|
|
|
given region, otherwise just leave it alone."
|
2012-08-22 23:08:42 +02:00
|
|
|
(when avandu-html2text-command
|
|
|
|
(shell-command-on-region
|
|
|
|
start end avandu-html2text-command t t)))
|
|
|
|
|
|
|
|
(defun avandu-view-w3m (start end)
|
2014-02-14 01:17:11 +01:00
|
|
|
"Render the region between START and END with w3m."
|
2012-08-22 23:08:42 +02:00
|
|
|
(when (require 'w3m nil t)
|
|
|
|
(w3m-region start end)
|
|
|
|
(w3m-minor-mode)))
|
|
|
|
|
2012-08-03 22:46:15 +02:00
|
|
|
;; Overview
|
2012-08-04 00:30:15 +02:00
|
|
|
(define-derived-mode avandu-overview-mode special-mode
|
|
|
|
avandu-overview-mode-name
|
2012-08-07 09:49:18 +02:00
|
|
|
"Major mode for the avandu overview screen.
|
2012-07-27 01:44:14 +02:00
|
|
|
|
2012-08-03 22:46:15 +02:00
|
|
|
This screen shows the articles categorized by feed as a list. It
|
|
|
|
doesn't sort the list, so you'll have to set that up in tt-rss.
|
2012-07-27 01:44:14 +02:00
|
|
|
|
2012-08-03 22:46:15 +02:00
|
|
|
\\{avandu-overview-map}
|
|
|
|
\\<avandu-overview-map>"
|
|
|
|
(use-local-map avandu-overview-map)
|
|
|
|
(set (make-local-variable 'revert-buffer-function)
|
2012-08-04 16:10:42 +02:00
|
|
|
#'(lambda (ignore-auto noconfirm) (avandu-overview)))
|
2012-08-04 00:30:15 +02:00
|
|
|
(setq mode-name (format "%s[%s]"
|
|
|
|
avandu-overview-mode-name
|
|
|
|
(avandu-new-articles-count))))
|
2012-07-25 01:49:02 +02:00
|
|
|
|
2014-03-03 21:45:24 +01:00
|
|
|
(define-derived-mode avandu-article-mode special-mode "Avandu:Article"
|
2012-08-22 12:44:50 +02:00
|
|
|
"Major mode for the avandu article screen.
|
|
|
|
|
|
|
|
This screen shows the contents of an article.
|
|
|
|
|
2014-02-15 16:37:45 +01:00
|
|
|
\\{avandu-article-mode-map}
|
|
|
|
\\<avandu-article-mode-map>")
|
2012-08-22 12:44:50 +02:00
|
|
|
|
2014-02-14 00:38:20 +01:00
|
|
|
(defsubst avandu--feed-id (alist)
|
|
|
|
"Get a feed_id from ALIST."
|
|
|
|
(cdr (assoc 'feed_id alist)))
|
|
|
|
|
|
|
|
(defun avandu--order-feed (feed1 feed2)
|
|
|
|
"Return t if FEED1 should be sorted before FEED2."
|
|
|
|
(string< (avandu--feed-id feed1) (avandu--feed-id feed2)))
|
|
|
|
|
2012-07-25 01:49:02 +02:00
|
|
|
;;;###autoload
|
2012-08-04 16:10:42 +02:00
|
|
|
(defun avandu-overview ()
|
2014-02-14 00:38:20 +01:00
|
|
|
"Request the headlines of unread articles and list them.
|
|
|
|
|
|
|
|
The list is grouped and sorted by feed ID. Sorting by feed ID is
|
|
|
|
meaningless, but it's easy."
|
2012-07-25 01:49:02 +02:00
|
|
|
(interactive)
|
|
|
|
(avandu--check-login)
|
|
|
|
(let ((buffer (get-buffer-create "*avandu-overview*"))
|
2014-02-14 00:38:20 +01:00
|
|
|
(result (sort (cl-coerce (avandu-headlines -4 :show-excerpt t
|
|
|
|
:view-mode "unread")
|
|
|
|
'list)
|
|
|
|
#'avandu--order-feed))
|
2012-07-25 01:49:02 +02:00
|
|
|
feed-id)
|
|
|
|
(with-current-buffer buffer
|
|
|
|
(setq buffer-read-only nil)
|
|
|
|
(erase-buffer)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(mapc #'(lambda (elt)
|
|
|
|
(unless (equal feed-id (assq 'feed_id elt))
|
2012-08-22 12:44:50 +02:00
|
|
|
(avandu--insert-feed-title (avu-prop elt feed_id)
|
|
|
|
(avu-prop elt feed_title)))
|
2012-07-25 01:49:02 +02:00
|
|
|
(setq feed-id (assq 'feed_id elt))
|
2012-08-22 12:44:50 +02:00
|
|
|
(avandu--insert-article-title (avu-prop elt id)
|
|
|
|
(avu-prop elt link)
|
|
|
|
(avu-prop elt title))
|
|
|
|
(avandu--insert-article-excerpt (avu-prop elt excerpt)))
|
2012-08-04 03:14:54 +02:00
|
|
|
result)
|
2012-07-25 01:49:02 +02:00
|
|
|
(setq buffer-read-only t)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(avandu-overview-mode))
|
|
|
|
(switch-to-buffer buffer)))
|
|
|
|
|
2012-08-22 12:44:50 +02:00
|
|
|
(defun avandu-view-article (id)
|
2014-02-14 01:17:11 +01:00
|
|
|
"Show a single article identified by ID in a new buffer."
|
2012-08-22 12:44:50 +02:00
|
|
|
(interactive "nArticle id: ")
|
|
|
|
(let* ((data (avandu-get-article id))
|
|
|
|
(buffer (get-buffer-create "*avandu-article*"))
|
2012-08-22 23:08:42 +02:00
|
|
|
(inhibit-read-only t)
|
|
|
|
content-start
|
|
|
|
content-end)
|
2012-08-22 12:44:50 +02:00
|
|
|
(with-current-buffer buffer
|
|
|
|
(erase-buffer)
|
|
|
|
(mapc #'(lambda (item)
|
|
|
|
(insert
|
|
|
|
(propertize (avu-prop item title)
|
|
|
|
'face 'avandu-article-title))
|
|
|
|
(newline)
|
|
|
|
(insert
|
|
|
|
(propertize (concat "by: " (avu-prop item author))
|
|
|
|
'face 'avandu-article-author))
|
2014-02-15 13:55:02 +01:00
|
|
|
(insert " (")
|
|
|
|
(insert-button
|
|
|
|
"Browse original"
|
|
|
|
'url (avu-prop item link)
|
|
|
|
'action #'(lambda (button)
|
|
|
|
(browse-url (button-get button 'url))))
|
|
|
|
(insert ")")
|
2012-08-22 12:44:50 +02:00
|
|
|
(newline)(newline)
|
2012-08-22 23:08:42 +02:00
|
|
|
(setq content-start (point))
|
|
|
|
(insert (avu-prop item content))
|
|
|
|
(setq content-end (point))
|
2012-08-22 12:44:50 +02:00
|
|
|
(newline)(newline))
|
|
|
|
data)
|
|
|
|
(setq buffer-read-only t)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(avandu-article-mode))
|
|
|
|
(avandu-mark-article-read id)
|
|
|
|
(avandu-ui-mark-article-read)
|
2012-08-22 23:08:42 +02:00
|
|
|
(switch-to-buffer buffer)
|
|
|
|
(when avandu-article-render-function
|
|
|
|
(funcall
|
|
|
|
avandu-article-render-function content-start
|
2014-02-15 16:38:26 +01:00
|
|
|
(min content-end (point-max))))
|
|
|
|
(goto-char (point-min))))
|
2012-08-22 12:44:50 +02:00
|
|
|
|
2012-07-25 01:49:02 +02:00
|
|
|
(provide 'avandu)
|
|
|
|
|
|
|
|
;;; avandu.el ends here
|
|
|
|
;; ((feed_title . "Identity at Mozilla")
|
|
|
|
;; (labels . [])
|
|
|
|
;; (tags . [""])
|
|
|
|
;; (feed_id . "6")
|
|
|
|
;; (link . "http://identity.mozilla.com/post/13619011637")
|
|
|
|
;; (title . "BrowserID this week: better, faster, more secure.")
|
|
|
|
;; (is_updated . :json-false)
|
|
|
|
;; (updated . 1322795401)
|
|
|
|
;; (published . :json-false)
|
|
|
|
;; (marked . :json-false)
|
|
|
|
;; (unread . t)
|
|
|
|
;; (id . 109))
|
2012-08-03 22:46:15 +02:00
|
|
|
|
|
|
|
;; (login user password)
|
|
|
|
;; (get-article article-id)
|
|
|
|
;; (get-config icons-dir icons-url daemon-is-running num-feeds)
|
|
|
|
;; (update-feed feed-id)
|
|
|
|
;; (get-pref pref-name)
|
|
|
|
;; (catchup-feed feed-id categoryp)
|
|
|
|
;; (get-counters output-mode)
|
|
|
|
;; (get-labels article-id)
|
|
|
|
;; (set-article-label article-ids label-id assingp)
|