-;;; company-elisp.el --- A company-mode completion back-end for emacs-lisp-mode -*- lexical-binding: t -*-
+;;; company-elisp.el --- company-mode completion back-end for Emacs Lisp -*- lexical-binding: t -*-
;; Copyright (C) 2009, 2011-2013 Free Software Foundation, Inc.
(require 'help-mode)
(require 'find-func)
+(defgroup company-elisp nil
+ "Completion back-end for Emacs Lisp."
+ :group 'company)
+
(defcustom company-elisp-detect-function-context t
"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)
(const :tag "On" t)))
(defcustom company-elisp-show-locals-first t
"If enabled, locally bound variables and functions are displayed
first in the candidates list."
- :group 'company
:type '(choice (const :tag "Off" nil)
(const :tag "On" t)))
res)
(condition-case nil
(save-excursion
- (dotimes (i company-elisp-parse-depth)
+ (dotimes (_ company-elisp-parse-depth)
(up-list -1)
(save-excursion
(when (eq (char-after) ?\()
company-elisp-var-binding-regexp))
(down-list 1)
(condition-case nil
- (dotimes (i company-elisp-parse-limit)
+ (dotimes (_ company-elisp-parse-limit)
(save-excursion
(when (looking-at "[ \t\n]*(")
(down-list 1))
(defun company-elisp--candidates-predicate (prefix)
(let* ((completion-ignore-case nil)
- (before (char-before (- (point) (length prefix)))))
+ (beg (- (point) (length prefix)))
+ (before (char-before beg)))
(if (and company-elisp-detect-function-context
- (not (eq before ?')))
+ (not (memq before '(?' ?`))))
(if (and (eq before ?\()
(not
(save-excursion
(ignore-errors
- (up-list -2)
- (and (save-excursion
- (forward-char 1)
- (looking-at "[ \t\n]*("))
- (prog1 (search-backward "(")
- (forward-char 1))
- (looking-at company-elisp-var-binding-regexp))))))
+ (goto-char (1- beg))
+ (or (company-elisp--before-binding-varlist-p)
+ (progn
+ (up-list -1)
+ (company-elisp--before-binding-varlist-p)))))))
'fboundp
'boundp)
'company-elisp--predicate)))
+(defun company-elisp--before-binding-varlist-p ()
+ (save-excursion
+ (and (prog1 (search-backward "(")
+ (forward-char 1))
+ (looking-at company-elisp-var-binding-regexp))))
+
(defun company-elisp--doc (symbol)
(let* ((symbol (intern symbol))
(doc (if (fboundp symbol)
;;;###autoload
(defun company-elisp (command &optional arg &rest ignored)
- "A `company-mode' completion back-end for `emacs-lisp-mode'."
+ "`company-mode' completion back-end for Emacs Lisp."
(interactive (list 'interactive))
(case command
(interactive (company-begin-backend 'company-elisp))