-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweechat-spelling.el
89 lines (70 loc) · 3.12 KB
/
weechat-spelling.el
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
;;; weechat-spelling.el --- FlySpell support for WeeChat. -*- lexical-binding: t -*-
;; Copyright (C) 2013 Rüdiger Sonderfeld <ruediger@c-plusplus.de>
;; Author: Rüdiger Sonderfeld <ruediger@c-plusplus.de>
;; Moritz Ulrich <moritz@tarn-vedra.de>
;; Aristid Breitkreuz <aristidb@gmail.com>
;; Keywords: irc chat network weechat
;; URL: https://github.com/the-kenny/weechat.el
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'weechat)
(require 'flyspell)
(require 's)
(defgroup weechat-spelling nil
"FlySpell support for WeeChat."
:link '(url-link "https://github.com/the-kenny/weechat.el")
:prefix "weechat-spelling"
:group 'weechat)
(defcustom weechat-spelling-dictionaries nil
"An alist mapping buffer names to dictionaries.
The format of each entry is (CHANNEL . DICTIONARY). Where CHANNEL is a regexp
matching the buffer name (\"Server.Channel\") and DICTIONARY is the name of an
`ispell' dictionary.
See `ispell-valid-dictionary-list' for a list of valid dictionaries."
:type '(choice
(const :tag "Default dictionary" nil)
(repeat (cons (string :tag "Server.Channel Regex")
(string :tag "Dictionary"))))
:group 'weechat-spelling)
(defun weechat-spelling-init (&optional buffer)
"Initialize spelling in BUFFER or `current-buffer'."
(with-current-buffer (or buffer (current-buffer))
(dolist (entry weechat-spelling-dictionaries)
(when (s-matches? (car entry) (buffer-name))
(setq ispell-local-dictionary (cdr entry))))
(setq flyspell-generic-check-word-predicate #'weechat-mode-flyspell-verify)
(flyspell-mode 1)))
(defvar weechat-prompt-end-marker) ;; See weechat.el
(defvar weechat-user-list) ;; See weechat.el
(defun weechat-mode-flyspell-verify ()
"Function used for `flyspell-generic-check-word-predicate' in `weechat-mode'."
(not (or
;; Spell-check only input line
(< (point) weechat-prompt-end-marker)
(let ((word-data (flyspell-get-word)))
(or
;; Don't spell-check nick names
(member (car word-data) weechat-user-list)
;; Don't spell-check words starting with a /
(eq (char-before (cadr word-data)) ?/))))))
(put 'weechat-mode
'flyspell-mode-predicate
#'weechat-mode-flyspell-verify)
(weechat-do-buffers (weechat-spelling-init))
(add-hook 'weechat-mode-hook #'weechat-spelling-init)
(defun weechat-spelling-unload-function ()
(weechat-do-buffers (flyspell-mode -1))
nil)
(provide 'weechat-spelling)
;;; weechat-spelling.el ends here