(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
(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)
(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)))
(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
(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
(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
;;
;;; Change Log:
;;
+;; Added `company-show-location'.
;; Added etags back-end.
;; Added work-around for end-of-buffer bug.
;; Added `company-filter-candidates'.
(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 ")
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
(define-key keymap "\C-m" 'company-complete-selection)
(define-key keymap "\t" 'company-complete-common)
(define-key keymap (kbd "<f1>") '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)
(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)