8

When typing a number in spacemacs all kind of numbers are being suggested. I can autocomplete them with enter. I like this behaviour in the case I'm typing words (made up of letters). But I don't want this behaviour when I'm typing numbers.

Often I have to type a number at the end of a line. So for instance, when I want the number 10 but type enter in order to go to the next line, the 10 I type expands to 1001004005438142.

example of a number being suggested when typing 10

To avoid the 10 being expanded, I can type a space and after that an enter. That's the way I handle this at this moment.

However I just don't want numbers to automatically expand.

What functions or strings can I put into my .spacemacs (or init.el) to prevent numbers, and only numbers, from being suggested (and consequently being expanding when I type enter)?

Drew
  • 75,699
  • 9
  • 109
  • 225
jajpater
  • 323
  • 1
  • 9

4 Answers4

3

It seems to be as simple as:

(setq company-dabbrev-char-regexp "[A-z:-]")

I got this far by studying this q&a: How can I prevent company-mode completing non-English chars?

jajpater
  • 323
  • 1
  • 9
  • I still worry a bit about the regex I used here, since I don't know if it matches every word/expression that I want to be suggested... – jajpater Sep 05 '18 at 07:57
2
(push (apply-partially #'cl-remove-if
                       (lambda (c) (string-match-p "\\`[0-9]+\\'" c)))
      company-transformers)

The above code snippet is copied from the discussion at How to let company-dabbrev ignore numbers analysis

Swarnendu Biswas
  • 1,378
  • 1
  • 11
  • 24
  • Yes, this is the best answer, though I would delete the ending `\\;` anchor so that anything that starts with a number is exempt from completion. – Daniel Doherty Apr 12 '22 at 11:48
1

When this drop-down menu for numbers completion appears, typically the mode-line would show the company backend which is causing this completion. You can remove this backend from the list 'company-backends.

E.g. if company-dabbrev is doing it,

(delete 'company-dabbrev company-backends)

Alternatively, you could prevent company from completing without your consent by setting company-idle-delay to a large number. Mine is

(setq company-idle-delay 999999)
Jeeves
  • 611
  • 4
  • 5
  • Thanks for your answer but I don't want to lose company-dabbrev in its entirety, since (as far as I understand) it is responsible for autocompletion of the words previously used in the buffer. – jajpater Sep 05 '18 at 07:33
  • OK, are you sure that dabbrev backend is causing the numbers drop down appearance ? – Jeeves Sep 06 '18 at 09:54
  • Yes, it is, since, changing the company-dabbrev-char-regexp changes the drop down behaviour. – jajpater Sep 06 '18 at 14:40
0

I suffered the same irritation. The best answer is to stop it at the dabbrev level, not company-mode. This works with cofu and other completion libraries as well:

(setq dabbrev-abbrev-skip-leading-regexp "[0-9]\\|\\$\\|\\*\\|/\\|=")

The only relevant bit is the first alternative with [0-9], causing dabbrev to forego completion when there is a digit at the beginning of the word to be completed.

Daniel Doherty
  • 418
  • 4
  • 12