I have recently switched from auto-complete-mode
to company-mode
and I having fun. Recently I had to write some Emacs Lisp code. I start typing my function, completion candidates are shown, I press F1
and the documentation opens up in another buffer. I would like to jump to the documentation buffer, but, as I type C-x o
it gets closed. Any hint?

- 665
- 1
- 5
- 18
2 Answers
I don't see a way built in to company-mode to do this, but you can add your own key binding to company-active-map
.
As a quick experiment I took the company-show-doc-buffer
implementation and simply removed the company--electric-do
wrapper:
(defun my/company-show-doc-buffer ()
"Temporarily show the documentation buffer for the selection."
(interactive)
(let* ((selected (nth company-selection company-candidates))
(doc-buffer (or (company-call-backend 'doc-buffer selected)
(error "No documentation available"))))
(with-current-buffer doc-buffer
(goto-char (point-min)))
(display-buffer doc-buffer t)))
You could bind this to another key, for example C-F1, to "permanently" open the doc buffer:
(define-key company-active-map (kbd "C-<f1>") #'my/company-show-doc-buffer)

- 20,175
- 1
- 51
- 83
-
Just for the sake of completeness: [here](https://github.com/company-mode/company-mode/issues/238#issuecomment-63917865) is the issue I opened on the GitHub project's repository, and they suggested to go down this path. – petrux Nov 21 '14 at 08:07
-
I just wanted to post my little tweak in case you want this window also get selected (defun my-company-show-doc-buffer () "Temporarily show the documentation buffer for the selection." (interactive) (let* ((selected (nth company-selection company-candidates)) (doc-buffer (or (company-call-backend 'doc-buffer selected) (error "No documentation available")))) (with-current-buffer doc-buffer (goto-char (point-min))) (select-window (display-buffer doc-buffer t)))) – sandric Jun 16 '16 at 13:52
Author's comment on a page comparing company-mode to auto-complete:
What happens when you press F1 in company mode
It uses pop-to-window to display the help buffer, but hides it before the next command (unless that command is scroll-other-window or scroll-other-window-down).
Based on that, you can only scroll the documentation buffer, not jump to it.
But, looking at the code for company-show-doc-buffer
, I noticed that it uses company--electric-do
, which will call interactively any commands in company--electric-commands
. Normally, it contains only scroll-other-window
and scroll-other-window-down
, but maybe you can add other-window
to that list.

- 700
- 4
- 9
-
I just tested like this: `(defvar company--electric-commands '(scroll-other-window scroll-other-window-down other-window) "List of Commands that won't break out of electric commands.")` but it doesn't work. As I type `C-...` the help buffer closes. The same putting `(add-to-list 'company--electric-commands 'other-window)` in my init file. – petrux Nov 20 '14 at 14:51
-
Yeah, looks like company--electric-do uses `save-window-excursion` to save/restore the the window configuration, so it won't work. You might be better off binding your own 'show doc' command to a key in the `company-active-map`. – glucas Nov 20 '14 at 15:44