Emacs company-mode and company-anaconda


When setting up your .emacs to automatically add company-anaconda to your company-backends list, eval-after-load is your friend:

;;; Company, and Company backends.
(add-hook 'after-init-hook 'global-company-mode)
(eval-after-load 'company
(progn
    '(add-to-list 'company-backends 'company-anaconda)
    ))

8 thoughts on “Emacs company-mode and company-anaconda

  1. You don’t need the progn in this simple example. You do need it when you want to evaluate multiple forms after the library is loaded, and, in that case, the progn form has itself to be quoted.

  2. You don’t need the `progn` in this case. You only need it, or something that implicitly has it, when you want to evaluate multiple forms after `company` is loaded. And, in that case, the `progn` form has to be quoted. Also, to make this idiomatic elisp, don’t put newlines between closing parenthesis.s

  3. You don’t need the (misleading) progn wrapper. But if you DID need it (because you wanted to perform multiple actions after loading), you would quote the progn, and not the expression(s) inside it.

  4. @joaotavora and @Phil:

    Thank you for the corrections! You’ve shamed me into deciding to dive into my Emacs Lisp books! 🙂 That’s my goal for today.

    (I used the progn because I anticipate adding more company backends.)

  5. Here’s version 2, using with-eval-after-load, which was added in Emacs Lisp version 24.4:

    ;; Company, and Company backends.
    (add-hook 'after-init-hook 'global-company-mode)
    (with-eval-after-load 'company
      (progn
        (add-to-list 'company-backends 'company-anaconda)))
    
    1. But then you don’t need the progn at all, since `with-eval-after-load` accepts &rest body

      (with-eval-after-load FILE &rest BODY)

      Execute BODY after FILE is loaded.

  6. Arg! I can’t make any more errors in such a short code fragment, can I? 🙂

    (> (/ errors lines_of_code) most-positive-fixnum)
    t
    

    And this tiny code becomes just this:

    ;; Company, and Company backends.
    (add-hook 'after-init-hook 'global-company-mode)
    (with-eval-after-load 'company
      (add-to-list 'company-backends 'company-anaconda))
    

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.