Skip to content

Instantly share code, notes, and snippets.

@ajvargo
Created January 20, 2013 03:56
Show Gist options
  • Save ajvargo/4576587 to your computer and use it in GitHub Desktop.
Save ajvargo/4576587 to your computer and use it in GitHub Desktop.
An example of getting user input for an Elisp function with a default value divined from context.
(defun input-example (text)
"Gets user input and prints it back. Defaults to word at point"
(interactive
(list
(read-string
(format "Text (%s): " (word-at-point)) ; prompt. It's nice to show the default value
nil ; initial input. This value is prefilled in the mini-buffer. Available but considered deprecated.
nil ; history list if you have a specific one for this
(word-at-point) ; Whatever this evaluates to will be the default value
)))
(message (format "You said '%s'" text)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment