Open nickdrozd opened 6 years ago
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?
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.
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.
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 restrictsuggest
output to just builtin Emacs functions.