Mercurial > emacs
annotate lisp/erc/erc-spelling.el @ 84033:52ef29977fe9
Move to ../doc/lispref
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Thu, 06 Sep 2007 04:14:59 +0000 |
parents | 85d67fae9a94 |
children | 5f92874bde07 |
rev | line source |
---|---|
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
1 ;;; erc-spelling.el --- use flyspell in ERC |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
2 |
75346 | 3 ;; Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
4 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
5 ;; Author: Jorgen Schaefer <forcer@forcix.cx> |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
6 ;; Keywords: irc |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
7 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcSpelling |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
8 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
10 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by |
78219
85d67fae9a94
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
76856
diff
changeset
|
13 ;; the Free Software Foundation; either version 3, or (at your option) |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
14 ;; any later version. |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
15 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
19 ;; GNU General Public License for more details. |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
20 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
21 ;; You should have received a copy of the GNU General Public License |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
24 ;; Boston, MA 02110-1301, USA. |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
25 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
26 ;;; Commentary: |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
27 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
28 ;; This is an ERC module to enable flyspell mode in ERC buffers. This |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
29 ;; ensures correct behavior of flyspell, and even sets up a |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
30 ;; channel-local dictionary if so required. |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
31 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
32 ;;; Code: |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
33 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
34 (require 'erc) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
35 (require 'flyspell) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
36 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
37 ;;;###autoload (autoload 'erc-spelling-mode "erc-spelling" nil t) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
38 (define-erc-module spelling nil |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
39 "Enable flyspell mode in ERC buffers." |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
40 ;; Use erc-connect-pre-hook instead of erc-mode-hook as pre-hook is |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
41 ;; called AFTER the server buffer is initialized. |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
42 ((add-hook 'erc-connect-pre-hook 'erc-spelling-init) |
72249 | 43 (dolist (buffer (erc-buffer-list)) |
76856 | 44 (erc-spelling-init buffer))) |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
45 ((remove-hook 'erc-connect-pre-hook 'erc-spelling-init) |
72249 | 46 (dolist (buffer (erc-buffer-list)) |
76856 | 47 (with-current-buffer buffer (flyspell-mode 0))))) |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
48 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
49 (defcustom erc-spelling-dictionaries nil |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
50 "An alist mapping buffer names to dictionaries. |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
51 The `car' of every cell is a buffer name, the `cadr' is the |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
52 string name of an associated dictionary. |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
53 The dictionary is inherited from server buffers, so if you want a |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
54 default dictionary for some server, you can use a server buffer |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
55 name here." |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
56 :type '(choice (const nil) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
57 (repeat (cons (string :tag "Buffer name") |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
58 (string :tag "Dictionary")))) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
59 :group 'erc-spelling) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
60 |
76856 | 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))) | |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
77 |
68630
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
78 (defun erc-spelling-unhighlight-word (word) |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
79 "Unhighlight the given WORD. |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
80 The cadr is the beginning and the caddr is the end." |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
81 (let ((beg (nth 1 word)) |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
82 (end (nth 2 word))) |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
83 (flyspell-unhighlight-at beg) |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
84 (when (> end beg) |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
85 (flyspell-unhighlight-at (1- end))))) |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
86 |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
87 (defun erc-spelling-flyspell-verify () |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
88 "Flyspell only the input line, nothing else." |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
89 (let ((word-data (and (boundp 'flyspell-word) |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
90 flyspell-word))) |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
91 (when word-data |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
92 (cond ((< (point) erc-input-marker) |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
93 nil) |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
94 ;; don't spell-check names of users |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
95 ((and erc-channel-users |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
96 (erc-get-channel-user (car word-data))) |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
97 (erc-spelling-unhighlight-word word-data) |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
98 nil) |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
99 ;; if '/' occurs before the word, don't spell-check it |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
100 ((eq (char-before (nth 1 word-data)) ?/) |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
101 (erc-spelling-unhighlight-word word-data) |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
102 nil) |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
103 (t t))))) |
86c478cccc57
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents:
68451
diff
changeset
|
104 |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
105 (put 'erc-mode |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
106 'flyspell-mode-predicate |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
107 'erc-spelling-flyspell-verify) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
108 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
109 (provide 'erc-spelling) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
110 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
111 ;; arch-tag: 04ae1c46-0fd1-4e1a-8b80-55bfa471c945 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
112 ;;; erc-spelling.el ends here |