Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #40 from seblemaguer/master

Elfeed support
  • Loading branch information...
commit adbcf062f4caeea19bf78244afab5a336e2ea75d 2 parents b80f1e7 + 6d1a2d5
@djcb authored
Showing with 134 additions and 3 deletions.
  1. +9 −1 README.org
  2. +123 −0 sauron-elfeed.el
  3. +2 −2 sauron.el
View
10 README.org
@@ -219,7 +219,7 @@
** the backend modules
- Currently, 7 backend modules have been implemented:
+ Currently, 8 backend modules have been implemented:
- *erc* - for ERC, the emacs IRC client
- *org-mode* - for tracking =org-mode= (=appt=) notifications
@@ -228,6 +228,7 @@
- *identica* - for =identica-mode=, the social-network site
- *twittering* - for =twittering-mode=, the emacs twitter client
- *jabber* - for =jabber=, the IM protocol (XMPP)
+ - *elfeed* - for =elfeed=, an emacs Atom/RSS feed reader
By default, =sauron= tries to load all of them; this should work, even if
you don't have some of these packages (they simply won't be activated).
@@ -363,7 +364,14 @@
The info, presence and connection events get priority 2, so by default you won't
get to see these. The others get priority 3, so those /should/ be visible by
default.
+*** elfeed
+=sauron-elfeed= show events from elfeed.el, this include new entries in each feed.
+By default, all events get priority 2 therefore you won't get to see these. However, it is possible
+to configure the priority using the following instruction
+#+begin_src emacs-lisp
+(puthash url priority sauron-elfeed-prio-hash)
+#+end_src
** adding new modules
It may be interesting to track other modules as well; this shouldn't be too
View
123 sauron-elfeed.el
@@ -0,0 +1,123 @@
+;;; sauron-elfeed.el --- an ELFEED tracking module, part of sauron
+;;
+;; Copyright (C) 2015 Sébastien Le Maguer
+
+;; This file is not part of GNU Emacs.
+;;
+;; Sauron is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; Sauron is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MELFEEDHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;; For documentation, please see:
+;; https://github.com/djcb/sauron/blob/master/README.org
+
+;;; Code:
+(require 'elfeed nil 'noerror)
+
+(eval-when-compile
+ (require 'cl))
+
+;; Variables
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+(defvar sauron-prio-elfeed-default 2
+ "ELFEED event default priority.")
+
+(defvar sauron-elfeed-prio-hash (make-hash-table :test 'equal)
+ "Hashtable to associate a priority for each feed.
+You can add a specific priority using `puthash' using the url of
+the seed as a key and the priority as the value.")
+
+(defvar sr-elfeed-running nil
+ "*internal* Whether sauron elfeed is running.")
+
+;; Elfeed temp. part
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+(defvar elfeed-update-interval (* 15 60)
+ "Interval time between two updates.
+Default value is 15min.")
+
+(defvar elfeed-update-timer nil
+ "Timer defined by elfeed-update-background-start.")
+
+(defun elfeed-update-background-start ()
+ "Start an automatic update.
+elfeed-update-timer is defined in this function."
+ (interactive)
+ (if elfeed-update-timer
+ (warn "elfeed background update is already started")
+ (setq elfeed-update-timer (run-with-timer 0 elfeed-update-interval 'elfeed-update))))
+
+(defun elfeed-update-background-stop ()
+ "Stop the automatic update."
+ (interactive)
+ (if elfeed-update-timer
+ (progn
+ (cancel-timer elfeed-update-timer)
+ (setq elfeed-update-timer nil))
+ (warn "elfeed background update is alread stopped")))
+
+;; Sauron commands
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+(defun sauron-elfeed-start ()
+ "Start watching ELFEED."
+ (interactive)
+ (if (not (boundp 'elfeed-version))
+ (progn
+ (message "sauron-elfeed not available")
+ nil)
+ (unless sr-elfeed-running
+ (add-hook 'elfeed-update-hooks 'sr-elfeed-update-hook-func)
+ (setq sr-elfeed-running t))
+ t))
+
+(defun sauron-elfeed-stop ()
+ "Stop watching ELFEED."
+ (interactive)
+ (when sr-elfeed-running
+ (remove-hook 'elfeed-update-hooks 'sr-elfeed-update-hook-func)
+ (setq sr-elfeed-running nil)))
+
+
+;; Util functions
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+(defun counting-unread (url)
+ "Getting the unread entries of a specific feed identified by URL."
+ (let (read-list)
+ (dolist (entry (elfeed-feed-entries url))
+ (when (member 'unread (elfeed-entry-tags entry))
+ (push (elfeed-entry-title entry) read-list)))
+ (length read-list)))
+
+
+;; Hooks
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+(defun sr-elfeed-update-hook-func (url)
+ "Hook function, to be called for elfeed-matched-hook. URL is the url of the feed."
+ (let* ((nb-unread (counting-unread url)))
+ (when (> nb-unread 0)
+ (sauron-add-event
+ 'elfeed
+ (if (gethash url sauron-elfeed-prio-hash)
+ (gethash url sauron-elfeed-prio-hash)
+ sauron-prio-elfeed-default)
+
+ (concat (propertize (elfeed-feed-title (elfeed-db-get-feed url))
+ 'face 'sauron-highlight1-face)
+ " has "
+ (format "%d" nb-unread)
+ " new entries")))))
+
+
+(provide 'sauron-elfeed)
+
+;;; sauron-elfeed ends here
View
4 sauron.el
@@ -39,10 +39,10 @@
(defvar sauron-modules
'(sauron-erc sauron-dbus sauron-org sauron-notifications
- sauron-twittering sauron-jabber sauron-identica)
+ sauron-twittering sauron-jabber sauron-identica sauron-elfeed)
"List of sauron modules to use. Currently supported are:
sauron-erc, sauron-org and sauron-dbus, sauron-twittering,
-sauron-jabber, sauron-identica.")
+sauron-jabber, sauron-identica, sauron-elfeed.")
(defvar sauron-separate-frame t
"Show sauron in a separate frame; if set to nil (*experimental*),
Please sign in to comment.
Something went wrong with that request. Please try again.