From ca10d1f15770d662861fd0e6cb541e58ef611c6d Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Thu, 31 Dec 2015 21:30:01 -0700 Subject: [PATCH] Add sauron event for @-mention in twittering mode If `twittering-username` is set, events will be added when new tweets come with with `@`. `sauron-prio-twittering-mention` can be customized to change the priority of @-mention messages. Resolves #43 --- README.org | 12 +++++++++-- sauron-twittering.el | 51 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/README.org b/README.org index 0c2915b..3faf89f 100644 --- a/README.org +++ b/README.org @@ -13,7 +13,7 @@ case of IRC (ERC), it will switch you to the buffer (channel) it originated from. It's a bit of a generalization of what /tracking mode/ does in ERC (the emacs IRC client), and that is in fact how it started. - + There's an increasing number of hooks and tunables in sauron, which allows you to fine-tune the behavior. However, I strive for it to be useful with minimal configuration. @@ -228,7 +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 + - *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). @@ -356,6 +356,14 @@ DBUS_SESSION_BUS_ADDRESS="`cat ~/.sauron-dbus`" dbus-send .... =sauron-identica= shows the number of new dents found by =identica-mode= whenever there is at least one new dent. +*** twittering + + =sauron-twittering= shows the number of new tweets found by + =twittering-mode= whenever there is at least one new tweet. + + If =twittering-username= is set, it will also show @-mentions when new + tweets arrive. + *** jabber =sauron-jabber= shows events from =jabber.el=, this includes new messages, info diff --git a/sauron-twittering.el b/sauron-twittering.el index 792bd6b..2f221c2 100644 --- a/sauron-twittering.el +++ b/sauron-twittering.el @@ -28,6 +28,9 @@ (defvar sauron-prio-twittering-new-tweets 3 "Twittering new tweets event priority.") +(defvar sauron-prio-twittering-mention 4 + "Twittering @-mention event priority.") + (defvar sauron-twittering-running nil "when non-nil, sauron-twittering is running") @@ -40,7 +43,9 @@ (error "sauron-twittering is already running. Call sauron-twittering-stop first.")) - (add-hook 'twittering-new-tweets-hook 'sauron-twittering-new-tweets-func) + (add-hook 'twittering-new-tweets-hook #'sauron-twittering-new-tweets-func) + (add-hook 'twittering-new-tweets-hook + #'sauron-twittering-check-tweet-mention-func) (setq sauron-twittering-running t)) (message "No twittering, so sauron-twittering could not start"))) @@ -50,21 +55,47 @@ "Stops and cleans up sauron-twittering." (when sauron-twittering-running (remove-hook 'twittering-new-tweets-hook 'sauron-twittering-new-tweets-func) + (remove-hook 'twittering-new-tweets-hook + #'sauron-twittering-check-tweet-mention-func) (setq sauron-twittering-running nil))) +(defun sauron-twittering-check-tweet-mention-func () + "Hook which takes newly incoming tweets and adds sauron events +for any mentioning `twittering-username'. Events will be added +using `sauron-prio-twittering-mention' priority." + (when (and twittering-username + (boundp 'twittering-new-tweets-statuses)) + (dolist (tweet twittering-new-tweets-statuses) + (when (string-match-p + (format "@%s" twittering-username) + (alist-get 'text tweet)) + (sr-twit-add-event + sauron-prio-twittering-mention + (format "%s: %s" + (alist-get 'user-screen-name tweet) + (alist-get 'text tweet)) + (lexical-let + ((tweets-spec twittering-new-tweets-spec) + (tweets-data twittering-new-tweets-statuses) + (tweets-count twittering-new-tweets-count)) + (lambda () + (sr-twit-activate-event + tweets-data tweets-count tweets-spec)))))))) + + (defun sauron-twittering-new-tweets-func () "Hook which handles the arrival of new tweets. Main entry point and interface to twittering." - (sr-twit-add-event sauron-prio-twittering-new-tweets - (format "%d new tweets" twittering-new-tweets-count) - (lexical-let - ((tweets-spec twittering-new-tweets-spec) - (tweets-data twittering-new-tweets-statuses) - (tweets-count twittering-new-tweets-count)) - (lambda () - (sr-twit-activate-event tweets-data tweets-count tweets-spec) - )))) + (sr-twit-add-event + sauron-prio-twittering-new-tweets + (format "%d new tweets" twittering-new-tweets-count) + (lexical-let + ((tweets-spec twittering-new-tweets-spec) + (tweets-data twittering-new-tweets-statuses) + (tweets-count twittering-new-tweets-count)) + (lambda () + (sr-twit-activate-event tweets-data tweets-count tweets-spec))))) (defun sr-twit-add-event (priority message callback) (sauron-add-event 'twittering priority message callback))