From 0a3a9540b3033e9e93927c92fb6df39a3785563d Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 21 Dec 2014 10:48:41 -0200 Subject: Move mode-line logic to sx-notify --- sx-notify.el | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 sx-notify.el (limited to 'sx-notify.el') diff --git a/sx-notify.el b/sx-notify.el new file mode 100644 index 0000000..bc88ceb --- /dev/null +++ b/sx-notify.el @@ -0,0 +1,66 @@ +;;; sx-notify.el --- Mode-line notifications. -*- lexical-binding: t; -*- + +;; Copyright (C) 2014 Artur Malabarba + +;; Author: Artur Malabarba + +;; This program 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. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY 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 this program. If not, see . + +;;; Commentary: + + +;;; Code: + +(require 'sx) +(require 'sx-inbox) + + +;;; mode-line notification +(defvar sx-notify--unread-inbox nil + "List of inbox items still unread.") + +(defvar sx-notify--unread-notifications nil + "List of notifications items still unread.") + +(defvar sx-notify--mode-line + '((sx-notify--unread-inbox (sx-notify--unread-notifications "[")) + (sx-notify--unread-inbox + (:propertize + (:eval (format "i:%s" (length sx-notify--unread-inbox))) + face mode-line-buffer-id + mouse-face mode-line-highlight)) + (sx-notify--unread-inbox (sx-notify--unread-notifications ",")) + (sx-notify--unread-notifications + (:propertize + (:eval (format "n:%s" (length sx-notify--unread-notifications))) + mouse-face mode-line-highlight)) + (sx-notify--unread-inbox (sx-notify--unread-notifications "]"))) + "") +(put 'sx-notify--mode-line 'risky-local-variable t) + + +;;; minor-mode definition +(define-minor-mode sx-notify-mode nil nil "sx" nil + (if sx-notify-mode + (add-to-list 'global-mode-string '(t sx-notify--mode-line) 'append) + (setq global-mode-string + (delete '(t sx-notify--mode-line) global-mode-string)))) + + +(provide 'sx-notify) +;;; sx-notify.el ends here + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: -- cgit v1.2.3 From b854489549490a53713f0777ac4c22096920e19f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 21 Dec 2014 11:35:42 -0200 Subject: Timer logic --- sx-notify.el | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) (limited to 'sx-notify.el') diff --git a/sx-notify.el b/sx-notify.el index bc88ceb..05babad 100644 --- a/sx-notify.el +++ b/sx-notify.el @@ -27,20 +27,28 @@ ;;; mode-line notification -(defvar sx-notify--unread-inbox nil +(defvar sx-notify--unread-inbox nil "List of inbox items still unread.") -(defvar sx-notify--unread-notifications nil +(defvar sx-notify--unread-notifications nil "List of notifications items still unread.") +(defvar sx-notify--read-inbox nil + "List of inbox items which are read. +These are identified by their links.") + +(defvar sx-notify--read-notifications nil + "List of notification items which are read. +These are identified by their links.") + (defvar sx-notify--mode-line - '((sx-notify--unread-inbox (sx-notify--unread-notifications "[")) + '((sx-notify--unread-inbox (sx-notify--unread-notifications " [")) (sx-notify--unread-inbox (:propertize (:eval (format "i:%s" (length sx-notify--unread-inbox))) face mode-line-buffer-id mouse-face mode-line-highlight)) - (sx-notify--unread-inbox (sx-notify--unread-notifications ",")) + (sx-notify--unread-inbox (sx-notify--unread-notifications " ")) (sx-notify--unread-notifications (:propertize (:eval (format "n:%s" (length sx-notify--unread-notifications))) @@ -51,12 +59,38 @@ ;;; minor-mode definition -(define-minor-mode sx-notify-mode nil nil "sx" nil +(defcustom sx-notify-timer-delay (* 60 5) + "Idle time, in seconds, before querying for inbox items." + :type 'integer + :group 'sx-notify) + +(defvar sx-notify--timer nil + "Timer used for fetching notifications.") + +(define-minor-mode sx-notify-mode nil nil nil nil + :global t (if sx-notify-mode - (add-to-list 'global-mode-string '(t sx-notify--mode-line) 'append) + (progn + (add-to-list 'global-mode-string '(t sx-notify--mode-line) 'append) + (setq sx-notify--timer + (run-with-idle-timer sx-notify-timer-delay 'repeat + #'sx-notify--update-unread))) + (when (timerp sx-notify--timer) + (cancel-timer sx-notify--timer) + (setq sx-notify--timer nil)) (setq global-mode-string (delete '(t sx-notify--mode-line) global-mode-string)))) +(defun sx-notify--update-unread () + "Update the lists of unread notifications." + (setq sx-notify--unread-inbox + (cl-remove-if + (lambda (x) (member (cdr (assq 'link x)) sx-notify--read-inbox)) + (append (sx-inbox-get) nil))) + (setq sx-notify--unread-notifications + (cl-remove-if + (lambda (x) (member (cdr (assq 'link x)) sx-notify--read-notifications)) + (append (sx-inbox-get t) nil)))) (provide 'sx-notify) ;;; sx-notify.el ends here -- cgit v1.2.3 From 316829ed9414e96684ba2dd82100426d28d7215f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 21 Dec 2014 19:59:50 -0200 Subject: Move unread lists to sx-inbox --- sx-inbox.el | 15 +++++++++++++++ sx-notify.el | 36 +++++++++++------------------------- 2 files changed, 26 insertions(+), 25 deletions(-) (limited to 'sx-notify.el') diff --git a/sx-inbox.el b/sx-inbox.el index 3bc95c8..9cdb959 100644 --- a/sx-inbox.el +++ b/sx-inbox.el @@ -63,6 +63,21 @@ KEYWORDS are added to the method call along with PAGE. :keywords keywords :filter sx-inbox-filter)) + +;;; Major-mode +(defvar sx-inbox--unread-inbox nil + "List of inbox items still unread.") + +(defvar sx-inbox--unread-notifications nil + "List of notifications items still unread.") + +(defvar sx-inbox--read-inbox nil + "List of inbox items which are read. +These are identified by their links.") + +(defvar sx-inbox--read-notifications nil + "List of notification items which are read. +These are identified by their links.") (provide 'sx-inbox) ;;; sx-inbox.el ends here diff --git a/sx-notify.el b/sx-notify.el index 05babad..c335427 100644 --- a/sx-notify.el +++ b/sx-notify.el @@ -27,33 +27,19 @@ ;;; mode-line notification -(defvar sx-notify--unread-inbox nil - "List of inbox items still unread.") - -(defvar sx-notify--unread-notifications nil - "List of notifications items still unread.") - -(defvar sx-notify--read-inbox nil - "List of inbox items which are read. -These are identified by their links.") - -(defvar sx-notify--read-notifications nil - "List of notification items which are read. -These are identified by their links.") - (defvar sx-notify--mode-line - '((sx-notify--unread-inbox (sx-notify--unread-notifications " [")) - (sx-notify--unread-inbox + '((sx-inbox--unread-inbox (sx-inbox--unread-notifications " [")) + (sx-inbox--unread-inbox (:propertize - (:eval (format "i:%s" (length sx-notify--unread-inbox))) + (:eval (format "i:%s" (length sx-inbox--unread-inbox))) face mode-line-buffer-id mouse-face mode-line-highlight)) - (sx-notify--unread-inbox (sx-notify--unread-notifications " ")) - (sx-notify--unread-notifications + (sx-inbox--unread-inbox (sx-inbox--unread-notifications " ")) + (sx-inbox--unread-notifications (:propertize - (:eval (format "n:%s" (length sx-notify--unread-notifications))) + (:eval (format "n:%s" (length sx-inbox--unread-notifications))) mouse-face mode-line-highlight)) - (sx-notify--unread-inbox (sx-notify--unread-notifications "]"))) + (sx-inbox--unread-inbox (sx-notify--unread-notifications "]"))) "") (put 'sx-notify--mode-line 'risky-local-variable t) @@ -83,13 +69,13 @@ These are identified by their links.") (defun sx-notify--update-unread () "Update the lists of unread notifications." - (setq sx-notify--unread-inbox + (setq sx-inbox--unread-inbox (cl-remove-if - (lambda (x) (member (cdr (assq 'link x)) sx-notify--read-inbox)) + (lambda (x) (member (cdr (assq 'link x)) sx-inbox--read-inbox)) (append (sx-inbox-get) nil))) - (setq sx-notify--unread-notifications + (setq sx-inbox--unread-notifications (cl-remove-if - (lambda (x) (member (cdr (assq 'link x)) sx-notify--read-notifications)) + (lambda (x) (member (cdr (assq 'link x)) sx-inbox--read-notifications)) (append (sx-inbox-get t) nil)))) (provide 'sx-notify) -- cgit v1.2.3