Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elisp: Asking yes-or-no in interactive commands

Tags:

emacs

lisp

elisp

I'm new to Emacs and am trying to write a few Emacs Lisp functions.

I'd like to write a function that takes two parameters and can handle being interactive. However, one of the parameters is a boolean — it'd be perfect if I could use (y-or-no-p), but (interactive) doesn't seem to have a character code for that.

Any ideas?

Update: I'm using GNU Emacs 23.

Also, here's what my function looks like so far:

(defun foo (str bool)
  (interactive "sSome text: \nsDo the thing?")
  (some-func str)
  (if bool (some-other-func str)))
like image 894
a paid nerd Avatar asked Dec 21 '10 07:12

a paid nerd


2 Answers

Ah, found it.

(defun foo (str bool)
  (interactive
    (list (read-string "Some text: ")
          (y-or-n-p "Do the thing? ")))
  (some-func str)
  (if bool (some-other-func str)))
like image 194
a paid nerd Avatar answered Sep 21 '22 15:09

a paid nerd


Not quite sure what you're asking, but I can't find a function called y-or-no-p. Did you mean yes-or-no-p?

That seems to do what I would expect.

like image 30
Mikel Avatar answered Sep 23 '22 15:09

Mikel