]> code.delx.au - gnu-emacs-elpa/commitdiff
Added ispell back-end.
authorNikolaj Schumacher <git@nschum.de>
Thu, 12 Mar 2009 17:35:12 +0000 (18:35 +0100)
committerNikolaj Schumacher <git@nschum.de>
Fri, 20 Mar 2009 08:46:05 +0000 (09:46 +0100)
company-ispell.el [new file with mode: 0644]
company.el

diff --git a/company-ispell.el b/company-ispell.el
new file mode 100644 (file)
index 0000000..a581170
--- /dev/null
@@ -0,0 +1,21 @@
+(require 'company)
+(require 'ispell)
+(eval-when-compile (require 'cl))
+
+(defcustom company-ispell-dictionary nil
+  "*Dictionary to use for `company-ispell'.
+If nil, use `ispell-complete-word-dict'."
+  :group 'company
+  :type '(choice (const :tag "default (nil)" nil)
+                 (file :tag "dictionary" t)))
+
+(defun company-ispell (command &optional arg &rest ignored)
+  (case command
+    ('prefix (company-grab "\\<\\w+\\>"))
+    ('candidates (lookup-words arg (or company-ispell-dictionary
+                                       ispell-complete-word-dict)))
+    ('sorted t)
+    ('ignore-case t)))
+
+(provide 'company-ispell)
+;;; company-ispell.el ends here
index a5b4662b5d78018b844e90e5f1bdcafce46d9d8f..6166363927e5056c4cde58ae97257845bad45103 100644 (file)
@@ -93,7 +93,8 @@
                                 company-preview-if-just-one-frontend)
                          (function :tag "custom function" nil))))
 
-(defcustom company-backends '(company-elisp company-nxml company-css)
+(defcustom company-backends '(company-elisp company-nxml company-css
+                              company-ispell)
   "*"
   :group 'company
   :type '(repeat (function :tag "function" nil)))
   (let ((offset (- company-selection display-limit -1)))
     (max offset 0)))
 
+(defsubst company-reformat (candidate)
+  ;; company-ispell needs this, because the results are always lower-case
+  ;; It's mory efficient to fix it only when they are displayed.
+  (concat company-prefix (substring candidate (length company-prefix))))
+
 (defsubst company-should-complete (prefix)
   (and (eq company-idle-delay t)
        (>= (length prefix) company-minimum-prefix-length)))
 
 (defun company-begin ()
   (or (company-continue-or-cancel)
-      (let ((completion-ignore-case nil) ;; TODO: make this optional
-            prefix)
+      (let (prefix)
         (dolist (backend company-backends)
           (unless (fboundp backend)
             (ignore-errors (require backend nil t)))
                         company-candidates
                         (funcall company-backend 'candidates prefix)
                         company-common
-                        (try-completion prefix company-candidates)
+                        (let ((completion-ignore-case (funcall backend
+                                                               'ignore-case)))
+                          (try-completion prefix company-candidates))
                         company-selection 0
                         company-point (point))
                   (unless (funcall company-backend 'sorted)
       (setq width (max (length (pop lines-copy)) width)))
     (setq width (min width (- (window-width) column)))
     (dotimes (i len)
-      (push (company-fill-propertize (pop lines) width (equal i selection))
+      (push (company-fill-propertize (company-reformat (pop lines))
+                                     width (equal i selection))
             new))
     (nreverse new)))
 
         (len -1)
         comp msg)
     (while candidates
-      (setq comp (pop candidates)
+      (setq comp (company-reformat (pop candidates))
             len (+ len 1 (length comp)))
       (if (>= len limit)
           (setq candidates nil)