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.

160 lines
4.9 KiB

  1. ;;; prelude-erc.el --- Emacs Prelude: ERC mode configuration.
  2. ;;
  3. ;; Copyright © 2011-2021 Bozhidar Batsov
  4. ;;
  5. ;; Author: Bozhidar Batsov <bozhidar@batsov.com>
  6. ;; URL: https://github.com/bbatsov/prelude
  7. ;; This file is not part of GNU Emacs.
  8. ;;; Commentary:
  9. ;; Some basic configuration for ERC mode, which should make your
  10. ;; IRC experience a bit more pleasant.
  11. ;;; License:
  12. ;; This program is free software; you can redistribute it and/or
  13. ;; modify it under the terms of the GNU General Public License
  14. ;; as published by the Free Software Foundation; either version 3
  15. ;; of the License, or (at your option) any later version.
  16. ;;
  17. ;; This program is distributed in the hope that it will be useful,
  18. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. ;; GNU General Public License for more details.
  21. ;;
  22. ;; You should have received a copy of the GNU General Public License
  23. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  24. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  25. ;; Boston, MA 02110-1301, USA.
  26. ;;; Code:
  27. (require 'erc)
  28. (require 'erc-log)
  29. (require 'erc-notify)
  30. (require 'erc-spelling)
  31. (require 'erc-autoaway)
  32. ;; Interpret mIRC-style color commands in IRC chats
  33. (setq erc-interpret-mirc-color t)
  34. ;; The following are commented out by default, but users of other
  35. ;; non-Emacs IRC clients might find them useful.
  36. ;; Kill buffers for channels after /part
  37. (setq erc-kill-buffer-on-part t)
  38. ;; Kill buffers for private queries after quitting the server
  39. (setq erc-kill-queries-on-quit t)
  40. ;; Kill buffers for server messages after quitting the server
  41. (setq erc-kill-server-buffer-on-quit t)
  42. ;; open query buffers in the current window
  43. (setq erc-query-display 'buffer)
  44. ;; exclude boring stuff from tracking
  45. (erc-track-mode t)
  46. (setq erc-track-exclude-types '("JOIN" "NICK" "PART" "QUIT" "MODE"
  47. "324" "329" "332" "333" "353" "477"))
  48. ;; logging
  49. (setq erc-log-channels-directory "~/.erc/logs/")
  50. (if (not (file-exists-p erc-log-channels-directory))
  51. (mkdir erc-log-channels-directory t))
  52. (setq erc-save-buffer-on-part t)
  53. ;; FIXME - this advice is wrong and is causing problems on Emacs exit
  54. ;; (defadvice save-buffers-kill-emacs (before save-logs (arg) activate)
  55. ;; (save-some-buffers t (lambda () (when (eq major-mode 'erc-mode) t))))
  56. ;; truncate long irc buffers
  57. (erc-truncate-mode +1)
  58. ;; enable spell checking
  59. (when prelude-flyspell
  60. (erc-spelling-mode 1))
  61. ;; set different dictionaries by different servers/channels
  62. ;;(setq erc-spelling-dictionaries '(("#emacs" "american")))
  63. (defvar erc-notify-nick-alist nil
  64. "Alist of nicks and the last time they tried to trigger a
  65. notification")
  66. (defvar erc-notify-timeout 10
  67. "Number of seconds that must elapse between notifications from
  68. the same person.")
  69. (defun erc-notify-allowed-p (nick &optional delay)
  70. "Return non-nil if a notification should be made for NICK.
  71. If DELAY is specified, it will be the minimum time in seconds
  72. that can occur between two notifications. The default is
  73. `erc-notify-timeout'."
  74. (unless delay (setq delay erc-notify-timeout))
  75. (let ((cur-time (time-to-seconds (current-time)))
  76. (cur-assoc (assoc nick erc-notify-nick-alist))
  77. (last-time nil))
  78. (if cur-assoc
  79. (progn
  80. (setq last-time (cdr cur-assoc))
  81. (setcdr cur-assoc cur-time)
  82. (> (abs (- cur-time last-time)) delay))
  83. (push (cons nick cur-time) erc-notify-nick-alist)
  84. t)))
  85. ;; autoaway setup
  86. (setq erc-auto-discard-away t)
  87. (setq erc-autoaway-idle-seconds 600)
  88. (setq erc-autoaway-use-emacs-idle t)
  89. ;; utf-8 always and forever
  90. (setq erc-server-coding-system '(utf-8 . utf-8))
  91. (defvar my-fav-irc '( "irc.freenode.net" )
  92. "Stores the list of IRC servers that you want to connect to with start-irc.")
  93. (defvar bye-irc-message "Asta la vista"
  94. "Message string to be sent while quitting IRC.")
  95. (defcustom prelude-new-irc-persp nil
  96. "True (t) means start IRC in new perspective."
  97. :type 'boolean
  98. :require 'prelude-erc
  99. :group 'prelude)
  100. (defun connect-to-erc (server)
  101. "Connects securely to IRC SERVER over TLS at port 6697."
  102. (erc-tls :server server
  103. :port 6697
  104. :nick erc-nick ))
  105. (defun start-irc ()
  106. "Connect to IRC?"
  107. (interactive)
  108. (when (y-or-n-p "Do you want to start IRC? ")
  109. (when prelude-new-irc-persp
  110. (persp-switch "IRC"))
  111. (mapcar 'connect-to-erc my-fav-irc)))
  112. (defun filter-server-buffers ()
  113. (delq nil
  114. (mapcar
  115. (lambda (x) (and (erc-server-buffer-p x) x))
  116. (buffer-list))))
  117. (defun stop-irc ()
  118. "Disconnects from all irc servers."
  119. (interactive)
  120. (when prelude-new-irc-persp
  121. (persp-switch "IRC"))
  122. (dolist (buffer (filter-server-buffers))
  123. (message "Server buffer: %s" (buffer-name buffer))
  124. (with-current-buffer buffer
  125. (erc-quit-server bye-irc-message)))
  126. (when prelude-new-irc-persp
  127. (persp-kill "IRC")))
  128. (provide 'prelude-erc)
  129. ;;; prelude-erc.el ends here