Wilfred / suggest.el

discover elisp functions that do what you want
367 stars 14 forks source link

Add support for seq.el #44

Closed piyo closed 6 years ago

piyo commented 6 years ago

Hello, what an intriguing package.

Personally I want to see recommendations from the seq.el library as well.

To start this off I am looking over each function and comparing the results to the default suggest.el configuration. The following is an in-progress skeleton.

(use-package suggest
  :config
  (setq suggest-functions-addl
        (list
         #'seq-doseq
         ;; #'seq
         ;; #'seq-let
         #'seq-elt
         #'seq-length
         ;; #'seq-do 
         #'seqp
         ;; #'seq-copy
         #'seq-subseq
         ;;;below #'seq-map
         ;;;below #'seq-mapn
         #'seq-drop
         #'seq-take
         #'seq-drop-while
         #'seq-take-while
         #'seq-empty-p
         #'seq-sort
         #'seq-reverse
         #'seq-concatenate
         #'seq-into-sequence
         #'seq-into
         #'seq-filter
         #'seq-remove
         #'seq-reduce
         #'seq-every-p
         #'seq-some
         #'seq-find
         #'seq-count
         #'seq-contains
         #'seq-set-equal-p
         #'seq-position
         #'seq-uniq
         #'seq-mapcat
         #'seq-partition
         #'seq-intersection
         #'seq-difference
         #'seq-group-by
         #'seq-min
         #'seq-max
         ;; seq-random-elt
         #'seq-min
         #'seq-max
         #'seq-position
         ))
  (setq suggest-functions-orig
        (or (bound-and-true-p suggest-functions-orig)
            (copy-list suggest-functions)))
  (setq suggest-functions (copy-list suggest-functions-orig))
  ;;
  (setq suggest-funcall-functions-addl
        (list
         #'seq-map
         #'seq-mapn
         ))
  (setq suggest-funcall-functions-orig
        (or (bound-and-true-p suggest-funcall-functions-orig)
            (copy-list suggest-funcall-functions)))
  (setq suggest-funcall-functions (copy-list suggest-funcall-functions-orig))
  ;;
  (suggest-activate-func-adds)
  )

(defun suggest-reset-func-adds ()
  ""
  (interactive)
  (setq
   suggest-functions suggest-functions-orig
   suggest-funcall-functions suggest-funcall-functions-orig))

(defun suggest-activate-func-adds ()
  ""
  (interactive)
  (setq suggest-functions (append suggest-functions-orig
                                  suggest-functions-addl)
        suggest-funcall-functions (append suggest-funcall-functions-orig
                                          suggest-funcall-functions-addl)))

Before (without seq.el):

;; Inputs (one per line):
(vector 1 2 3 6 5)
2
4

;; Desired output:
(vector 3 6)

;; Suggestions:

(substring (vector 1 2 3 6 5) 2 4) ;=> [3 6]
(apply #'substring (list (vector 1 2 3 6 5) 2 4)) ;=> [3 6]
(apply #'substring (-cons* (vector 1 2 3 6 5) 2 4 nil)) ;=> [3 6]
(apply #'substring (cl-list* (vector 1 2 3 6 5) 2 4 nil)) ;=> [3 6] 3 6 5) 2 4 nil)) ;=> [3 6]

After (with seq.el):

;; Inputs (one per line):
(vector 1 2 3 6 5)
2
4

;; Desired output:
(vector 3 6)

;; Suggestions:

(seq-subseq (vector 1 2 3 6 5) 2 4) ;=> [3 6]
(apply #'substring (list (vector 1 2 3 6 5) 2 4)) ;=> [3 6]
(apply #'seq-subseq (list (vector 1 2 3 6 5) 2 4)) ;=> [3 6]
(apply #'substring (-cons* (vector 1 2 3 6 5) 2 4 nil)) ;=> [3 6]
Wilfred commented 6 years ago

Thanks for your feedback :)

I've gone through and added the seq.el functions that I think make sense. Note that some of your additions are dangerous -- you should not be adding higher-order functions like seq-mapcat into suggest-functions. Suggest.el can find arbitrary functions with read, so if I have an input of "delete-file" then you really don't want it to try things like (seq-mapcat (read "delete-file") (list 1 2 3)).

You can use suggest-funcall-functions for these and it should be safe.

Suggest.el doesn't really work with macros, so I've not added seq-doseq. I've also skipped functions that take predicates, as users tend not to supply predicates as inputs and suggest.el usually refuses to try predicates to avoid executing something with side-effects. I also skipped a couple of trivial functions like seq-length that don't seem like useful additions when we already have length. suggest.el is pretty much O(N) in the size of suggest-functions.

Other than that, there are some great functions that suggest.el definitely benefits from. As you showed, suggest.el hasn't been very good at vectors and this really helps improve in that area. :) I've also added a few entries in suggest-extra-args to make the most of these new functions.

I hope that make sense! I'm happy to discuss any further additions you think I've missed.

piyo commented 6 years ago

Thank you very much for your consideration and also for the extra comments. (^_^)/