Commit bf921e17301f

Vincent Demeester <vincent@sbr.pm>
2015-08-01 12:12:20
Customize circe and add circe-notifications
1 parent d92eeb1
Changed files (3)
.config
mr
.emacs.d
.gitignore.d
.config/mr/groups.d/emacs-config
@@ -1,6 +1,9 @@
 [$HOME/.emacs.d/snippets/andreaCrotti-snippets]
 checkout = git clone git@github.com:vdemeester/yasnippet-snippets.git andreaCrotti-snippets
 
+[$HOME/.emacs.d/lisp/circe-notifications]
+checkout = git clone git@github.com:eqyiel/circe-notifications circe-notifications
+
 [$HOME/.emacs.d/lisp/pt]
 checkout = git clone git@github.com:vdemeester/pt.el pt
 
.emacs.d/emacs.org
@@ -3004,15 +3004,73 @@
   let's try something different than the good old ERC : let's try
   circe.
 
+  Let's also try to add notifications too, because I miss this a
+  bit. There is some [[https://github.com/eqyiel/circe-notifications#caveats][caveats]] with the setup I have (using znc) so this
+  configuration is probably dumber than it should but.. /meh/..
+
+
   #+BEGIN_SRC emacs-lisp
     (use-package circe
       :ensure t
       :config
       (progn
+        (defun my-circe-prompt ()
+          (lui-set-prompt
+           (concat (propertize (concat (buffer-name) ">")
+                               'face 'circe-server-face)
+                   " ")))
+        (defun my-circe-set-margin ()
+          (setq
+           fringes-outside-margins t
+           right-margin-width 5
+           word-wrap t
+           wrap-prefix "    "))
+
+        (add-hook 'lui-mode-hook 'my-circe-set-margin)
+        (add-hook 'circe-chat-mode-hook 'my-circe-prompt)
+
         (use-package helm-circe
-          :ensure t)))
+          :ensure t)
+        (use-package circe-notifications
+          :load-path "~/.emacs.d/lisp/circe-notifications"
+          :config
+          (progn
+            ;; ZNC's MOTD is 25 lines.
+            ;; I have two networks defined in `circe-network-options'.
+            ;; So wait to see 50 notices from ZNC before enabling notifications.
+
+            (defvar eqyiel-circe-znc-notices 0
+              "How many notices have we received from ZNC?")
+
+            (defvar eqyiel-circe-znc-motd-length 25
+              "How many lines are in ZNC's MOTD?")
+
+            (defun eqyiel-circe-znc-count-networks ()
+              "Return the number of networks in `circe-network-options' multiplied by
+    `eqyiel-circe-znc-motd-length', so we can know how many notices to expect before
+    enabling notifications."
+              (* eqyiel-circe-znc-motd-length (list-length circe-network-options)))
+
+            (defun eqyiel-circe-wait-for-znc (nick user host command args)
+              (if (> (eqyiel-circe-znc-count-networks) eqyiel-circe-znc-notices)
+                  (when (and (string-equal host "znc.in")
+                           (string-equal command "NOTICE"))
+                    (setq eqyiel-circe-znc-notices (+ 1 eqyiel-circe-znc-notices))
+                    (message "That's %d ..." eqyiel-circe-znc-notices))
+                (progn
+                  (message "OK.")
+                  (remove-hook 'circe-receive-message-functions 'eqyiel-circe-wait-for-znc)
+                  (enable-circe-notifications))))
+
+            (defadvice circe-reconnect (before eqyiel-remove-circe-notifications)
+              (setq eqyiel-circe-znc-notices 0)
+              (remove-hook 'circe-receive-message-functions 'circe-notifications)
+              (add-hook 'circe-receive-message-functions 'eqyiel-circe-wait-for-znc))
+
+            (add-hook 'circe-receive-message-functions 'eqyiel-circe-wait-for-znc)))))
   #+END_SRC
 
+
 * Mails ✉
 
   Don't load if not on a computer where there is mails.
.gitignore.d/emacs-config
@@ -22,6 +22,8 @@
 .emacs.d/tramp
 .emacs.d/lisp/docker
 .emacs.d/lisp/pt
+.emacs.d/lisp/circe-notifications
+.emacs.d/undo
 *.elc
 .emacs.d/el-get
 .emacs.d/auto-save-list