I also got to get SLIME up and running which gives me direct access to the running stumpw process, I can directly eval code from emacs/slime and change the behavior of the window manager, very neat indeed.
For starters, I added all a lot of stuff to the mode line, with my hostname, battery charge, date, IP address etc. The best part, I was able to make emacs talk to stumpwm through slime, so I thought I might as well go ahead and integrate jabber.el and jabber-mail-notify.el (which notifies emacs of new mail) to the stumpwm modeline and message bar.
The initial model I adopted was
Emacs Jabber -> Slime -> Stumpwm (swank loaded) -> Stumpwm modeline/message-bar.The drawback was I always had to startup swank and slime-connect to it from emacs before sending any messages to stumpwm. So I adopted a flat file approach (emacs talking to stumpwm through flat files), which turned out to be very quicky and efficient.
Emacs Jabber -> File write -> Stumpwm File read -> Update sumpwm modeline/message-bar.The result was neat and working (see screen shots at the end)
Here's how I did it:
Firstly you will need jabber-mail-notify.el (an extension I wrote last week to notify emacs jabber of new google mail messages).
Once you have emacs jabber, with jabber-mail-notify.el in place, add the following to your emacs de-jabber.el init file:
(this code registers 2 emacs jabber hooks, one for new chat requests, and the second for new mail.)
Now lets make stumpwm periodically read the temporary files for any mail/chat updates using the unix cat command.
;; Stumpwm new message mode-line integration
(defun jabber-stumpwm-activity-modeline-update ()
(let ((text jabber-activity-mode-string))
(if (not (eq (length text) 0))
(setf text (concat " [Message from " text "]")))
(write-string-to-file "~/emacs-jabber.temp" text)
(princ "Done.")))
(add-hook 'jabber-activity-update-hook 'jabber-stumpwm-activity-modeline-update)
;; Stumpwm new mail mode-line integration
(defun jabber-mail-stumpwm-mode-line-update(iq-data)
(let* ((text (jabber-build-mailbox-string iq-data)))
(write-string-to-file "~/emacs-jabber-mail.temp" text)
text)
(princ "Done."))
(add-hook 'jabber-mail-notification-hook 'jabber-mail-stumpwm-mode-line-update)
;; -------------------------------------------
Add the following to your ~/.stumprc or wherever you initialize your mode line format:
That should make your modeline periodically call those methods you just added. ..Done. restart stumpwm and emacs jabber, and you should be good. If you're smart, you can use slime, and ielm, and eval everything on the fly, without any restarts. That's the beauty of emacs and stumpwm! dynamic runtime evaluation is beautiful.
(in-package stumpwm)
(defun show-emacs-jabber-new-message ()
(let ((new-message (run-shell-command "cat ~/emacs-jabber.temp" t)))
(substitute #\Space #\Newline new-message)))
(defun show-emacs-jabber-new-mail ()
(let ((new-mail (run-shell-command "cat ~/emacs-jabber-mail.temp" t)))
(if (not (eq (length new-mail) 0))
(progn (stumpwm:message new-mail)
(run-shell-command "rm ~/emacs-jabber-mail.temp" t)
(run-shell-command "touch ~/emacs-jabber-mail.temp" t)))
""))</PRE>Lastly modify your *screen-mode-line-format* variable such that it includes the following bolded elements at the end of the list.<PRE>(in-package stumpwm)
;; Set mode-line format
(setf *screen-mode-line-format*
(list
'(:eval (show-hostname))
"| Battery:"
'(:eval (show-battery-charge))
'(:eval (show-battery-state))
"| IP " '(:eval (show-ip-address))
"| " '(:eval (run-shell-command "ruby -e \"print Time.now\"" t))
'(:eval (show-emacs-jabber-new-message))
'(:eval (show-emacs-jabber-new-mail))))
With the above code in place now, I can receive notifications of new mail, and chat messages from any window/frame/group of stumpwm. This is very handy for me as I no longer would silently ignore chat/mail notifications from emacs jabber just because I was on some other window/group.
If you hit any problem, feel free to mail or message me, now that I have the stump / emacs-jabber integrated, I will instantly get your message. :)
Screen shots (click to view larger):
stumpwm modeline getting updated with a new chat notification by emacs-jabber:

stumpwm message bar updated with a new mail message notification by emacs-jabber:

stumpwm message bar updated with a list of unread email on connecting to jabber:
0 comments:
Post a Comment