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

company-capf: Allow custom prefix function #450

Merged
merged 1 commit into from Jan 9, 2016

Conversation

@fbergroth
Copy link
Contributor

fbergroth commented Jan 9, 2016

There is currently no way to have custom logic in the prefix command for company-capf, such as when you want to return a cons-cell instead of a string. This let's you specify a prefix function using :company-prefix in the capf-function.

fbergroth referenced this pull request in racer-rust/emacs-racer Jan 9, 2016
The company-capf backend will automatically pickup completions and
requires no additional setup. Adds dependency to s.el.
@dgutov

This comment has been minimized.

Copy link
Member

dgutov commented Jan 9, 2016

In order not to return redundant information (which can conflict and lead to confusion), how about the property function (let's call it :company-prefix-length) will return only the imaginary prefix length (for lack of a better term). And company-capf will construct the cons in its prefix handler.

@dgutov

This comment has been minimized.

Copy link
Member

dgutov commented Jan 9, 2016

Or we can decide that the property function should only return boolean values, and call it appropriately for that.

@fbergroth

This comment has been minimized.

Copy link
Contributor Author

fbergroth commented Jan 9, 2016

Sure, so if the property function exists and returns a non-nil value v, the prefix handler returns ("prefix" . v), otherwise the handler returns the plain string "prefix"?

@dgutov

This comment has been minimized.

Copy link
Member

dgutov commented Jan 9, 2016

Pretty much.

@fbergroth fbergroth force-pushed the fbergroth:capf-prefix-function branch from 2406b5a to 46b8284 Jan 9, 2016
@fbergroth

This comment has been minimized.

Copy link
Contributor Author

fbergroth commented Jan 9, 2016

Updated the commit.

@dgutov

This comment has been minimized.

Copy link
Member

dgutov commented Jan 9, 2016

Looks good. Please add a NEWS entry (at the top) as well.

Note that while we don't allow end to be more than (point) now, that should change in the future. Then we'll have to pass (point) as the second argument to the new function. Should we make this change now, to make sure no implementations get surprised later?

@fbergroth fbergroth force-pushed the fbergroth:capf-prefix-function branch from 46b8284 to 0a6bfa9 Jan 9, 2016
@fbergroth

This comment has been minimized.

Copy link
Contributor Author

fbergroth commented Jan 9, 2016

That's probably a good idea. I updated the call to (funcall f beg (point)), and added a news entry. :-)

dgutov added a commit that referenced this pull request Jan 9, 2016
company-capf: Allow custom prefix function
@dgutov dgutov merged commit 23c6f85 into company-mode:master Jan 9, 2016
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@dgutov

This comment has been minimized.

Copy link
Member

dgutov commented Jan 9, 2016

Thanks!

@dgutov

This comment has been minimized.

Copy link
Member

dgutov commented Jan 20, 2016

@fbergroth What do you think about making :company-prefix-length to be just a value, not a function?

Maybe it's an unnecessary complication.

@fbergroth

This comment has been minimized.

Copy link
Contributor Author

fbergroth commented Jan 20, 2016

Sure, that works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.