11

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?

2 Answers 2

10

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)
2
  • Just for the sake of completeness: here is the issue I opened on the GitHub project's repository, and they suggested to go down this path.
    – petrux
    Commented Nov 21, 2014 at 8: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
    Commented Jun 16, 2016 at 13:52
4

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.

2
  • 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
    Commented Nov 20, 2014 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
    Commented Nov 20, 2014 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.