

- #Autoanswer yes to prompts manual#
- #Autoanswer yes to prompts full#
- #Autoanswer yes to prompts code#
You can give users a way to override your choices on a calling function-by-function basis, by using library yes-no.el. Still, users can have different preferences in this regard.
#Autoanswer yes to prompts code#
( defalias ' yes-or-no-p 'my-yes-or-mumble-p) Library `yes-no.el': Let Users Chooseįor Lisp code that you write, you make a good judgment about whether to use ‘yes-or-no-p’ or ‘y-or-n-p’ for each confirmation prompt context. "PROMPT user with a yes-or-no question, but only test for yes."

#Autoanswer yes to prompts full#
If you would prefer to have an empty response (hitting ‘RET’) or any other input to act as ‘no’, but still require the full word ‘yes’ to confirm, you can use this function as an alias for ‘yes-or-no-p’. (mapcar ( lambda (elt) (add-to-list 'yes-or-no-p-history elt)) You can predefine the ‘yes’ and ‘no’ answers for ‘yes-or-no-p’ so you can select them (retrieving them as past inputs) using ‘M-p’. (apply fun args)))) Responding To `yes-or-no-p' Prompts Without Typing ((symbol-function 'yes-or-no-p) #'always-yes)) (cl-letf (((symbol-function 'y-or-n-p) #'always-yes) "Apply FUN to ARGS, skipping user confirmations." Without advising, here’s another way to force a function to act (assume yes) without asking for confirmation: use (no-confirm SOME-FUNCTION). ((symbol-function 'y-or-n-p) ( lambda ( &rest args) t))) (cl-letf (((symbol-function 'yes-or-no-p) ( lambda ( &rest args) t)) ( defadvice SOME-FUNCTION (around auto-confirm compile activate) Or, since ‘flet’ is deprecated, advising using ‘cl-letf’. And see also AdviceVsHooks before you decide to advise a function. But if you do this, be careful that it doesn’t also catch lower-level questions. For example, RevertBuffer asks before rereading a file, but you can set user option ‘revert-without-query’ to record files that you want to be able to revert without confirming.Īnd you can advise a function (see AdvisingFunctions) to prevent it from asking yes or no and just assume yes. Some ‘yes-or-no-p’ prompts can be disabled. Auto-Confirmation: Automatically Saying Yes

Is that a good idea? Depends on the user, presumably. If you want to do that, put this in your init file ( ~/.emacs): ( defalias ' yes-or-no-p 'y-or-n-p) Some users apparently feel that no ‘yes-or-no-p’ prompts are important enough to warrant typing two or three characters, and they prefer to substitute ‘y-or-n-p’ for ‘yes-or-no-p’ everywhere, to save typing one or two characters. However, Emacs design decisions need to be relatively conservative, and they need to fit the needs of the average user, as well as the EmacsNewbie. Some Users Want to Always Use `y-or-n-p', Never `yes-or-no-p' You are asked to type a full word not to annoy you but to save you from shooting yourself in the foot. For functions delivered as part of vanilla Emacs, the designers of Emacs have presumably based their decisions on years of experience with user problems. The author of a function prompts users for a yes-or-no answer decides which of these prompting functions to use.
#Autoanswer yes to prompts manual#
See the Elisp manual doc for yes-or-no-p. You must type a full ‘yes’ or ‘no’ to answer ‘yes-or-no-p’. It is typically used for more important yes-or-no questions, that is, questions where the answer might have more serious consequences.

‘yes-or-no-p’ is another way that Emacs uses to do this. ‘y-or-n-p’ is one way that Emacs asks a yes-or-no question, usually to get your confirmation for something you requested.
