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

Sorting order is confusing sometimes #13

Open
ddovod opened this issue Jul 23, 2016 · 8 comments
Open

Sorting order is confusing sometimes #13

ddovod opened this issue Jul 23, 2016 · 8 comments

Comments

@ddovod
Copy link

ddovod commented Jul 23, 2016

Hello.
Assume we have some files:
SomeClass.h
SomeClass.cpp
main.cpp

I would like to unclude SomeClass.h into main.cpp, so:
main.cpp:

include "Some|

SomeClass.cpp
SomeClass.h

First candidate is .cpp file, but in 99% cases I would like to include .h, .hpp, .inl and other files, but not .cpp.
I think this is due to 'sort' function, and 'c' is smaller than 'h', right?
Is there any way to customize sorting behavior?
Thank you a lot!

@hotpxl
Copy link
Owner

hotpxl commented Jul 23, 2016

Yes currently I use string< to sort. SomeClass.h and SomeClass.cpp usually stick together and a single M-n will get you to the right choice. I don't want to complicate the sorting function for now. It's hard to come up with a general rule for sorting.

@ddovod
Copy link
Author

ddovod commented Jul 23, 2016

Ok, thank you for response! Maybe you can implement the ability to set custom comparator for sorting algo which can be set manually? So anybody would have instrument to tweak behavior a bit without bloody patching of original code?

@ddovod
Copy link
Author

ddovod commented Jul 23, 2016

I have no many experience in elisp, but I can try to implement such thing and create a PR, don't you mind?

@hotpxl
Copy link
Owner

hotpxl commented Jul 23, 2016

I can defvar a some kind of post completion hook and I'll hand you all the candidates. You can do reordering or filtering or whatever you want. Does this look good to you?

@ddovod
Copy link
Author

ddovod commented Jul 23, 2016

Yes, sounds good!

@hotpxl
Copy link
Owner

hotpxl commented Jul 23, 2016

I added a post completion hook and tried to reverse the list myself. It worked on my side. But after I returned those results to company, looks like company has sorted them again. I wonder if there anything on company side that prevents me from specifying a specific order.

@ddovod
Copy link
Author

ddovod commented Jul 23, 2016

company.el:

(defun company--preprocess-candidates (candidates)
  (cl-assert (cl-every #'stringp candidates))
  (unless (company-call-backend 'sorted)
    (setq candidates (sort candidates 'string<)))
  (when (company-call-backend 'duplicates)
    (company--strip-duplicates candidates))
  candidates)

Maybe I should create issue in the company-mode github repo = (
But your addition will be helpful no matter what.
Thank you again!

@hotpxl
Copy link
Owner

hotpxl commented Jul 23, 2016

Strangely I already set 'sorted to t, but it's still doing a sort for me somehow.

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