X-Git-Url: https://cgit.sxemacs.org/?a=blobdiff_plain;f=lisp%2Friece-history.el;h=4ea64484bafbefa026a4dcdbafb01a32b15e87bf;hb=6c6d6932464e4d79ae65205babeb6d98823df118;hp=65da96016b102f78c9cd268ff845d8a87a61d284;hpb=1a81aa31cd21424720b8a59283ab1d01ae181f73;p=riece diff --git a/lisp/riece-history.el b/lisp/riece-history.el index 65da960..4ea6448 100644 --- a/lisp/riece-history.el +++ b/lisp/riece-history.el @@ -31,6 +31,11 @@ ;;; Code: +(require 'riece-options) +(require 'riece-globals) +(require 'riece-highlight) +(require 'riece-identity) +(require 'riece-signal) (require 'ring) (defgroup riece-history nil @@ -44,8 +49,36 @@ :type 'integer :group 'riece-history) +(defface riece-channel-list-history-face + '((((class color) + (background dark)) + (:foreground "PaleTurquoise")) + (((class color) + (background light)) + (:foreground "SeaGreen3")) + (t + (:bold t))) + "Face used for displaying history channels." + :group 'riece-highlight-faces) +(defvar riece-channel-list-history-face 'riece-channel-list-history-face) + +(unless (riece-facep 'riece-modeline-history-face) + (make-face 'riece-modeline-history-face + "Face used for displaying history channels in modeline.") + (if (featurep 'xemacs) + (set-face-parent 'riece-modeline-history-face 'modeline)) + (set-face-foreground 'riece-modeline-history-face + (face-foreground 'riece-channel-list-history-face))) + +(defvar riece-modeline-history-face 'riece-modeline-history-face) + (defvar riece-channel-history nil) +(defvar riece-history-enabled nil) + +(defconst riece-history-description + "Keep track channel history") + (defun riece-guess-channel-from-history () (let ((length (ring-length riece-channel-history)) (index 0) @@ -55,27 +88,62 @@ index (1+ index))) (nreverse result))) +(defun riece-history-format-identity-for-channel-list-buffer (index identity) + (if (and riece-history-enabled + (not (ring-empty-p riece-channel-history)) + (riece-identity-equal identity (ring-ref riece-channel-history 0))) + (concat (format "%2d:+" index) + (riece-format-identity identity)))) + +(defun riece-history-format-identity-for-channel-list-indicator (index + identity) + (if (and riece-history-enabled + (not (ring-empty-p riece-channel-history)) + (riece-identity-equal identity (ring-ref riece-channel-history 0))) + (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-history-face))))) + ;;; (defun riece-history-requires () ;;; (if (memq 'riece-guess riece-addons) ;;; '(riece-guess))) (defun riece-history-insinuate () - (add-hook 'riece-startup-hook - (lambda () - (setq riece-channel-history - (make-ring riece-channel-history-length)))) - (add-hook 'riece-exit-hook - (lambda () - (setq riece-channel-history nil))) (add-hook 'riece-after-switch-to-channel-functions (lambda (last) - (ring-insert riece-channel-history last))) + (if (and riece-history-enabled last + (not (riece-identity-equal last riece-current-channel))) + (ring-insert riece-channel-history last)))) + (add-hook 'riece-format-identity-for-channel-list-buffer-functions + 'riece-history-format-identity-for-channel-list-buffer) + (add-hook 'riece-format-identity-for-channel-list-indicator-functions + 'riece-history-format-identity-for-channel-list-indicator) + (if (memq 'riece-highlight riece-addons) + (setq riece-channel-list-mark-face-alist + (cons '(?+ . riece-channel-list-history-face) + riece-channel-list-mark-face-alist))) ;;; (if (memq 'riece-guess riece-addons) ;;; (add-hook 'riece-guess-channel-try-functions ;;; 'riece-guess-channel-from-history)) ) +(defun riece-history-enable () + (setq riece-channel-history + (make-ring riece-channel-history-length)) + (setq riece-history-enabled t) + (riece-emit-signal 'channel-list-changed)) + +(defun riece-history-disable () + (setq riece-channel-history nil + riece-history-enabled nil) + (riece-emit-signal 'channel-list-changed)) + (provide 'riece-history) ;;; riece-history.el ends here -