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

Add builtins-only flag #46

Open
nickdrozd opened this issue Jul 3, 2018 · 3 comments
Open

Add builtins-only flag #46

nickdrozd opened this issue Jul 3, 2018 · 3 comments

Comments

@nickdrozd
Copy link
Contributor

Sometimes you can't or don't want to use functions from f, s, etc. In those cases it would be nice to be able to restrict suggest output to just builtin Emacs functions.

@Wilfred
Copy link
Owner

Wilfred commented Jul 17, 2018

Interesting idea, I'm not opposed to this.

Since suggest always returns 5 results anyway, I generally find that it returns both builtin functions and f/s functions. Do you have any examples where you don't get a mix of results but would like to?

@nickdrozd
Copy link
Contributor Author

I feel like I had an example like that, but I can't remember what it
was.

Still, it would be nice to filter out suggestions that I know won't be
useful to me (if I'm sticking to builtins). For example, in

;; Inputs (one per line):
"file.c"

;; Desired output:
"file"

;; Suggestions:

(f-base "file.c") ;=> "file"
(f-no-ext "file.c") ;=> "file"
(file-name-base "file.c") ;=> "file"
(car (s-split-words "file.c")) ;=> "file"
(cl-first (s-split-words "file.c")) ;=> "file"

four of those five suggestions are no good.

(Of course, it's good to know that those functions are out there in
the world of Elisp, so suggest-builtins-only or whatever the flag
would be called should default to nil.)

Besides improving the quality of the results (in this specific case),
pulling f-*, s-*, etc out of the list of functions to check would
also speed things up.

@Wilfred
Copy link
Owner

Wilfred commented Sep 16, 2018

I was reminded of this issue today, when I got the following results:

;; Inputs (one per line):
"x"
3

;; Desired output:
"xxx"

;; Suggestions:
(s-repeat 3 "x") ;=> "xxx"
(s-pad-left 3 "x" nil) ;=> "xxx"
(s-pad-right 3 "x" nil) ;=> "xxx"
(string-join (-repeat 3 "x")) ;=> "xxx"
(string-join (make-list 3 "x")) ;=> "xxx"

If you're willing to use s.el, s-repeat is what you want. If you're only using core Emacs, then the last result is what you wanted. I think (string-join (-repeat 3 "x")) is interesting too.

An ideal ordering is probably this:

(s-repeat 3 "x") ;=> "xxx"
(string-join (make-list 3 "x")) ;=> "xxx"
(string-join (-repeat 3 "x")) ;=> "xxx"
(s-pad-left 3 "x" nil) ;=> "xxx"
(s-pad-right 3 "x" nil) ;=> "xxx"

I'm not sure exactly what heuristics to use here. We probably want to upweight smaller numbers of function calls and upweight calls that only use built-in functions. In this case, downweighting calls that have extra args (nil here) would help, but I'm not sure if that's true in general.

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