Emacs config utilizing prelude as a base
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
5.8 KiB

  1. ;;; prelude-erc.el --- Emacs Prelude: ERC mode configuration.
  2. ;;
  3. ;; Copyright (c) 2011 Bozhidar Batsov
  4. ;;
  5. ;; Author: Bozhidar Batsov <bozhidar.batsov@gmail.com>
  6. ;; URL: http://www.emacswiki.org/cgi-bin/wiki/Prelude
  7. ;; Version: 1.0.0
  8. ;; Keywords: convenience
  9. ;; This file is not part of GNU Emacs.
  10. ;;; Commentary:
  11. ;; Some basic configuration for ERC mode, which should make your
  12. ;; IRC experience a bit more pleasant.
  13. ;;; License:
  14. ;; This program is free software; you can redistribute it and/or
  15. ;; modify it under the terms of the GNU General Public License
  16. ;; as published by the Free Software Foundation; either version 3
  17. ;; of the License, or (at your option) any later version.
  18. ;;
  19. ;; This program is distributed in the hope that it will be useful,
  20. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. ;; GNU General Public License for more details.
  23. ;;
  24. ;; You should have received a copy of the GNU General Public License
  25. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  26. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  27. ;; Boston, MA 02110-1301, USA.
  28. ;;; Code:
  29. (require 'erc)
  30. (require 'erc-log)
  31. (require 'erc-notify)
  32. (require 'erc-spelling)
  33. (require 'erc-autoaway)
  34. ;; Join the a couple of interesting channels whenever connecting to Freenode.
  35. (setq erc-autojoin-channels-alist '(("freenode.net"
  36. "#emacs" "#ruby" "#lisp")))
  37. ;; Interpret mIRC-style color commands in IRC chats
  38. (setq erc-interpret-mirc-color t)
  39. ;; The following are commented out by default, but users of other
  40. ;; non-Emacs IRC clients might find them useful.
  41. ;; Kill buffers for channels after /part
  42. (setq erc-kill-buffer-on-part t)
  43. ;; Kill buffers for private queries after quitting the server
  44. (setq erc-kill-queries-on-quit t)
  45. ;; Kill buffers for server messages after quitting the server
  46. (setq erc-kill-server-buffer-on-quit t)
  47. ;; open query buffers in the current window
  48. (setq erc-query-display 'buffer)
  49. ;; exclude boring stuff from tracking
  50. (erc-track-mode t)
  51. (setq erc-track-exclude-types '("JOIN" "NICK" "PART" "QUIT" "MODE"
  52. "324" "329" "332" "333" "353" "477"))
  53. ;; logging
  54. (setq erc-log-channels-directory "~/.erc/logs/")
  55. (if (not (file-exists-p erc-log-channels-directory))
  56. (mkdir erc-log-channels-directory t))
  57. (setq erc-save-buffer-on-part t)
  58. (defadvice save-buffers-kill-emacs (before save-logs (arg) activate)
  59. (save-some-buffers t (lambda () (when (eq major-mode 'erc-mode) t))))
  60. ;; truncate long irc buffers
  61. (erc-truncate-mode +1)
  62. ;; share my real name
  63. (setq erc-user-full-name "Bozhidar Batsov")
  64. ;; enable spell checking
  65. (erc-spelling-mode 1)
  66. ;; set different dictionaries by different servers/channels
  67. ;;(setq erc-spelling-dictionaries '(("#emacs" "american")))
  68. ;; TODO - replace this with use of notify.el
  69. ;; Notify my when someone mentions my nick.
  70. (defun call-libnotify (matched-type nick msg)
  71. (let* ((cmsg (split-string (clean-message msg)))
  72. (nick (first (split-string nick "!")))
  73. (msg (mapconcat 'identity (rest cmsg) " ")))
  74. (shell-command-to-string
  75. (format "notify-send -u critical '%s says:' '%s'" nick msg))))
  76. (when (eq system-type 'linux)
  77. (add-hook 'erc-text-matched-hook 'call-libnotify))
  78. (defvar erc-notify-nick-alist nil
  79. "Alist of nicks and the last time they tried to trigger a
  80. notification")
  81. (defvar erc-notify-timeout 10
  82. "Number of seconds that must elapse between notifications from
  83. the same person.")
  84. (defun erc-notify-allowed-p (nick &optional delay)
  85. "Return non-nil if a notification should be made for NICK.
  86. If DELAY is specified, it will be the minimum time in seconds
  87. that can occur between two notifications. The default is
  88. `erc-notify-timeout'."
  89. (unless delay (setq delay erc-notify-timeout))
  90. (let ((cur-time (time-to-seconds (current-time)))
  91. (cur-assoc (assoc nick erc-notify-nick-alist))
  92. (last-time nil))
  93. (if cur-assoc
  94. (progn
  95. (setq last-time (cdr cur-assoc))
  96. (setcdr cur-assoc cur-time)
  97. (> (abs (- cur-time last-time)) delay))
  98. (push (cons nick cur-time) erc-notify-nick-alist)
  99. t)))
  100. ;; private message notification
  101. (defun erc-notify-on-private-msg (proc parsed)
  102. (let ((nick (car (erc-parse-user (erc-response.sender parsed))))
  103. (target (car (erc-response.command-args parsed)))
  104. (msg (erc-response.contents parsed)))
  105. (when (and (erc-current-nick-p target)
  106. (not (erc-is-message-ctcp-and-not-action-p msg))
  107. (erc-notify-allowed-p nick))
  108. (shell-command-to-string
  109. (format "notify-send -u critical '%s says:' '%s'" nick msg))
  110. nil)))
  111. (add-hook 'erc-server-PRIVMSG-functions 'erc-notify-on-private-msg)
  112. ;; autoaway setup
  113. (setq erc-auto-discard-away t)
  114. (setq erc-autoaway-idle-seconds 600)
  115. (setq erc-autoaway-use-emacs-idle t)
  116. ;; auto identify
  117. (when (file-exists-p (expand-file-name "~/.ercpass"))
  118. (load "~/.ercpass")
  119. (require 'erc-services)
  120. (erc-services-mode 1)
  121. (setq erc-prompt-for-nickserv-password nil)
  122. (setq erc-nickserv-passwords
  123. `((freenode (("bozhidar" . ,bozhidar-pass)))))
  124. )
  125. ;; utf-8 always and forever
  126. (setq erc-server-coding-system '(utf-8 . utf-8))
  127. (defun start-irc ()
  128. "Connect to IRC."
  129. (interactive)
  130. (when (y-or-n-p "Do you want to start IRC? ")
  131. (erc :server "irc.freenode.net" :port 6667 :nick "bozhidar")))
  132. (defun filter-server-buffers ()
  133. (delq nil
  134. (mapcar
  135. (lambda (x) (and (erc-server-buffer-p x) x))
  136. (buffer-list))))
  137. (defun stop-irc ()
  138. "Disconnects from all irc servers"
  139. (interactive)
  140. (dolist (buffer (filter-server-buffers))
  141. (message "Server buffer: %s" (buffer-name buffer))
  142. (with-current-buffer buffer
  143. (erc-quit-server "Asta la vista"))))
  144. (provide 'prelude-erc)
  145. ;;; prelude-erc.el ends here