help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to avoid y-or-n-p in a program?


From: Tassilo Horn
Subject: Re: How to avoid y-or-n-p in a program?
Date: Wed, 12 Mar 2014 17:14:28 +0100
User-agent: Gnus/5.13001 (Ma Gnus v0.10) Emacs/24.3.50 (gnu/linux)

Thorsten Jolitz <address@hidden> writes:

Hi Thorsten,

> when in a program function A calls another (external) function B that
> asks the user a y-or-n-p question, and you want to avoid that and
> instead code in function A that the answer is always Y, so that the
> prompt never shows up - how do you do that?

In very recent emacs versions, you can use `cl-letf' for that purpose:

--8<---------------cut here---------------start------------->8---
(defun b ()
  (if (y-or-n-p "do it?")
      :done
    :not-done))

(defun a ()
  (cl-letf (((symbol-function #'y-or-n-p)
             (lambda (&rest ignore) t)))
    (b)))

(a) ;; C-x C-e => :done (and no query)
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]