]> code.delx.au - gnu-emacs-elpa/commitdiff
Added location referencing.
authorNikolaj Schumacher <git@nschum.de>
Sun, 22 Mar 2009 15:58:22 +0000 (16:58 +0100)
committerNikolaj Schumacher <git@nschum.de>
Sun, 22 Mar 2009 19:08:10 +0000 (20:08 +0100)
company-elisp.el
company-etags.el
company-files.el
company-gtags.el
company-semantic.el
company.el

index c40b6f6b0e36ff0e35f1481fedda8e74108026d6..bc22c771bb6a1a70ec85ead511bda0c7d9fc8006 100644 (file)
                    (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
index 59aee1101c6171a601dc4525cfa53c8395ae8a25..84e8e6599397069132df6533e68c3e85bfe82247 100644 (file)
@@ -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)
index adbdf904c9bccd596fe32755f6b40d4a7ea59834..f08479c9c610645d79162b6facffe81ddaaf576c 100644 (file)
@@ -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)))
 
index a7667677a5c717f105cddd9e193974295898ad53..f5605970bc1c917d7c319d81d1f1239e90178ec6 100644 (file)
           (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
index c2f6185b86fd4a0568524e6f71414280ae275e77..a30d97ea3b8f2718cd374ec3d7ffa2bbe941c41b 100644 (file)
                     (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
index 033a880182a60c7c464f9943bac20434d951c922..9964010185957d9a9b6e18708da762da503b42e9 100644 (file)
@@ -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 "<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)
@@ -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)