All Projects → Wilfred → Suggest.el

Wilfred / Suggest.el

discover elisp functions that do what you want

Labels

Projects that are alternatives of or similar to Suggest.el

Emacs Theme Darktooth
Darktooth : From the darkness... it watches.
Stars: ✭ 270 (-10.6%)
Mutual labels:  emacs
Radian
🍉 Dotfiles that marry elegance and practicality.
Stars: ✭ 274 (-9.27%)
Mutual labels:  emacs
Fountain Mode
Emacs major mode for screenwriting in Fountain plain-text markup
Stars: ✭ 288 (-4.64%)
Mutual labels:  emacs
Org Superstar Mode
Make org-mode stars a little more super
Stars: ✭ 271 (-10.26%)
Mutual labels:  emacs
Rg.el
Emacs search tool based on ripgrep
Stars: ✭ 277 (-8.28%)
Mutual labels:  emacs
Zetteldeft
A Zettelkasten system! Or rather, some functions on top of the emacs deft package.
Stars: ✭ 284 (-5.96%)
Mutual labels:  emacs
Org Transclusion
(alpha) Emacs package to enable transclusion with Org Mode
Stars: ✭ 251 (-16.89%)
Mutual labels:  emacs
Emax64
64-bit Emacs for Windows with ImageMagick 7
Stars: ✭ 301 (-0.33%)
Mutual labels:  emacs
Dotfiles
●📄 Ryan McGeary's configuration shiznit that makes him productive
Stars: ✭ 278 (-7.95%)
Mutual labels:  emacs
Helm
Emacs incremental completion and selection narrowing framework
Stars: ✭ 3,109 (+929.47%)
Mutual labels:  emacs
Ivy Rich
More friendly interface for ivy.
Stars: ✭ 274 (-9.27%)
Mutual labels:  emacs
Objed
Navigate and edit text objects with Emacs. Development on pause.
Stars: ✭ 276 (-8.61%)
Mutual labels:  emacs
Helm Projectile
Helm UI for Projectile
Stars: ✭ 285 (-5.63%)
Mutual labels:  emacs
Emacs.d
My emacs configuration documented in literate programming style
Stars: ✭ 271 (-10.26%)
Mutual labels:  emacs
Vue Mode
Emacs major mode for vue.js
Stars: ✭ 290 (-3.97%)
Mutual labels:  emacs
Unpackaged.el
A collection of useful Emacs Lisp code that isn't substantial enough to be packaged
Stars: ✭ 269 (-10.93%)
Mutual labels:  emacs
Spacehammer
Hammerspoon config inspired by Spacemacs
Stars: ✭ 280 (-7.28%)
Mutual labels:  emacs
Cider
The Clojure Interactive Development Environment that Rocks for Emacs
Stars: ✭ 3,229 (+969.21%)
Mutual labels:  emacs
Company Coq
A Coq IDE build on top of Proof General's Coq mode
Stars: ✭ 297 (-1.66%)
Mutual labels:  emacs
Rogue
Personal Emacs config
Stars: ✭ 286 (-5.3%)
Mutual labels:  emacs

suggest.el

Build Status Coverage Status MELPA

suggest.el is an Emacs package for discovering elisp functions based on examples. You supply an example input and output, and it makes suggestions.

Interested readers may enjoy my blog posts:

suggest

Examples

suggest.el knows many string functions:

;; Inputs (one per line):
"foo bar"

;; Desired output:
"Foo Bar"

;; Suggestions:
(capitalize "foo bar") ;=> "Foo Bar"

suggest.el can also help you find tricky dash.el functions:

;; Inputs (one per line):
(list 'a 'b 'c 'd)
'c

;; Desired output:
2

;; Suggestions:
(-elem-index 'c (list 'a 'b 'c 'd)) ;=> 2

suggest.el is particularly handy for path manipulation, using both built-in functions as well as f.el:

;; Inputs (one per line):
"/foo/bar/baz.txt"

;; Desired output:
"baz.txt"

;; Suggestions:
(file-name-nondirectory "/foo/bar/baz.txt") ;=> "baz.txt"
(f-filename "/foo/bar/baz.txt") ;=> "baz.txt"

It can even suggest calling functions with apply:

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

;; Desired output:
15

;; Suggestions:
(-sum '(1 2 3 4 5)) ;=> 15
(apply #'+ '(1 2 3 4 5)) ;=> 15

It can also suggest composing functions:

;; Inputs (one per line):
'(a b c)

;; Desired output:
'c

;; Suggestions:
(cadr (cdr '(a b c))) ;=> 'c
(car (last '(a b c))) ;=> 'c
(cl-third '(a b c)) ;=> 'c

It will also suggest additional arguments of basic values (0 in this example):

;; Inputs (one per line):
'(a b c d)

;; Desired output:
'a

;; Suggestions:
(elt '(a b c d) 0) ;=> 'a
(nth 0 '(a b c d)) ;=> 'a
(car '(a b c d)) ;=> 'a
(cl-first '(a b c d)) ;=> 'a
(-first-item '(a b c d)) ;=> 'a

How it works

suggest.el uses enumerative program synthesis. It tries your inputs (in any order) against every function in suggest-functions.

suggest-functions is a carefully chosen function list: they're all pure functions with a small number of arguments using only simple data types. We only include functions that users could 'stumble upon' with the right set of inputs.

Contributing

To work on the code, clone the repo, then you can eval suggest.el in your current Emacs instance.

To run the tests, you will need Cask. Once you've installed Cask, you can install the suggest.el dependencies and run the tests as follows:

$ cask
$ cask exec ert-runner

License

GPLv3.

Related projects

Program synthesis or inductive programming is a computer science research topic, with a range of tools taking very different approaches to generate code.

Smalltalk: Finder

This project was inspired by the Finder in Smalltalk, which does something similar. There's a great demo video here.

You give a list of values (inputs followed by an output):

3. 4. 7.

The Finder iterates over all possible calls (with arguments in any order) to a list of known safe messages, and returns suggestions:

3 + 4 --> 7
3 bitOr: 4 --> 7
3 bitXor: 4 --> 7
3 | 4 --> 7

This only returns single messages that meet the requirements, no nesting (e.g. it won't find '(data1 reversed asUppercase)' from 'foo'. 'OOF').

You can also supply multiple examples, using expressions as inputs:

MethodFinder methodFor: { {'29 Apr 1999' asDate}. 'Thursday'.
		{'30 Apr 1999' asDate}. 'Friday' }.

This returns '(data1 weekday)'.

Amusingly, it will sometimes find '(data1 shuffled)' from 'fo'. 'of'., which is a random sort.

Python: cant

There are some other niche tools that take other approaches. For example, cant for Python tries every function in scope (without a safety whitelist) to find functionality.

Scheme: barliman

barliman takes this idea of synthesis much, much further for Scheme. There's an incredible demo video here.

C-like: sketch

sketch allows the user to specify value placeholders in code (examples).

harness void doubleSketch(int x){
  int t = x * ??;
  assert t == x + x;
}

Generally you provide the structure of the code.

bit[W] firstLeadingZeroSketch (bit[W] x) implements firstLeadingZero {	
	return !(x + ??) & (x + ??); 
}

Or you can specify a set of operators for sketch to explore. Each line here is an assignment to x or tmp of an expression that may contain ! & + with x, tmp or a constant as arguments.

bit[W] firstLeadingZeroSketch (bit[W] x) implements firstLeadingZero {	
	bit[W] tmp=0;
       {| x | tmp |} = {| (!)?((x | tmp) (& | +) (x | tmp | ??)) |};
       {| x | tmp |} = {| (!)?((x | tmp) (& | +) (x | tmp | ??)) |};
       {| x | tmp |} = {| (!)?((x | tmp) (& | +) (x | tmp | ??)) |};
       return tmp;
}

Constraints are fed to a SAT solver, then sketch finds a solution. The output can be converted to C.

Liquid Haskell: Synquid

Synquid (the first half of this Microsoft Research talk gives a good overview) is a program synthesis tool leveraging refinement types.

The user provides the type of the function they want to generate, and a collection of 'components', the building blocks that Synquid tries to combine.

Synquid then lazily generates ASTs and type checks them. This allows it to prune the search tree by ignoring program structures that are never valid types.

(This is the extent of my understanding: I have probably oversimplified.)

Impressively, Synquid can generate recursive functions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].