| 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 |
(require 'erc) |
|---|
| 35 |
(require 'flyspell) |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
(define-erc-module spelling nil |
|---|
| 39 |
"Enable flyspell mode in ERC buffers." |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
((add-hook 'erc-connect-pre-hook 'erc-spelling-init) |
|---|
| 43 |
(dolist (buffer (erc-buffer-list)) |
|---|
| 44 |
(erc-spelling-init buffer))) |
|---|
| 45 |
((remove-hook 'erc-connect-pre-hook 'erc-spelling-init) |
|---|
| 46 |
(dolist (buffer (erc-buffer-list)) |
|---|
| 47 |
(with-current-buffer buffer (flyspell-mode 0))))) |
|---|
| 48 |
|
|---|
| 49 |
(defcustom erc-spelling-dictionaries nil |
|---|
| 50 |
"An alist mapping buffer names to dictionaries. |
|---|
| 51 |
The `car' of every cell is a buffer name, the `cadr' is the |
|---|
| 52 |
string name of an associated dictionary. |
|---|
| 53 |
The dictionary is inherited from server buffers, so if you want a |
|---|
| 54 |
default dictionary for some server, you can use a server buffer |
|---|
| 55 |
name here." |
|---|
| 56 |
:type '(choice (const nil) |
|---|
| 57 |
(repeat (cons (string :tag "Buffer name") |
|---|
| 58 |
(string :tag "Dictionary")))) |
|---|
| 59 |
:group 'erc-spelling) |
|---|
| 60 |
|
|---|
| 61 |
(defun erc-spelling-init (buffer) |
|---|
| 62 |
"Enable flyspell mode in an ERC buffer. |
|---|
| 63 |
The current buffer is given by BUFFER." |
|---|
| 64 |
(with-current-buffer buffer |
|---|
| 65 |
(let ((name (downcase (buffer-name))) |
|---|
| 66 |
(dicts erc-spelling-dictionaries)) |
|---|
| 67 |
(when dicts |
|---|
| 68 |
(while (and dicts |
|---|
| 69 |
(not (string= name (downcase (caar dicts))))) |
|---|
| 70 |
(setq dicts (cdr dicts))) |
|---|
| 71 |
(setq ispell-local-dictionary |
|---|
| 72 |
(if dicts |
|---|
| 73 |
(cadr (car dicts)) |
|---|
| 74 |
(erc-with-server-buffer ispell-local-dictionary))))) |
|---|
| 75 |
(setq flyspell-generic-check-word-p 'erc-spelling-flyspell-verify) |
|---|
| 76 |
(flyspell-mode 1))) |
|---|
| 77 |
|
|---|
| 78 |
(defun erc-spelling-unhighlight-word (word) |
|---|
| 79 |
"Unhighlight the given WORD. |
|---|
| 80 |
The cadr is the beginning and the caddr is the end." |
|---|
| 81 |
(let ((beg (nth 1 word)) |
|---|
| 82 |
(end (nth 2 word))) |
|---|
| 83 |
(flyspell-unhighlight-at beg) |
|---|
| 84 |
(when (> end beg) |
|---|
| 85 |
(flyspell-unhighlight-at (1- end))))) |
|---|
| 86 |
|
|---|
| 87 |
(defun erc-spelling-flyspell-verify () |
|---|
| 88 |
"Flyspell only the input line, nothing else." |
|---|
| 89 |
(let ((word-data (and (boundp 'flyspell-word) |
|---|
| 90 |
flyspell-word))) |
|---|
| 91 |
(when word-data |
|---|
| 92 |
(cond ((< (point) erc-input-marker) |
|---|
| 93 |
nil) |
|---|
| 94 |
|
|---|
| 95 |
((and erc-channel-users |
|---|
| 96 |
(erc-get-channel-user (car word-data))) |
|---|
| 97 |
(erc-spelling-unhighlight-word word-data) |
|---|
| 98 |
nil) |
|---|
| 99 |
|
|---|
| 100 |
((eq (char-before (nth 1 word-data)) ?/) |
|---|
| 101 |
(erc-spelling-unhighlight-word word-data) |
|---|
| 102 |
nil) |
|---|
| 103 |
(t t))))) |
|---|
| 104 |
|
|---|
| 105 |
(put 'erc-mode |
|---|
| 106 |
'flyspell-mode-predicate |
|---|
| 107 |
'erc-spelling-flyspell-verify) |
|---|
| 108 |
|
|---|
| 109 |
(provide 'erc-spelling) |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|