X-Git-Url: http://cgit.sxemacs.org/?p=riece;a=blobdiff_plain;f=lisp%2Friece-unread.el;h=9e8969525aa5608da8605ceec639f1541ec0d5fb;hp=2d1e7f351be57b84874a667aaaeb1c41816ee404;hb=66cb75216d39717d46b679ebe978976f6892b094;hpb=f78ce599a5ea6975e7ccdf80b44559bc654c2bbf;ds=sidebyside diff --git a/lisp/riece-unread.el b/lisp/riece-unread.el index 2d1e7f3..9e89695 100644 --- a/lisp/riece-unread.el +++ b/lisp/riece-unread.el @@ -23,30 +23,51 @@ ;;; Commentary: -;; This add-on displays unread mark ("!") for channels which have -;; "unread messages". +;; This add-on marks channels where new messages are arrived. -;; To use, add the following line to your ~/.riece/init.el: -;; (add-to-list 'riece-addons 'riece-unread t) +;; You can check the unread channels via `C-c g' in the commands +;; buffer, by adding the following lines to ~/.riece/init.el: + +;; (add-hook 'riece-guess-channel-try-functions +;; 'riece-guess-channel-from-unread) ;;; Code: -(eval-when-compile (require 'riece-message)) +(require 'riece-message) +(require 'riece-commands) + +(eval-when-compile (require 'riece-highlight)) + +(defgroup riece-unread nil + "Mark unread channels" + :tag "Unread" + :prefix "riece-" + :group 'riece) + +(defface riece-channel-list-unread-face + '((((class color) + (background dark)) + (:foreground "orange")) + (((class color) + (background light)) + (:foreground "firebrick")) + (t + (:bold t))) + "Face used for displaying unread channels." + :group 'riece-highlight-faces) +(defvar riece-channel-list-unread-face 'riece-channel-list-unread-face) (defvar riece-unread-channels nil) -(defun riece-unread-display-message-function (message) +(defun riece-unread-after-display-message-function (message) (unless (or (riece-message-own-p message) - (equal (riece-message-target message) riece-current-channel) - (eq (window-buffer (selected-window)) - (get-buffer riece-command-buffer))) + (equal (riece-message-target message) riece-current-channel)) (setq riece-unread-channels - (delete (riece-message-target message) riece-unread-channels)) - (add-to-list 'riece-unread-channels - (riece-message-target message)) + (cons (riece-message-target message) + (delete (riece-message-target message) riece-unread-channels))) (riece-unread-update-channel-list-buffer))) -(defun riece-unread-channel-switch-hook () +(defun riece-unread-after-switch-to-channel-function (last) (setq riece-unread-channels (delete riece-current-channel riece-unread-channels)) @@ -60,14 +81,15 @@ buffer-read-only) (goto-char (point-min)) (while (not (eobp)) - (if (looking-at "\\( ?[0-9]+:\\)\\([ !]\\)\\(.+\\)") - (let ((channel (match-string 3))) + (if (looking-at "\\( ?[0-9]+:\\)\\(.\\)") + (let ((channel (get-text-property (match-end 0) + 'riece-identity))) (replace-match (concat "\\1" - (if (member channel riece-unread-channels) + (if (riece-identity-member channel + riece-unread-channels) "!" - " ") - "\\3")))) + "\\2"))))) (forward-line)))))) (defun riece-unread-switch-to-channel () @@ -76,23 +98,44 @@ (riece-command-switch-to-channel (car riece-unread-channels)) (error "No unread channel!"))) +(defun riece-guess-channel-from-unread () + riece-unread-channels) + (defvar riece-command-mode-map) (defvar riece-dialogue-mode-map) (defvar riece-channel-list-mode-map) +(defun riece-unread-requires () + (let (requires) + (if (memq 'riece-highlight riece-addons) + (setq requires (cons 'riece-highlight requires))) +;;; (if (memq 'riece-guess riece-addons) +;;; (setq requires (cons 'riece-guess requires))) + requires)) + (defun riece-unread-insinuate () (add-hook 'riece-after-display-message-functions - 'riece-unread-display-message-function) - (add-hook 'riece-channel-switch-hook - 'riece-unread-channel-switch-hook) - (add-hook 'riece-update-buffers-hook - 'riece-unread-update-channel-list-buffer) + 'riece-unread-after-display-message-function) + (add-hook 'riece-after-switch-to-channel-functions + 'riece-unread-after-switch-to-channel-function) + (add-hook 'riece-channel-list-mode-hook + (lambda () + (add-hook 'riece-update-buffer-functions + 'riece-unread-update-channel-list-buffer t))) (define-key riece-command-mode-map "\C-c\C-u" 'riece-unread-switch-to-channel) (define-key riece-dialogue-mode-map "u" 'riece-unread-switch-to-channel) (define-key riece-channel-list-mode-map - "u" 'riece-unread-switch-to-channel)) + "u" 'riece-unread-switch-to-channel) + (if (memq 'riece-highlight riece-addons) + (setq riece-channel-list-mark-face-alist + (cons '(?! . riece-channel-list-unread-face) + riece-channel-list-mark-face-alist))) +;;; (if (memq 'riece-guess riece-addons) +;;; (add-hook 'riece-guess-channel-try-functions +;;; 'riece-guess-channel-from-unread)) + ) (provide 'riece-unread)