annotate lisp/erc/erc-spelling.el @ 112408:04c350138c72

* man.el (Man-highlight-references0): Use make-button (Bug#7881).
author Chong Yidong <cyd@stupidchicken.com>
date Fri, 21 Jan 2011 22:53:06 -0500
parents ef719132ddfa
children
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
112218
376148b31b5e Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
3 ;; Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 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
94660
2a734255bcc7 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79706
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
68451
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
94660
2a734255bcc7 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79706
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
2a734255bcc7 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79706
diff changeset
14 ;; (at your option) any later version.
68451
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
94660
2a734255bcc7 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79706
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
23
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
24 ;;; Commentary:
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 ;; 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
27 ;; 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
28 ;; 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
29
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
30 ;;; Code:
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 (require 'erc)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
33 (require 'flyspell)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
34
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
35 ;;;###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
36 (define-erc-module spelling nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
37 "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
38 ;; 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
39 ;; 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
40 ((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
41 (dolist (buffer (erc-buffer-list))
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
42 (erc-spelling-init buffer)))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
43 ((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
44 (dolist (buffer (erc-buffer-list))
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
45 (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
46
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
47 (defcustom erc-spelling-dictionaries nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
48 "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
49 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
50 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
51 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
52 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
53 name here."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
54 :type '(choice (const nil)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
55 (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
56 (string :tag "Dictionary"))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
57 :group 'erc-spelling)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
58
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
59 (defun erc-spelling-init (buffer)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
60 "Enable flyspell mode in an ERC buffer.
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
61 The current buffer is given by BUFFER."
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
62 (with-current-buffer buffer
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
63 (let ((name (downcase (buffer-name)))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
64 (dicts erc-spelling-dictionaries))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
65 (when dicts
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
66 (while (and dicts
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
67 (not (string= name (downcase (caar dicts)))))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
68 (setq dicts (cdr dicts)))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
69 (setq ispell-local-dictionary
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
70 (if dicts
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
71 (cadr (car dicts))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
72 (erc-with-server-buffer ispell-local-dictionary)))))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
73 (setq flyspell-generic-check-word-p 'erc-spelling-flyspell-verify)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
74 (flyspell-mode 1)))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
75
68630
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
76 (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
77 "Unhighlight the given WORD.
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
78 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
79 (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
80 (end (nth 2 word)))
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
81 (flyspell-unhighlight-at beg)
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
82 (when (> end beg)
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
83 (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
84
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
85 (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
86 "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
87 (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
88 flyspell-word)))
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
89 (when word-data
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
90 (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
91 nil)
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
92 ;; 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
93 ((and erc-channel-users
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
94 (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
95 (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
96 nil)
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
97 ;; 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
98 ((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
99 (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
100 nil)
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
101 (t t)))))
86c478cccc57 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-46
Miles Bader <miles@gnu.org>
parents: 68451
diff changeset
102
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
103 (put 'erc-mode
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
104 'flyspell-mode-predicate
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
105 'erc-spelling-flyspell-verify)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
106
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
107 (provide 'erc-spelling)
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 ;;; erc-spelling.el ends here