;;; company-elisp.el --- A company-mode completion back-end for emacs-lisp-mode -*- lexical-binding: t -*-
-;; Copyright (C) 2009, 2011-2012 Free Software Foundation, Inc.
+;; Copyright (C) 2009, 2011-2013 Free Software Foundation, Inc.
;; Author: Nikolaj Schumacher
(defcustom company-elisp-show-locals-first t
"If enabled, locally bound variables and functions are displayed
-first in the candidates list.")
+first in the candidates list."
+ :group 'company
+ :type '(choice (const :tag "Off" nil)
+ (const :tag "On" t)))
-(defun company-grab-lisp-symbol ()
+(defun company-elisp--prefix ()
(let ((prefix (company-grab-symbol)))
(if prefix
(unless (and (company-in-string-or-comment)
prefix)
'stop)))
-(defun company-elisp-predicate (symbol)
+(defun company-elisp--predicate (symbol)
(or (boundp symbol)
(fboundp symbol)
(facep symbol)
(defvar company-elisp-parse-depth 100)
(defvar company-elisp-var-binding-regexp
- (concat "\\_<" (regexp-opt '("let" "defun" "defmacro" "defsubst"
- "lambda" "lexical-let"))
+ (concat "\\_<\\(?:cl-\\)?" (regexp-opt '("let" "defun" "defmacro" "defsubst"
+ "lambda" "lexical-let"))
"\\*?\\_>")
"Regular expression matching head of a multiple variable bindings form.")
"Regular expression matching head of a form with one variable binding.")
(defvar company-elisp-fun-binding-regexp
- (concat "\\_<\\(?:cl-\\)?" (regexp-opt '("flet" "labels")) "\\_>")
+ (concat "\\_<\\(?:cl-\\)?" (regexp-opt '("flet" "labels")) "\\*?\\_>")
"Regular expression matching head of a function bindings form.")
-(defun company-elisp-locals (prefix functions-p)
+(defun company-elisp--locals (prefix functions-p)
(let ((regexp (concat "[ \t\n]*\\(\\_<" (regexp-quote prefix)
"\\(?:\\sw\\|\\s_\\)*\\_>\\)"))
(pos (point))
res))
(defun company-elisp-candidates (prefix)
- (let* ((predicate (company-elisp-candidates-predicate prefix))
- (locals (company-elisp-locals prefix (eq predicate 'fboundp)))
- (globals (company-elisp-globals prefix predicate))
+ (let* ((predicate (company-elisp--candidates-predicate prefix))
+ (locals (company-elisp--locals prefix (eq predicate 'fboundp)))
+ (globals (company-elisp--globals prefix predicate))
(locals (loop for local in locals
when (not (member local globals))
collect local)))
(sort globals 'string<))
(append locals globals))))
-(defun company-elisp-globals (prefix predicate)
+(defun company-elisp--globals (prefix predicate)
(all-completions prefix obarray predicate))
-(defun company-elisp-candidates-predicate (prefix)
+(defun company-elisp--candidates-predicate (prefix)
(let* ((completion-ignore-case nil)
(before (char-before (- (point) (length prefix)))))
(if (and company-elisp-detect-function-context
(save-excursion
(ignore-errors
(up-list -2)
- (forward-char 1)
- (looking-at " *(")))))
+ (and (save-excursion
+ (forward-char 1)
+ (looking-at "[ \t\n]*("))
+ (prog1 (search-backward "(")
+ (forward-char 1))
+ (looking-at company-elisp-var-binding-regexp))))))
'fboundp
'boundp)
- 'company-elisp-predicate)))
+ 'company-elisp--predicate)))
-(defun company-elisp-doc (symbol)
+(defun company-elisp--doc (symbol)
(let* ((symbol (intern symbol))
(doc (if (fboundp symbol)
(documentation symbol t)
(case command
(interactive (company-begin-backend 'company-elisp))
(prefix (and (eq (derived-mode-p 'emacs-lisp-mode) 'emacs-lisp-mode)
- (company-grab-lisp-symbol)))
+ (company-elisp--prefix)))
(candidates (company-elisp-candidates arg))
(sorted company-elisp-show-locals-first)
- (meta (company-elisp-doc arg))
+ (meta (company-elisp--doc arg))
(doc-buffer (let ((symbol (intern arg)))
(save-window-excursion
(ignore-errors