X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/6422b3e7efb554bbfc8b9d9f051402d9097573b1..779de03e226b161a00c3428ffdadd89ecbc422d0:/company-elisp.el diff --git a/company-elisp.el b/company-elisp.el index 000f30c7f..3db0d8b83 100644 --- a/company-elisp.el +++ b/company-elisp.el @@ -1,4 +1,4 @@ -;;; company-elisp.el --- A company-mode completion back-end for emacs-lisp-mode -*- lexical-binding: t -*- +;;; company-elisp.el --- company-mode completion backend for Emacs Lisp -*- lexical-binding: t -*- ;; Copyright (C) 2009, 2011-2013 Free Software Foundation, Inc. @@ -26,21 +26,23 @@ ;;; Code: (require 'company) -(eval-when-compile (require 'cl)) +(require 'cl-lib) (require 'help-mode) (require 'find-func) +(defgroup company-elisp nil + "Completion backend 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))) @@ -109,7 +111,7 @@ first in the candidates list." 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) ?\() @@ -124,19 +126,19 @@ first in the candidates list." 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)) (when (looking-at regexp) - (pushnew (match-string-no-properties 1) res))) + (cl-pushnew (match-string-no-properties 1) res))) (forward-sexp)) (scan-error nil))) ((unless functions-p (looking-at company-elisp-var-binding-regexp-1)) (down-list 1) (when (looking-at regexp) - (pushnew (match-string-no-properties 1) res))))))))) + (cl-pushnew (match-string-no-properties 1) res))))))))) (scan-error nil)) res)) @@ -144,9 +146,9 @@ first in the candidates list." (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))) + (locals (cl-loop for local in locals + when (not (member local globals)) + collect local))) (if company-elisp-show-locals-first (append (sort locals 'string<) (sort globals 'string<)) @@ -157,24 +159,29 @@ first in the candidates list." (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 (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) @@ -186,11 +193,11 @@ first in the candidates list." ;;;###autoload (defun company-elisp (command &optional arg &rest ignored) - "A `company-mode' completion back-end for `emacs-lisp-mode'." + "`company-mode' completion backend for Emacs Lisp." (interactive (list 'interactive)) - (case command + (cl-case command (interactive (company-begin-backend 'company-elisp)) - (prefix (and (eq (derived-mode-p 'emacs-lisp-mode) 'emacs-lisp-mode) + (prefix (and (derived-mode-p 'emacs-lisp-mode 'inferior-emacs-lisp-mode) (company-elisp--prefix))) (candidates (company-elisp-candidates arg)) (sorted company-elisp-show-locals-first)