X-Git-Url: https://cgit.sxemacs.org/?p=riece;a=blobdiff_plain;f=lisp%2Friece-unread.el;h=a36b72fe36b55ca45d798c1bb87988a22d57c77d;hp=47c998a96d21fcaed6cc19d3d127a1791bbd2d93;hb=52bf8fa57db89e6a5f8ca2ed07c91ed828bcd88e;hpb=a86316a5d418673f99e35a21a59356b57a778a3d diff --git a/lisp/riece-unread.el b/lisp/riece-unread.el index 47c998a..a36b72f 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)) @@ -57,41 +58,72 @@ :group 'riece-highlight-faces) (defvar riece-channel-list-unread-face 'riece-channel-list-unread-face) +(unless (riece-facep 'riece-modeline-unread-face) + (make-face 'riece-modeline-unread-face + "Face used for displaying unread channels in modeline.") + (if (featurep 'xemacs) + (set-face-parent 'riece-modeline-unread-face 'modeline)) + (set-face-foreground 'riece-modeline-unread-face + (face-foreground 'riece-channel-list-unread-face))) + (defvar riece-unread-channels nil) +(defvar riece-unread-enabled nil) + +(defconst riece-unread-description + "Mark channels where \"unread\" messages arrived") + (defun riece-unread-after-display-message-function (message) - (unless (or (riece-message-own-p message) - (riece-identity-equal (riece-message-target message) - riece-current-channel) - (riece-identity-member (riece-message-target message) - riece-unread-channels)) - (setq riece-unread-channels - (cons (riece-message-target message) riece-unread-channels)) - (riece-redisplay-buffers))) + (if riece-unread-enabled + (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))) - -(defun riece-unread-format-channel-list-line (index channel) - (if (riece-identity-member channel riece-unread-channels) + (if riece-unread-enabled + (setq riece-unread-channels + (delq (car (riece-identity-member riece-current-channel + riece-unread-channels)) + riece-unread-channels)))) + +(defun riece-unread-format-identity-for-channel-list-buffer (index identity) + (if (and riece-unread-enabled + (riece-identity-member identity riece-unread-channels)) (concat (format "%2d:!" index) - (riece-format-identity channel) - "\n"))) + (riece-format-identity identity)))) + +(defun riece-unread-format-identity-for-channel-list-indicator (index identity) + (if (and riece-unread-enabled + (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-modeline-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 () - riece-unread-channels) - -(defvar riece-command-mode-map) -(defvar riece-dialogue-mode-map) -(defvar riece-channel-list-mode-map) + (reverse riece-unread-channels)) (defun riece-unread-requires () (let (requires) @@ -106,14 +138,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-format-channel-list-line-functions - 'riece-unread-format-channel-list-line) - (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) + (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) (if (memq 'riece-highlight riece-addons) (setq riece-channel-list-mark-face-alist (cons '(?! . riece-channel-list-unread-face) @@ -123,6 +151,30 @@ ;;; 'riece-guess-channel-from-unread)) ) +(defvar riece-command-mode-map) +(defvar riece-dialogue-mode-map) +(defvar riece-channel-list-mode-map) +(defun riece-unread-enable () + (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) + (setq riece-unread-enabled t) + (riece-emit-signal 'channel-list-changed)) + +(defun riece-unread-disable () + (define-key riece-command-mode-map + "\C-c\C-u" nil) + (define-key riece-dialogue-mode-map + "u" nil) + (define-key riece-channel-list-mode-map + "u" nil) + (setq riece-unread-channels nil + riece-unread-enabled nil) + (riece-emit-signal 'channel-list-changed)) + (provide 'riece-unread) ;;; riece-unread.el ends here