1

In short, I want org-babel's prompt to accept a single y/n keypress instead of typing it out and pressing enter, but I don't want to replace all such prompts globally.

I've seen information on changing to y-or-n-p as the global default via defalias, or turning off the prompt specific to org-babel completely via org-confirm-babel-evaluate, but not how to simply shorten the prompt. I see notes on yes-or-no.el for making functions customizable, but it doesn't seem like that applies to org-babel.

In this particular case (imho), it's important enough to preserve the prompt, but not important enough to justify typing 4 characters to do so each time.

I'm sure there's an easy way to do this, but I'm not finding it.

3

yes-or-no-p is hard-coded into org-babel-confirm-evaluate. We override it with y-or-n-p locally for org-babel-confirm-evaluate:

(eval-when-compile
  (require 'cl-lib))

(defun org+-substitute-yes-or-no-p (fun &rest args)
  "Run FUN with ARGS and `yes-or-no-p' locally substituted by `y-or-n-p'."
  (cl-letf (((symbol-function 'yes-or-no-p) #'y-or-n-p))
    (apply fun args)))

(advice-add 'org-babel-confirm-evaluate :around #'org+-substitute-yes-or-no-p)

Note, that I also tried to set org-confirm-babel-evaluate to the function

(lambda (_lang _body)
  (unless (y-or-n-p "Evaluate source block? ")
    (signal 'quit '("Evaluation of source block aborted"))))

But that does not work nicely. It asks twice for y-or-n-p confirmation for each code block.

Tested with emacs -Q of version 26.3.

| improve this answer | |
  • That worked perfectly for regular emacs. Confusingly I just noticed that on Aquamacs [on a different machine with same .emacs.el] it does this by default. – Digicrat Feb 28 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.