Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Space appended to completion when :annotation-function returns string #2360

Closed
non-Jedi opened this issue Aug 12, 2020 · 2 comments
Closed

Comments

@non-Jedi
Copy link

non-Jedi commented Aug 12, 2020

Expected behavior

The first argument that :exit-function receives should be the un-annotated string that is being completed-to.

Actual behavior (from emacs-helm.sh if possible, see note at the bottom)

At least part of the the value returned from :annotation-function is appended to the completion name when its passed to :exit-function. The annotation also appears to be included in the final in-buffer completion.

The docstring for completion-extra-properties says:

The function must accept one argument, a completion string,
and return either nil or a string which is to be displayed
next to the completion (but which is not part of the
completion).

Steps to reproduce (recipe)

(defun my-capf ()
  (list (line-beginning-position) (point) '("foo" "foobar")
        :annotation-function (lambda (_) " ")
        :exit-function (lambda (string _status)
                         (message ":exit-function string: %s, length: %d"
                                  string (length string)))))

(setq completion-at-point-functions (list 'my-capf))

The message when completing "foo" should be :exit-function string: foo, length: 3; instead it is :exit-function string: foo , length: 4. "foo" should be inserted into the buffer by itself; instead a space is inserted after "foo".

Backtraces if any (M-x toggle-debug-on-error)

Describe versions of Helm, Emacs, operating system, etc.

Helm master, Emacs 26.3, Linux

Are you using emacs-helm.sh to reproduce this bug? (yes/no):

Yes

Are you using Spacemacs? (yes/no):

No

@non-Jedi non-Jedi changed the title Content from :annotation-function passed to :exit-function Space appended to completion when :annotation-function returns string Aug 12, 2020
@non-Jedi
Copy link
Author

non-Jedi commented Aug 12, 2020

Actually the space gets appended to the completion result if :annotation-function returns any string. The value returned by :annotation-function seems to be irrelevant for this bug:

(defun my-capf ()
  (list (line-beginning-position) (point) '("foo" "foobar")
	:annotation-function (lambda (_) "")
        :exit-function (lambda (string _status)
                         (message ":exit-function string: %s, length: %d" string (length string)))))

(setq completion-at-point-functions (list 'my-capf))

The above shows the same output of :exit-function string: foo, length: 4.

@thierryvolpiatto
Copy link
Member

thierryvolpiatto commented Aug 13, 2020 via email

thierryvolpiatto added a commit that referenced this issue Aug 16, 2020
…2360)

This avoid error when result is not a string like in CRM.

Do this in the right cond clause of helm-completion-in-region--insert-result
instead of doing it earlier in helm--completion-in-region.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants