-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-rcirc.el
129 lines (114 loc) · 4.32 KB
/
init-rcirc.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
;; You can autoload, but at the end of this block we'll
;; connect to two networks anyway.
(require 'rcirc)
;; Stop rcirc from printing /away message
(defun rcirc-handler-301 (process cmd sender args)
"/away message handler.")
;; Use fly spell check
(add-hook 'rcirc-mode-hook (lambda ()
(flyspell-mode 1)))
;; Keep input line at bottom.
(add-hook 'rcirc-mode-hook
(lambda ()
(set (make-local-variable 'scroll-conservatively)
8192)))
;; Reconnect
(eval-after-load 'rcirc
'(defun-rcirc-command reconnect (arg)
"Reconnect the server process."
(interactive "i")
(unless process
(error "There's no process for this target"))
(let* ((server (car (process-contact process)))
(port (process-contact process :service))
(nick (rcirc-nick process))
channels query-buffers)
(dolist (buf (buffer-list))
(with-current-buffer buf
(when (eq process (rcirc-buffer-process))
(remove-hook 'change-major-mode-hook
'rcirc-change-major-mode-hook)
(if (rcirc-channel-p rcirc-target)
(setq channels (cons rcirc-target channels))
(setq query-buffers (cons buf query-buffers))))))
(delete-process process)
(rcirc-connect server port nick
rcirc-default-user-name
rcirc-default-user-full-name
channels))))
;; Turn the debugging mode on
;(setq rcirc-debug-flag t)
;; Adjust the colors of one of the faces.
(set-face-foreground 'rcirc-my-nick "red" nil)
;; Include date in time stamp.
(setq rcirc-time-format "%Y-%m-%d %H:%M ")
;; Change user info
(setq rcirc-default-nick "chenbin0")
(setq rcirc-default-user-name "chenbin0")
(setq rcirc-default-full-name "Chen Bin")
(let ((auth-file "~/private/.auth-rcirc.el"))
(when (file-readable-p auth-file)
(load auth-file)))
;; Join these channels at startup.
(if (< emacs-major-version 23)
(setq rcirc-startup-channels-alist nil)
(setq rcirc-server-alist
'(("irc.freenode.net" :channels ("#emacs"))))
)
(defun freenode ()
(interactive)
(rcirc nil))
(defun bitlbee ()
(interactive)
(rcirc-connect
"localhost" "6667" rcirc-default-nick rcirc-default-user-name
rcirc-default-full-name
"&bitlbee"))
(defun rbitlbee ()
(interactive)
(rcirc-connect
"im.bitlbee.org" "6667" rcirc-default-nick rcirc-default-user-name
rcirc-default-full-name
"&bitlbee"))
;; Notifications
(defun th-rcirc-notification (process sender response target text)
(let ((my-nick (rcirc-nick process)))
(when (and (string= response "PRIVMSG")
(not (string= sender my-nick))
(not (and (string= sender "root")
(string= target "&bitlbee")))
(or
;; BitlBee IM messages
(string-match "localhost" (format "%s" process))
;; Messages that mention my name
(string-match my-nick text)))
(notify "rcirc" target))))
(add-hook 'rcirc-print-hooks 'th-rcirc-notification)
; Minimal logging
(add-hook 'rcirc-print-hooks 'rcirc-write-log)
(defvar my-rcirc-log-dir "~/.irclog/")
(defun rcirc-write-log (process sender response target text)
(with-temp-buffer
;; Sometimes TARGET is a buffer :-(
(when (bufferp target)
(setq target (with-current-buffer buffer rcirc-target)))
;; Sometimes buffer is not anything at all!
(unless (or (null target) (string= target ""))
;; Print the line into the temp buffer.
(insert (format-time-string "%Y-%m-%d %H:%M "))
(insert (format "%-16s " (rcirc-user-nick sender)))
(unless (string= response "PRIVMSG")
(insert "/" (downcase response) " "))
(insert text "\n")
;; Append the line to the appropriate logfile.
(let* ((coding-system-for-write 'no-conversion)
(log-dir (concat my-rcirc-log-dir
(downcase target)
(format-time-string "/%Y/%m/")))
(log-file (format-time-string "%d")))
(unless (file-exists-p log-dir)
(make-directory log-dir t))
(write-region (point-min) (point-max)
(concat log-dir log-file)
t 'quietly)))))
(provide 'init-rcirc)