andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 1 | # ERC IRC |
| 2 | |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 3 | It's very simple to get started with ERC; just do the following: |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 4 | |
| 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 |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 9 | |
| 10 | You may notice the following problems: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 11 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 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. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 15 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 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: |
| 20 | |
| 21 | ```el |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 22 | (require 'erc) |
| 23 | |
| 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) |
| 37 | |
| 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.)") |
| 43 | |
| 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))) |
| 50 | |
| 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)) |
| 68 | |
| 69 | ;; Kill the input and the prompt |
| 70 | (delete-region (erc-beg-of-input-line) |
| 71 | (erc-end-of-input-line)) |
| 72 | |
| 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)))))) |
| 87 | |
| 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!")))) |
| 93 | |
| 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 | ``` |
| 99 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 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)). |