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.

161 lines
5.2 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. ;; Interpret mIRC-style color commands in IRC chats
  35. (setq erc-interpret-mirc-color t)
  36. ;; The following are commented out by default, but users of other
  37. ;; non-Emacs IRC clients might find them useful.
  38. ;; Kill buffers for channels after /part
  39. (setq erc-kill-buffer-on-part t)
  40. ;; Kill buffers for private queries after quitting the server
  41. (setq erc-kill-queries-on-quit t)
  42. ;; Kill buffers for server messages after quitting the server
  43. (setq erc-kill-server-buffer-on-quit t)
  44. ;; open query buffers in the current window
  45. (setq erc-query-display 'buffer)
  46. ;; exclude boring stuff from tracking
  47. (erc-track-mode t)
  48. (setq erc-track-exclude-types '("JOIN" "NICK" "PART" "QUIT" "MODE"
  49. "324" "329" "332" "333" "353" "477"))
  50. ;; logging
  51. (setq erc-log-channels-directory "~/.erc/logs/")
  52. (if (not (file-exists-p erc-log-channels-directory))
  53. (mkdir erc-log-channels-directory t))
  54. (setq erc-save-buffer-on-part t)
  55. (defadvice save-buffers-kill-emacs (before save-logs (arg) activate)
  56. (save-some-buffers t (lambda () (when (eq major-mode 'erc-mode) t))))
  57. ;; truncate long irc buffers
  58. (erc-truncate-mode +1)
  59. ;; enable spell checking
  60. (erc-spelling-mode 1)
  61. ;; set different dictionaries by different servers/channels
  62. ;;(setq erc-spelling-dictionaries '(("#emacs" "american")))
  63. ;; TODO - replace this with use of notify.el
  64. ;; Notify my when someone mentions my nick.
  65. (defun call-libnotify (matched-type nick msg)
  66. (let* ((cmsg (split-string (clean-message msg)))
  67. (nick (first (split-string nick "!")))
  68. (msg (mapconcat 'identity (rest cmsg) " ")))
  69. (shell-command-to-string
  70. (format "notify-send -u critical '%s says:' '%s'" nick msg))))
  71. (when (eq system-type 'linux)
  72. (add-hook 'erc-text-matched-hook 'call-libnotify))
  73. (defvar erc-notify-nick-alist nil
  74. "Alist of nicks and the last time they tried to trigger a
  75. notification")
  76. (defvar erc-notify-timeout 10
  77. "Number of seconds that must elapse between notifications from
  78. the same person.")
  79. (defun erc-notify-allowed-p (nick &optional delay)
  80. "Return non-nil if a notification should be made for NICK.
  81. If DELAY is specified, it will be the minimum time in seconds
  82. that can occur between two notifications. The default is
  83. `erc-notify-timeout'."
  84. (unless delay (setq delay erc-notify-timeout))
  85. (let ((cur-time (time-to-seconds (current-time)))
  86. (cur-assoc (assoc nick erc-notify-nick-alist))
  87. (last-time nil))
  88. (if cur-assoc
  89. (progn
  90. (setq last-time (cdr cur-assoc))
  91. (setcdr cur-assoc cur-time)
  92. (> (abs (- cur-time last-time)) delay))
  93. (push (cons nick cur-time) erc-notify-nick-alist)
  94. t)))
  95. ;; private message notification
  96. (defun erc-notify-on-private-msg (proc parsed)
  97. (let ((nick (car (erc-parse-user (erc-response.sender parsed))))
  98. (target (car (erc-response.command-args parsed)))
  99. (msg (erc-response.contents parsed)))
  100. (when (and (erc-current-nick-p target)
  101. (not (erc-is-message-ctcp-and-not-action-p msg))
  102. (erc-notify-allowed-p nick))
  103. (shell-command-to-string
  104. (format "notify-send -u critical '%s says:' '%s'" nick msg))
  105. nil)))
  106. (add-hook 'erc-server-PRIVMSG-functions 'erc-notify-on-private-msg)
  107. ;; autoaway setup
  108. (setq erc-auto-discard-away t)
  109. (setq erc-autoaway-idle-seconds 600)
  110. (setq erc-autoaway-use-emacs-idle t)
  111. ;; utf-8 always and forever
  112. (setq erc-server-coding-system '(utf-8 . utf-8))
  113. (defun start-irc ()
  114. "Connect to IRC."
  115. (interactive)
  116. (when (y-or-n-p "Do you want to start IRC? ")
  117. (erc :server "irc.freenode.net" :port 6667 :nick erc-nick)))
  118. (defun filter-server-buffers ()
  119. (delq nil
  120. (mapcar
  121. (lambda (x) (and (erc-server-buffer-p x) x))
  122. (buffer-list))))
  123. (defun stop-irc ()
  124. "Disconnects from all irc servers"
  125. (interactive)
  126. (dolist (buffer (filter-server-buffers))
  127. (message "Server buffer: %s" (buffer-name buffer))
  128. (with-current-buffer buffer
  129. (erc-quit-server "Asta la vista"))))
  130. (provide 'prelude-erc)
  131. ;;; prelude-erc.el ends here