annotate lisp/erc/erc-spelling.el @ 75373:f636c357cd5d

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Mon, 22 Jan 2007 00:10:19 +0000
parents 7a3f13e2dd57
children 2fae574a2382
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
7a3f13e2dd57 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 72249
diff changeset
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
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
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
268989954f79 Merge from erc--emacs--21
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
43 (dolist (buffer (erc-buffer-list))
268989954f79 Merge from erc--emacs--21
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
44 (when (buffer-live-p buffer)
268989954f79 Merge from erc--emacs--21
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
45 (with-current-buffer buffer (erc-spelling-init)))))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
46 ((remove-hook 'erc-connect-pre-hook 'erc-spelling-init)
72249
268989954f79 Merge from erc--emacs--21
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
47 (dolist (buffer (erc-buffer-list))
268989954f79 Merge from erc--emacs--21
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
48 (when (buffer-live-p buffer)
268989954f79 Merge from erc--emacs--21
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
49 (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
50
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
51 (defcustom erc-spelling-dictionaries nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
52 "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
53 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
54 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
55 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
56 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
57 name here."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
58 :type '(choice (const nil)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
59 (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
60 (string :tag "Dictionary"))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
61 :group 'erc-spelling)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
62
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
63 (defun erc-spelling-init ()
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
64 "Enable flyspell mode in an ERC buffer."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
65 (let ((name (downcase (buffer-name)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
66 (dicts erc-spelling-dictionaries))
68630
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
67 (when dicts
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
68 (while (and dicts
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
69 (not (string= name (downcase (caar dicts)))))
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
70 (setq dicts (cdr dicts)))
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
71 (setq ispell-local-dictionary
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
72 (if dicts
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
73 (cadr (car dicts))
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
74 (let ((server (erc-server-buffer)))
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
75 (if server
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
76 (with-current-buffer server
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
77 ispell-local-dictionary)
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
78 nil))))))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
79 (setq flyspell-generic-check-word-p 'erc-spelling-flyspell-verify)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
80 (flyspell-mode 1))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
81
68630
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
82 (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
83 "Unhighlight the given WORD.
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
84 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
85 (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
86 (end (nth 2 word)))
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
87 (flyspell-unhighlight-at beg)
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
88 (when (> end beg)
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
89 (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
90
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
91 (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
92 "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
93 (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
94 flyspell-word)))
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
95 (when word-data
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
96 (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
97 nil)
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
98 ;; 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
99 ((and erc-channel-users
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
100 (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
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 ;; 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
104 ((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
105 (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
106 nil)
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
107 (t t)))))
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
108
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
109 (put 'erc-mode
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
110 'flyspell-mode-predicate
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
111 'erc-spelling-flyspell-verify)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
112
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
113 (provide 'erc-spelling)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
114
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
115 ;; 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
116 ;;; erc-spelling.el ends here