]> crepu.dev Git - config.git/blob - djavu-asus/emacs/elpa/company-20230926.32/company-ispell.el
3cb7c5d693bb4bf172231678810bf321b6b916f7
[config.git] / djavu-asus / emacs / elpa / company-20230926.32 / company-ispell.el
1 ;;; company-ispell.el --- company-mode completion backend using Ispell
2
3 ;; Copyright (C) 2009-2011, 2013-2016, 2018, 2021 Free Software Foundation, Inc.
4
5 ;; Author: Nikolaj Schumacher
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
21
22
23 ;;; Commentary:
24 ;;
25
26 ;;; Code:
27
28 (require 'company)
29 (require 'cl-lib)
30 (require 'ispell)
31
32 (defgroup company-ispell nil
33 "Completion backend using Ispell."
34 :group 'company)
35
36 (defcustom company-ispell-dictionary nil
37 "Dictionary to use for `company-ispell'.
38 If nil, use `ispell-complete-word-dict'."
39 :type '(choice (const :tag "default (nil)" nil)
40 (file :tag "dictionary" t)))
41
42 (defvar company-ispell-available 'unknown)
43
44 (defalias 'company-ispell--lookup-words
45 (if (fboundp 'ispell-lookup-words)
46 'ispell-lookup-words
47 'lookup-words))
48
49 (defun company-ispell-available ()
50 (when (eq company-ispell-available 'unknown)
51 (condition-case err
52 (progn
53 (company-ispell--lookup-words "WHATEVER")
54 (setq company-ispell-available t))
55 (error
56 (message "Company-Ispell: %s" (error-message-string err))
57 (setq company-ispell-available nil))))
58 company-ispell-available)
59
60 ;;;###autoload
61 (defun company-ispell (command &optional arg &rest ignored)
62 "`company-mode' completion backend using Ispell."
63 (interactive (list 'interactive))
64 (cl-case command
65 (interactive (company-begin-backend 'company-ispell))
66 (prefix (when (company-ispell-available)
67 (company-grab-word)))
68 (candidates
69 (let ((words (company-ispell--lookup-words
70 arg
71 (or company-ispell-dictionary ispell-complete-word-dict)))
72 (completion-ignore-case t))
73 (if (string= arg "")
74 ;; Small optimization.
75 words
76 ;; Work around issue #284.
77 (all-completions arg words))))
78 (kind 'text)
79 (sorted t)
80 (ignore-case 'keep-prefix)))
81
82 (provide 'company-ispell)
83 ;;; company-ispell.el ends here