From: Nikolaj Schumacher Date: Sun, 22 Mar 2009 15:58:22 +0000 (+0100) Subject: Added location referencing. X-Git-Url: https://code.delx.au/gnu-emacs-elpa/commitdiff_plain/9db8d0904c1673f8ae321a30221b06442b3ab159 Added location referencing. --- diff --git a/company-elisp.el b/company-elisp.el index c40b6f6b0..bc22c771b 100644 --- a/company-elisp.el +++ b/company-elisp.el @@ -87,7 +87,11 @@ (save-window-excursion (when (or (ignore-errors (describe-function symbol)) (ignore-errors (describe-variable symbol))) - (help-buffer))))))) + (help-buffer))))) + ('location (let ((sym (intern arg))) + (or (ignore-errors (find-definition-noselect sym nil)) + (ignore-errors (find-definition-noselect sym 'defvar)) + (ignore-errors (find-definition-noselect sym t))))))) (provide 'company-elisp) ;;; company-elisp.el ends here diff --git a/company-etags.el b/company-etags.el index 59aee1101..84e8e6599 100644 --- a/company-etags.el +++ b/company-etags.el @@ -65,6 +65,10 @@ buffer automatically." (completion-ignore-case nil)) (and (fboundp 'tags-completion-table) (all-completions arg (tags-completion-table))))) + ('location (let ((tags-table-list (company-etags-buffer-table))) + (when (fboundp 'find-tag-noselect) + (let ((buffer (find-tag-noselect arg))) + (cons buffer (with-current-buffer buffer (point))))))) ('sorted t))) (add-to-list 'company-backends 'company-etags) diff --git a/company-files.el b/company-files.el index adbdf904c..f08479c9c 100644 --- a/company-files.el +++ b/company-files.el @@ -61,6 +61,8 @@ (case command ('prefix (company-files-grab-existing-name)) ('candidates (company-files-complete arg)) + ('location (cons (dired-noselect + (file-name-directory (directory-file-name arg))) 1)) ('sorted t) ('no-cache t))) diff --git a/company-gtags.el b/company-gtags.el index a7667677a..f5605970b 100644 --- a/company-gtags.el +++ b/company-gtags.el @@ -57,6 +57,17 @@ (forward-line))) (nreverse tags)))) +(defun company-gtags-location (tag) + (with-temp-buffer + (when (= 0 (call-process "global" nil (list (current-buffer) nil) + nil "-x" tag)) + (goto-char (point-min)) + (when (looking-at (concat (regexp-quote tag) + "[ \t]+\\([[:digit:]]+\\)" + "[ \t]+\\([^ \t]+\\)")) + (cons (expand-file-name (match-string 2)) + (string-to-number (match-string 1))))))) + (defun company-gtags (command &optional arg &rest ignored) "A `company-mode' completion back-end for GNU Global." (case command @@ -65,7 +76,8 @@ (company-gtags-available) (or (company-grab company-gtags-symbol-regexp) ""))) ('candidates (company-gtags-fetch-tags arg)) - ('sorted t))) + ('sorted t) + ('location (company-gtags-location arg)))) (provide 'company-gtags) ;;; company-gtags.el ends here diff --git a/company-semantic.el b/company-semantic.el index c2f6185b8..a30d97ea3 100644 --- a/company-semantic.el +++ b/company-semantic.el @@ -74,7 +74,11 @@ (semantic-analyze-find-tag arg))) ('doc-buffer (company-semantic-doc-buffer (semantic-analyze-find-tag arg))) ;; because "" is an empty context and doesn't return local variables - ('no-cache (equal arg "")))) + ('no-cache (equal arg "")) + ('location (let ((tag (semantic-analyze-find-tag arg))) + (when (buffer-live-p (semantic-tag-buffer tag)) + (cons (semantic-tag-buffer tag) + (semantic-tag-start tag))))))) (provide 'company-semantic) ;;; company-semantic.el ends here diff --git a/company.el b/company.el index 033a88018..996401018 100644 --- a/company.el +++ b/company.el @@ -56,6 +56,7 @@ ;; ;;; Change Log: ;; +;; Added `company-show-location'. ;; Added etags back-end. ;; Added work-around for end-of-buffer bug. ;; Added `company-filter-candidates'. @@ -79,6 +80,7 @@ (add-to-list 'debug-ignored-errors "^Preview frontend cannot be used twice$") (add-to-list 'debug-ignored-errors "^Echo area cannot be used twice$") (add-to-list 'debug-ignored-errors "^No documentation available$") +(add-to-list 'debug-ignored-errors "^No location available$") (add-to-list 'debug-ignored-errors "^Company not enabled$") (add-to-list 'debug-ignored-errors "^Company not in search mode$") (add-to-list 'debug-ignored-errors "^No candidate number ") @@ -235,6 +237,10 @@ return a (short) documentation string for it. create a buffer (preferably with `company-doc-buffer'), fill it with documentation and return it. +'location: The second argument is a completion candidate. The back-end can +return the cons of buffer and buffer location, or of file and line +number where the completion candidate was defined. + The back-end should return nil for all commands it does not support or does not know about." :group 'company @@ -278,6 +284,7 @@ The work-around consists of adding a newline.") (define-key keymap "\C-m" 'company-complete-selection) (define-key keymap "\t" 'company-complete-common) (define-key keymap (kbd "") 'company-show-doc-buffer) + (define-key keymap "\C-w" 'company-show-location) (define-key keymap "\C-s" 'company-search-candidates) (define-key keymap "\C-\M-s" 'company-filter-candidates) (dotimes (i 10) @@ -924,6 +931,22 @@ when the selection has been changed, the selected candidate is completed." (error "No documentation available")) t)))) (put 'company-show-doc-buffer 'company-keep t) +(defun company-show-location () + "Temporarily display a buffer showing the selected candidate in context." + (interactive) + (company-electric + (let* ((selected (nth company-selection company-candidates)) + (location (funcall company-backend 'location selected)) + (pos (or (cdr location) (error "No location available"))) + (buffer (or (and (bufferp (car location)) (car location)) + (find-file-noselect (car location) t)))) + (with-selected-window (display-buffer buffer t) + (if (bufferp (car location)) + (goto-char pos) + (goto-line pos)) + (set-window-start nil (point)))))) +(put 'company-show-location 'company-keep t) + ;;; pseudo-tooltip ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defvar company-pseudo-tooltip-overlay nil)