June 9, 2024
Some Emacs commands tend to ask too many confirmation questions, or at least it would be nice to have the option to skip the confirmation step. For example, saving and quitting a merge session in ediff requires quitting, confirming the quit, and then confirming the save.
I wanted to bind a single keystroke that would unconditionally commit my changes and end ediff. In the process, with the help of a coaching session from Prot, I made a general-purpose wrapper around any Emacs function to bypass confirmation.
(defun always-yes (&rest args) (cl-letf (((symbol-function 'yes-or-no-p) #'always) ((symbol-function 'y-or-n-p) #'always)) (funcall-interactively (car args) (cdr args))))
I then used it to bind Q
to unconditionally quit ediff, which requires a little more work than other packages typically would:
(defun my/ediff-quit-unconditionally () (interactive) (always-yes #'ediff-quit)) (defun add-Q-to-ediff-mode-map () (define-key ediff-mode-map "Q" 'my/ediff-quit-unconditionally)) (add-hook 'ediff-keymap-setup-hook 'add-Q-to-ediff-mode-map)
This is a small improvement to be sure, but little quality of life improvements like this accrue over time. It’s one of the things I like most about Emacs.