;;; home-modeline.el --- 

;; Copyright (C) 2010  Mark Triggs

;; Author: Mark Triggs <mst@dishevelled.net>
;; Keywords: 

;; 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 <http://www.gnu.org/licenses/>.

;;; Commentary:

;; 

;;; Code:



(defun my-interesting-modeline ()
  (mapconcat 'identity
             (remove-if-not
              (lambda (s)
                (and (not (string-match "^\\[[0-9]+\\]" s))
                     (or (string-match "^\\[" s)
                         (string-match "\\]$" s))))
              (split-string (remove-properties-from-string (format-mode-line
                                                            mode-line-format))
                            " " t))
             " "))


(defvar *last-mode* "")

(defun broadcast-modeline (&optional force)
  (let ((mode (my-interesting-modeline)))
    (when (or force
              (not (string= *last-mode* mode)))
      (setq *last-mode* mode)
      (x-change-window-property
       "HOME_MODELINE"
       mode
       (selected-frame)
       "STRING" nil t))))

(defvar *home-modeline-timer* nil)

(setq *home-modeline-timer*
      (run-at-time
       nil
       10
       'broadcast-modeline))


(eval-after-load "erc-track"
  '(progn
     (add-hook 'erc-track-list-changed-hook 'broadcast-modeline)))


(provide 'home-modeline)
;;; home-modeline.el ends here
