Roll src/third_party/WebKit 0c3f21f:4f9ce20 (svn 202223:202224)
[chromium-blink-merge.git] / docs / erc_irc.md
blobc8e17e77b08d845b222d16d5ac2906508b3f83ec
1 # ERC IRC
3 It's very simple to get started with ERC; just do the following:
5 1.  Optional: Sign up at freenode.net to claim your nickname.
6 1.  M-x
7 1.  erc (and accept default for the first couple of items)
8 1.  /join #chromium
10 You may notice the following problems:
12 *   It's hard to notice when you're mentioned.
13 *   ERC does not have built-in accidental paste prevention, so you might
14     accidentally paste multiple lines of text into the IRC channel.
16 You can modify the following and add it to your .emacs file to fix both of the
17 above. Note that you'll need to install and configure sendxmpp for the mention
18 hack, which also requires you to create an account for your "robot" on e.g.
19 jabber.org:
21 ```el
22 (require 'erc)
24 ;; Notify me when someone mentions my nick or aliases on IRC.
25 (erc-match-mode 1)
26 (add-to-list 'erc-keywords "\\bjoi\\b")
27 ;; Only when I'm sheriff.
28 ;;(add-to-list 'erc-keywords "\\bsheriff\\b")
29 ;;(add-to-list 'erc-keywords "\\bsheriffs\\b")
30 (defun erc-global-notify (matched-type nick msg)
31   (interactive)
32   (when (or (eq matched-type 'current-nick) (eq matched-type 'keyword)))
33   (shell-command
34    (concat "echo \"Mentioned by " (car (split-string nick "!")) ": " msg
35            "\" | sendxmpp joi@google.com")))
36 (add-hook 'erc-text-matched-hook 'erc-global-notify)
38 (defvar erc-last-input-time 0
39   "Time of last call to `erc-send-current-line' (as returned by `float-time'),
40   or 0 if that function has never been called.
41   Used to detect accidental pastes (i.e., large amounts of text
42   accidentally entered into the ERC buffer.)")
44 (defcustom erc-accidental-paste-threshold-seconds 1
45   "Time in seconds that must pass between invocations of
46   `erc-send-current-line' in order for that function to consider
47   the new line to be intentional."
48   :group 'erc
49   :type '(choice number (other :tag "disabled" nil)))
51 (defun erc-send-current-line-with-paste-protection ()
52   "Parse current line and send it to IRC, with accidental paste protection."
53   (interactive)
54   (let ((now (float-time)))
55     (if (or (not erc-accidental-paste-threshold-seconds)
56             (< erc-accidental-paste-threshold-seconds (- now erc-last-input-time)))
57         (save-restriction
58           (widen)
59           (if (< (point) (erc-beg-of-input-line))
60               (erc-error "Point is not in the input area")
61             (let ((inhibit-read-only t)
62                   (str (erc-user-input))
63                   (old-buf (current-buffer)))
64               (if (and (not (erc-server-buffer-live-p))
65                        (not (erc-command-no-process-p str)))
66                   (erc-error "ERC: No process running")
67                 (erc-set-active-buffer (current-buffer))
69                 ;; Kill the input and the prompt
70                 (delete-region (erc-beg-of-input-line)
71                                (erc-end-of-input-line))
73                 (unwind-protect
74                     (erc-send-input str)
75                   ;; Fix the buffer if the command didn't kill it
76                   (when (buffer-live-p old-buf)
77                     (with-current-buffer old-buf
78                       (save-restriction
79                         (widen)
80                         (goto-char (point-max))
81                         (when (processp erc-server-process)
82                           (set-marker (process-mark erc-server-process) (point)))
83                         (set-marker erc-insert-marker (point))
84                         (let ((buffer-modified (buffer-modified-p)))
85                           (erc-display-prompt)
86                           (set-buffer-modified-p buffer-modified))))))
88                 ;; Only when last hook has been run...
89                 (run-hook-with-args 'erc-send-completed-hook str))))
90           (setq erc-last-input-time now))
91       (switch-to-buffer "*ERC Accidental Paste Overflow*")
92       (lwarn 'erc :warning "You seem to have accidentally pasted some text!"))))
94 (add-hook 'erc-mode-hook
95           '(lambda ()
96              (define-key erc-mode-map "\C-m" 'erc-send-current-line-with-paste-protection)
97              ))
98 ```
100 Note: The paste protection code is modified from a paste by user 'yashh' at
101 http://paste.lisp.org/display/78068 (Google cache
102 [here](http://webcache.googleusercontent.com/search?q=cache:p_S9ZKlWZPoJ:paste.lisp.org/display/78068+paste+78068&cd=1&hl=en&ct=clnk&gl=ca&source=www.google.ca)).