2

When you want to do something, you get sometimes a confirmation prompt in the minibuffer, with pressing yes or no to proceed.

I'm aware that you could change this with typing y instead yes with the following setting.

(fset 'yes-or-no-p 'y-or-n-p)  ;; Ask for y/n instead of yes/no

I'm wondering if you could configure this in a way that he will accept RET as y?

  • 2
    Yes; redefine y-or-n-p to treat RET the same as y. (Personally, I find that if Emacs uses yes-or-no-p it usually has a good reason for it.) – Drew Oct 9 '15 at 23:46
  • Drew, in the source code of y-or-n-p, there is a conditional that reads the input from the string: ((member str '("y" "Y")) (setq answer 'act)) So I need to read the key instead a string. I have looked into the Emacs documentation how to receive key inputs from <RET>, without result. Any suggestion? – ReneFroger Oct 10 '15 at 9:44
  • The way the function is written, a blank string "" equals RET -- i.e., read-string. Evaluate: (read-string "Hello-World: ") and then press the return key and watch the echo area. – lawlist Oct 10 '15 at 15:28
1

As @phils commented simply redefining the key in query-replace-map will effect other things as well. The following copies the key-map to avoid that:

(defun y-or-n-p-with-return (orig-func &rest args)
  (let ((query-replace-map (copy-keymap query-replace-map)))
    (define-key query-replace-map (kbd "RET") 'act)
    (apply orig-func args)))        

(advice-add 'y-or-n-p :around #'y-or-n-p-with-return)
  • It didn't worked out. When I mark multiple files in Dired, and delete it. I need to confirm with yes-or-no to delete the files. When I press RET, then it will not work. When I press y, it will work. So it seems me that there is an error in your solution? – ReneFroger Oct 10 '15 at 11:00
  • @ReneFroger Hm, don't know whats wrong. Does it work when you just eval (y-or-n-p "test")?. I don't use dired, maybe this is not the function which get's called? – clemera Oct 10 '15 at 11:42
  • Are you sure it works properly on your side? – ReneFroger Oct 10 '15 at 14:25
  • @ReneFroger Yes, it works. I tried it with emacs -Q and it works as well. – clemera Oct 10 '15 at 14:38
  • You're right, it turned out that I disabled the (fset 'yes-or-no-p 'y-or-n-p) setting. Now fixed and your snipping works like a charm. – ReneFroger Oct 11 '15 at 16:04

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.