]> code.delx.au - gnu-emacs-elpa/commitdiff
Added company-elisp-functions-only-in-context option.
authorNikolaj Schumacher <git@nschum.de>
Fri, 27 Mar 2009 20:23:30 +0000 (21:23 +0100)
committerNikolaj Schumacher <git@nschum.de>
Sat, 28 Mar 2009 18:02:33 +0000 (19:02 +0100)
company-elisp.el
company.el

index b312bf27f8d3e3811f1a84cef0e529af04c82b7c..b77851e18b741135413891ba1b4701d2b8da3795 100644 (file)
 (require 'company)
 (eval-when-compile (require 'cl))
 
+(defcustom company-elisp-functions-only-in-context nil
+  "*If enabled, offer lisp functions only in appropriate contexts.
+Functions are offered for completion only after ' and \(."
+  :group 'company
+  :type '(choice (const :tag "off (nil)" nil)
+                 (integer :tag "count" t)))
+
 (defvar company-lisp-symbol-regexp
   "\\_<\\(\\sw\\|\\s_\\)+\\_>\\=")
 
 
 (defun company-elisp-candidates (prefix)
   (let* ((completion-ignore-case nil)
-         (candidates (all-completions prefix obarray 'company-elisp-predicate)))
+         (before (char-before (- (point) (length prefix))))
+         (predicate (if (and company-elisp-functions-only-in-context
+                             (not (eq before ?')))
+                        (if (eq before ?\()
+                            'fboundp
+                          'boundp)
+                      'company-elisp-predicate))
+         (candidates (all-completions prefix obarray predicate)))
     (company-elisp-parse-local prefix candidates)))
 
 (defun company-elisp-doc (symbol)
@@ -77,7 +91,8 @@
          (match-string 0 doc))))
 
 (defun company-elisp (command &optional arg &rest ignored)
-  "A `company-mode' completion back-end for `emacs-lisp-mode'."
+  "A `company-mode' completion back-end for `emacs-lisp-mode'.
+See `company-elisp-functions-only-in-context'."
   (case command
     ('prefix (and (eq (derived-mode-p 'emacs-lisp-mode) 'emacs-lisp-mode)
                   (company-grab-lisp-symbol)))
index 12be691410956b7d8d73f276b8e91472f08a9c49..ea482c7e033cb3796304a64b0f45c45b5afdc8bd 100644 (file)
@@ -56,6 +56,7 @@
 ;;
 ;;; Change Log:
 ;;
+;;    Added `company-elisp-functions-only-in-context' option.
 ;;    The mouse can now be used for selection.
 ;;
 ;; 2009-03-22 (0.2)