aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2013-08-29 15:18:16 -0400
committerStefan Monnier2013-08-29 15:18:16 -0400
commit2da4c3ab6f9f2caf026e03c42e74ccd1f1c86c25 (patch)
treefef83b6252c0744191dc38ec14422f49bfd6d2e1
parentf069bba87c15091288a3c89d8fbb5035e85e7c7f (diff)
downloademacs-2da4c3ab6f9f2caf026e03c42e74ccd1f1c86c25.tar.gz
emacs-2da4c3ab6f9f2caf026e03c42e74ccd1f1c86c25.zip
* lisp/emacs-lisp/lisp.el (lisp--company-doc-buffer)
(lisp--company-doc-string, lisp--company-location): New functions. (lisp-completion-at-point): Use them to improve Company support.
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/emacs-lisp/lisp.el73
2 files changed, 71 insertions, 6 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 3f957874fc4..4d0859097d2 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,9 @@
12013-08-29 Stefan Monnier <monnier@iro.umontreal.ca> 12013-08-29 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * emacs-lisp/lisp.el (lisp--company-doc-buffer)
4 (lisp--company-doc-string, lisp--company-location): New functions.
5 (lisp-completion-at-point): Use them to improve Company support.
6
3 * progmodes/ruby-mode.el (ruby-smie-grammar): Add rule for formal 7 * progmodes/ruby-mode.el (ruby-smie-grammar): Add rule for formal
4 params of lambda expressions. 8 params of lambda expressions.
5 (ruby-smie--implicit-semi-p): Refine rule (bug#15208). 9 (ruby-smie--implicit-semi-p): Refine rule (bug#15208).
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
index b37a811b8d5..11891679202 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -752,6 +752,57 @@ considered."
752 (mapcar #'symbol-name (lisp--local-variables)))))) 752 (mapcar #'symbol-name (lisp--local-variables))))))
753 lastvars))))) 753 lastvars)))))
754 754
755;; FIXME: Support for Company brings in features which straddle eldoc.
756;; We should consolidate this, so that major modes can provide all that
757;; data all at once:
758;; - a function to extract "the reference at point" (may be more complex
759;; than a mere string, to distinguish various namespaces).
760;; - a function to jump to such a reference.
761;; - a function to show the signature/interface of such a reference.
762;; - a function to build a help-buffer about that reference.
763;; FIXME: Those functions should also be used by the normal completion code in
764;; the *Completions* buffer.
765
766(defun lisp--company-doc-buffer (str)
767 (let ((symbol (intern-soft str)))
768 ;; FIXME: we really don't want to "display-buffer and then undo it".
769 (save-window-excursion
770 ;; Make sure we don't display it in another frame, otherwise
771 ;; save-window-excursion won't be able to undo it.
772 (let ((display-buffer-overriding-action
773 '(nil . ((inhibit-switch-frame . t)))))
774 (ignore-errors
775 (cond
776 ((fboundp symbol) (describe-function symbol))
777 ((boundp symbol) (describe-variable symbol))
778 ((featurep symbol) (describe-package symbol))
779 ((facep symbol) (describe-face symbol))
780 (t (signal 'user-error nil)))
781 (help-buffer))))))
782
783(defun lisp--company-doc-string (str)
784 (let* ((symbol (intern-soft str))
785 (doc (if (fboundp symbol)
786 (documentation symbol t)
787 (documentation-property symbol 'variable-documentation t))))
788 (and (stringp doc)
789 (string-match ".*$" doc)
790 (match-string 0 doc))))
791
792(declare-function find-library-name "find-func" (library))
793
794(defun lisp--company-location (str)
795 (let ((sym (intern-soft str)))
796 (cond
797 ((fboundp sym) (find-definition-noselect sym nil))
798 ((boundp sym) (find-definition-noselect sym 'defvar))
799 ((featurep sym)
800 (require 'find-func)
801 (cons (find-file-noselect (find-library-name
802 (symbol-name sym)))
803 0))
804 ((facep sym) (find-definition-noselect sym 'defface)))))
805
755(defun lisp-completion-at-point (&optional _predicate) 806(defun lisp-completion-at-point (&optional _predicate)
756 "Function used for `completion-at-point-functions' in `emacs-lisp-mode'." 807 "Function used for `completion-at-point-functions' in `emacs-lisp-mode'."
757 (with-syntax-table emacs-lisp-mode-syntax-table 808 (with-syntax-table emacs-lisp-mode-syntax-table
@@ -783,7 +834,10 @@ considered."
783 lisp--local-variables-completion-table 834 lisp--local-variables-completion-table
784 obarray) ;Could be anything. 835 obarray) ;Could be anything.
785 :annotation-function 836 :annotation-function
786 (lambda (str) (if (fboundp (intern-soft str)) " <f>"))) 837 (lambda (str) (if (fboundp (intern-soft str)) " <f>"))
838 :company-doc-buffer #'lisp--company-doc-buffer
839 :company-docsig #'lisp--company-doc-string
840 :company-location #'lisp--company-location)
787 ;; Looks like a funcall position. Let's double check. 841 ;; Looks like a funcall position. Let's double check.
788 (save-excursion 842 (save-excursion
789 (goto-char (1- beg)) 843 (goto-char (1- beg))
@@ -800,10 +854,12 @@ considered."
800 ;; we should use something like a symbol-property. 854 ;; we should use something like a symbol-property.
801 (`declare 855 (`declare
802 (list t (mapcar (lambda (x) (symbol-name (car x))) 856 (list t (mapcar (lambda (x) (symbol-name (car x)))
803 (delete-dups 857 (delete-dups
804 (append 858 ;; FIXME: We should include some
805 macro-declarations-alist 859 ;; docstring with each entry.
806 defun-declarations-alist))))) 860 (append
861 macro-declarations-alist
862 defun-declarations-alist)))))
807 ((and (or `condition-case `condition-case-unless-debug) 863 ((and (or `condition-case `condition-case-unless-debug)
808 (guard (save-excursion 864 (guard (save-excursion
809 (ignore-errors 865 (ignore-errors
@@ -811,7 +867,12 @@ considered."
811 (< (point) beg))))) 867 (< (point) beg)))))
812 (list t obarray 868 (list t obarray
813 :predicate (lambda (sym) (get sym 'error-conditions)))) 869 :predicate (lambda (sym) (get sym 'error-conditions))))
814 (_ (list nil obarray #'fboundp)))))))) 870 (_ (list nil obarray
871 :predicate #'fboundp
872 :company-doc-buffer #'lisp--company-doc-buffer
873 :company-docsig #'lisp--company-doc-string
874 :company-location #'lisp--company-location
875 ))))))))
815 (when end 876 (when end
816 (let ((tail (if (null (car table-etc)) 877 (let ((tail (if (null (car table-etc))
817 (cdr table-etc) 878 (cdr table-etc)