X-Git-Url: https://cgit.sxemacs.org/?a=blobdiff_plain;f=lisp%2Friece-unread.el;h=35143580838865de20b9f01de75520d653e00c22;hb=2d67acd4af1122a36fcc09b47a479b927ca03904;hp=64bb382e588e7eb0a9b6d2385bfc3bee7c946684;hpb=1a81aa31cd21424720b8a59283ab1d01ae181f73;p=riece diff --git a/lisp/riece-unread.el b/lisp/riece-unread.el index 64bb382..3514358 100644 --- a/lisp/riece-unread.el +++ b/lisp/riece-unread.el @@ -35,6 +35,7 @@ (require 'riece-message) (require 'riece-commands) +(require 'riece-signal) (eval-when-compile (require 'riece-highlight)) @@ -44,11 +45,6 @@ :prefix "riece-" :group 'riece) -(defcustom riece-channel-list-unread-face 'riece-channel-list-unread-face - "Face used for displaying unread channels." - :type 'face - :group 'riece-highlight-faces) - (defface riece-channel-list-unread-face '((((class color) (background dark)) @@ -60,47 +56,52 @@ (: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-after-display-message-function (message) - (unless (or (riece-message-own-p message) - (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)) - (riece-unread-update-channel-list-buffer))) + (let ((target (if (riece-message-private-p message) + (riece-message-speaker message) + (riece-message-target message)))) + (unless (or (riece-message-own-p message) + (riece-message-type message) + (riece-identity-equal target riece-current-channel) + (riece-identity-member target riece-unread-channels)) + (setq riece-unread-channels (cons target riece-unread-channels)) + (riece-emit-signal 'channel-list-changed)))) (defun riece-unread-after-switch-to-channel-function (last) (setq riece-unread-channels (delete riece-current-channel - riece-unread-channels)) - (riece-unread-update-channel-list-buffer)) - -(defun riece-unread-update-channel-list-buffer () - (if riece-channel-list-buffer-mode - (save-excursion - (set-buffer riece-channel-list-buffer) - (let ((inhibit-read-only t) - buffer-read-only) - (goto-char (point-min)) - (while (not (eobp)) - (if (looking-at "\\( ?[0-9]+:\\)\\(.\\)\\(.+\\)") - (let ((channel (save-match-data - (riece-parse-identity (match-string 3))))) - (replace-match - (concat "\\1" - (if (member channel riece-unread-channels) - "!" - "\\2") - "\\3")))) - (forward-line)))))) - + riece-unread-channels))) + +(defun riece-unread-format-identity-for-channel-list-buffer (index identity) + (if (riece-identity-member identity riece-unread-channels) + (concat (format "%2d:!" index) + (riece-format-identity identity)))) + +(defun riece-unread-format-identity-for-channel-list-indicator (index identity) + (if (riece-identity-member identity riece-unread-channels) + (let ((string (riece-format-identity identity)) + (start 0)) + ;; Escape % -> %%. + (while (string-match "%" string start) + (setq start (1+ (match-end 0)) + string (replace-match "%%" nil nil string))) + (list (format "%d:" index) + (riece-propertize-modeline-string + string 'face 'riece-channel-list-unread-face))))) + (defun riece-unread-switch-to-channel () (interactive) - (if (car riece-unread-channels) - (riece-command-switch-to-channel (car riece-unread-channels)) + (if riece-unread-channels + (let ((channel (car riece-unread-channels))) + (if (riece-identity-member channel riece-current-channels) + (riece-command-switch-to-channel channel) + (setq riece-unread-channels + (delete channel riece-unread-channels)) + (riece-unread-switch-to-channel))) (error "No unread channel!"))) (defun riece-guess-channel-from-unread () @@ -123,8 +124,10 @@ 'riece-unread-after-display-message-function) (add-hook 'riece-after-switch-to-channel-functions 'riece-unread-after-switch-to-channel-function) - (add-hook 'riece-update-buffer-functions - 'riece-unread-update-channel-list-buffer t) + (add-hook 'riece-format-identity-for-channel-list-buffer-functions + 'riece-unread-format-identity-for-channel-list-buffer) + (add-hook 'riece-format-identity-for-channel-list-indicator-functions + 'riece-unread-format-identity-for-channel-list-indicator) (define-key riece-command-mode-map "\C-c\C-u" 'riece-unread-switch-to-channel) (define-key riece-dialogue-mode-map