0

I want to write backend for company-mode. I have this example:

(require 'company)
(require 'cl-lib)

(defun backend-name (command &optional arg &rest ignored)
  (interactive (list 'interactive))
  (cl-case command
    (interactive (company-begin-backend 'backend-name))
    (prefix (when (looking-back "git .*?\\([a-zA-Z-~]+ \\)$") (match-string 1)))
    (candidates (cond
      ((string= arg "reset ) '("--hard" "--soft"))
      (t nil)))))

This does not do what I want. Choosing "--hard" from list replaces word "reset ". It should append "--hard" to the end of word "reset ".

1 Answer 1

1

The literal answer would be "you can't" because the prefix is the thing that's supposed to be replaced.

What you can (should) do instead, is return a smaller string as prefix (e.g. ""), but then inside the candidates handler search back e.g. using the same regexp, see whether the previous word is "reset", and act accordingly.

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.