]> code.delx.au - gnu-emacs-elpa/commitdiff
Extracted company-show-electric-buffer.
authorNikolaj Schumacher <git@nschum.de>
Sun, 22 Mar 2009 13:51:44 +0000 (14:51 +0100)
committerNikolaj Schumacher <git@nschum.de>
Sun, 22 Mar 2009 15:59:04 +0000 (16:59 +0100)
company-elisp.el
company.el

index b3536eb8ab7267cb5a64d4d9309d4250e0f85f39..c40b6f6b0e36ff0e35f1481fedda8e74108026d6 100644 (file)
     ('candidates (company-elisp-candidates arg))
     ('meta (company-elisp-doc arg))
     ('doc-buffer (let ((symbol (intern arg)))
-                   (when (or (ignore-errors (describe-function symbol))
-                             (ignore-errors (describe-variable symbol)))
-                     (help-buffer))))))
+                   (save-window-excursion
+                     (when (or (ignore-errors (describe-function symbol))
+                               (ignore-errors (describe-variable symbol)))
+                       (help-buffer)))))))
 
 (provide 'company-elisp)
 ;;; company-elisp.el ends here
index 7d482ce30dee1703fd2c5090d26a22a7c23f0473..f12b38ba2a2d4a0b5b5dfa73b397ef254df802dd 100644 (file)
@@ -896,28 +896,32 @@ when the selection has been changed, the selected candidate is completed."
     (erase-buffer)
     (current-buffer)))
 
+(defmacro company-electric (&rest body)
+  (declare (indent 0) (debug t))
+  `(if company-mode
+       (when (company-manual-begin)
+         (save-window-excursion
+           (let ((height (window-height))
+                 (row (cdr (posn-col-row (posn-at-point)))))
+             ,@body
+             (and (< (window-height) height)
+                  (< (- (window-height) row 2) company-tooltip-limit)
+                  (recenter (- (window-height) row 2)))
+             (while (eq 'scroll-other-window
+                        (key-binding (vector (list (read-event)))))
+               (call-interactively 'scroll-other-window))
+             (when last-input-event
+               (clear-this-command-keys t)
+               (setq unread-command-events (list last-input-event))))))
+     (error "Company not enabled")))
+
 (defun company-show-doc-buffer ()
   "Temporarily show a buffer with the complete documentation for the selection."
   (interactive)
-  (unless company-mode (error "Company not enabled"))
-  (when (company-manual-begin)
-    (save-window-excursion
-      (let* ((height (window-height))
-             (row (cdr (posn-col-row (posn-at-point))))
-             (selected (nth company-selection company-candidates))
-             (buffer (funcall company-backend 'doc-buffer selected)))
-        (if (not buffer)
-            (error "No documentation available.")
-          (display-buffer buffer)
-          (and (< (window-height) height)
-               (< (- (window-height) row 2) company-tooltip-limit)
-               (recenter (- (window-height) row 2)))
-          (while (eq 'scroll-other-window
-                     (key-binding (vector (list (read-event)))))
-            (scroll-other-window))
-          (when last-input-event
-            (clear-this-command-keys t)
-            (setq unread-command-events (list last-input-event))))))))
+  (company-electric
+    (let ((selected (nth company-selection company-candidates)))
+      (display-buffer (or (funcall company-backend 'doc-buffer selected)
+                          (error "No documentation available")) t))))
 (put 'company-show-doc-buffer 'company-keep t)
 
 ;;; pseudo-tooltip ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;