]> code.delx.au - gnu-emacs-elpa/commitdiff
Added command to filter based on search.
authorNikolaj Schumacher <git@nschum.de>
Mon, 16 Mar 2009 18:45:54 +0000 (19:45 +0100)
committerNikolaj Schumacher <git@nschum.de>
Fri, 20 Mar 2009 11:58:28 +0000 (12:58 +0100)
company.el

index c613e0b15fdda7987bf240f25f9c34e13e240916..ce55081a16c8944579156fc57f6cb6f71a391303 100644 (file)
 (defvar company-candidates-cache nil)
 (make-variable-buffer-local 'company-candidates-cache)
 
+(defvar company-candidates-predicate nil)
+(make-variable-buffer-local 'company-candidates-predicate)
+
 (defvar company-common nil)
 (make-variable-buffer-local 'company-common)
 
           company-selection-changed t)
     (company-call-frontends 'update)))
 
+(defun company-apply-predicate (candidates predicate)
+  (let (new)
+    (dolist (c candidates)
+      (when (funcall predicate c)
+        (push c new)))
+    (nreverse new)))
+
 (defsubst company-calculate-candidates (prefix)
   (or (setq company-candidates (cdr (assoc prefix company-candidates-cache)))
       (let ((len (length prefix))
             (return t))))
       (progn
         (setq company-candidates (funcall company-backend 'candidates prefix))
+        (when company-candidates-predicate
+          (setq company-candidates
+                (company-apply-predicate company-candidates
+                                         company-candidates-predicate)))
         (unless (funcall company-backend 'sorted)
           (setq company-candidates (sort company-candidates 'string<)))))
   (unless (assoc prefix company-candidates-cache)
         company-prefix nil
         company-candidates nil
         company-candidates-cache nil
+        company-candidates-predicate nil
         company-common nil
         company-selection 0
         company-selection-changed nil
         (ding)
       (company-set-selection (- company-selection pos 1) t))))
 
+(defun company-search-kill-others ()
+  (interactive)
+  (let ((predicate `(lambda (candidate)
+                      (string-match ,company-search-string candidate))))
+    (company-cancel)
+    (setq company-candidates-predicate predicate)
+    (company-manual-begin)))
+
 (defun company-search-abort ()
   (interactive)
   (company-set-selection company-search-old-selection t)
     (define-key keymap "\C-g" 'company-search-abort)
     (define-key keymap "\C-s" 'company-search-repeat-forward)
     (define-key keymap "\C-r" 'company-search-repeat-backward)
+    (define-key keymap "\C-o" 'company-search-kill-others)
     keymap))
 
 (define-minor-mode company-search-mode