]> code.delx.au - gnu-emacs-elpa/blob - company-elisp.el
Added documentation buffer.
[gnu-emacs-elpa] / company-elisp.el
1 (require 'company)
2 (eval-when-compile (require 'cl))
3
4 (defvar company-lisp-symbol-regexp
5 "\\_<\\(\\sw\\|\\s_\\)+\\_>\\=")
6
7 (defun company-grab-lisp-symbol ()
8 (let ((prefix (or (company-grab company-lisp-symbol-regexp) "")))
9 (unless (and (company-in-string-or-comment (- (point) (length prefix)))
10 (/= (char-before (- (point) (length prefix))) ?`))
11 prefix)))
12
13 (defun company-elisp-predicate (symbol)
14 (or (boundp symbol)
15 (fboundp symbol)))
16
17 (defvar company-elisp-parse-limit 30)
18 (defvar company-elisp-parse-depth 100)
19
20 (defun company-elisp-parse-let ()
21 (let (vars)
22 (ignore-errors
23 (save-excursion
24 (dotimes (i company-elisp-parse-depth)
25 (up-list -1)
26 (save-excursion
27 (when (looking-at "([ \t\n]*let")
28 (down-list 2)
29 (ignore-errors
30 (dotimes (i company-elisp-parse-limit)
31 (save-excursion
32 (down-list 1)
33 (if (looking-at "[ \t\n]*\\(\\(?:\\sw\\|\\s_\\)+\\)")
34 (add-to-list 'vars (match-string-no-properties 1))
35 (error)))
36 (forward-sexp))))))))
37 vars))
38
39 (defun company-elisp-doc (symbol)
40 (let* ((symbol (intern symbol))
41 (doc (if (fboundp symbol)
42 (documentation symbol t)
43 (documentation-property symbol 'variable-documentation t))))
44 (when (string-match ".*$" doc)
45 (match-string 0 doc))))
46
47 (defun company-elisp (command &optional arg &rest ignored)
48 (case command
49 ('prefix (and (eq major-mode 'emacs-lisp-mode)
50 (company-grab-lisp-symbol)))
51 ('candidates (let ((completion-ignore-case nil))
52 (append (all-completions arg (company-elisp-parse-let))
53 (all-completions arg obarray
54 'company-elisp-predicate))))
55 ('meta (company-elisp-doc arg))
56 ('doc-buffer (describe-function 'describe-function)
57 (help-buffer))))
58
59 (provide 'company-elisp)
60 ;;; company-elisp.el ends here