0

I am trying to prevent company-mode from autocompleting numbers. I added the following to my init file.

  (push (apply-partially #'cl-remove-if
               (lambda (c) (string-match-p "\\`[0-9]+\\'" c)))
      company-transformers)

I am now getting this message

Symbol's value as variable is void: company-transformers

This is the relevant part of my init file for company-mode

  (use-package company
    :bind (:map company-active-map
    ("C-n" . company-select-next)
    ("C-p" . company-select-previous)
    ("M-h" . company-show-doc-buffer))
    :custom
    (company-idle-delay 0)
    (company-selection-wrap-around t)
    (company-tooltip-limit 10)
    (company-minimum-prefix-length 1)
    :hook
     (after-init . global-company-mode))


  (push (apply-partially #'cl-remove-if
               (lambda (c) (string-match-p "\\`[0-9]+\\'" c)))
      company-transformers)

I found this on StackExchange, Symbol's value as variable is void: company-backends, but I can't figure out how to adapt it.

0

1 Answer 1

1

Add a :config section to the use-package declaration and move the code that modifies company-transformers to that section:

 (use-package company
    :bind (:map company-active-map
    ("C-n" . company-select-next)
    ("C-p" . company-select-previous)
    ("M-h" . company-show-doc-buffer))
    :custom
    (company-idle-delay 0)
    (company-selection-wrap-around t)
    (company-tooltip-limit 10)
    (company-minimum-prefix-length 1)
    :config
    (push (apply-partially #'cl-remove-if
                           (lambda (c) (string-match-p "\\`[0-9]+\\'" c)))
          company-transformers)
    :hook
     (after-init . global-company-mode))

The doc string for use-package says:


For full documentation, please see the README file that came with
this file.  Usage:

  (use-package package-name
     [:keyword [option]]...)

:init            Code to run before PACKAGE-NAME has been loaded.
:config          Code to run after PACKAGE-NAME has been loaded.  Note that
                 if loading is deferred for any reason, this code does not
                 execute until the lazy load has occurred.
...

use-package does not necessarily load the package and so company-transformers is not necessarily defined after the use-package declaration. A similar problem occurs e.g. if in your init file, you try to modify company-transformers before the package is loaded (with require or load-library): the name is not defined and when emacs tries to evaluate it (as it will, when you are trying to push to it: it has to know the old value at that point), it fails with the Symbol's value as variable is void error message. Invariably, this message means that you are trying to evaluate a variable before it is defined.

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.