Answers:
您可以建议ediff-quit
这样做,以便它动态地重新绑定y-or-n-p
到return 的函数t
。
(defun disable-y-or-n-p (orig-fun &rest args)
(cl-letf (((symbol-function 'y-or-n-p) (lambda (prompt) t)))
(apply orig-fun args)))
(advice-add 'ediff-quit :around #'disable-y-or-n-p)
对于上游更改,此方法比重新定义更可靠ediff-quit
。
不幸的是,我认为您必须重新绑定q或调整的来源ediff-quit
。正如ediff-quit
在提示源中显而易见的那样,总是会发生。
(defun ediff-quit (reverse-default-keep-variants)
"Finish an Ediff session and exit Ediff.
Unselects the selected difference, if any, restores the read-only and modified
flags of the compared file buffers, kills Ediff buffers for this session
\(but not buffers A, B, C\).
If `ediff-keep-variants' is nil, the user will be asked whether the buffers
containing the variants should be removed \(if they haven't been modified\).
If it is t, they will be preserved unconditionally. A prefix argument,
temporarily reverses the meaning of this variable."
(interactive "P")
(ediff-barf-if-not-control-buffer)
(let ((ctl-buf (current-buffer))
(ctl-frm (selected-frame))
(minibuffer-auto-raise t))
(if (y-or-n-p (format "Quit this Ediff session%s? "
(if (ediff-buffer-live-p ediff-meta-buffer)
" & show containing session group" "")))
(progn
(message "")
(set-buffer ctl-buf)
(ediff-really-quit reverse-default-keep-variants))
(select-frame ctl-frm)
(raise-frame ctl-frm)
(message ""))))
我建议ediff-quit
您重新定义您.emacs
的补丁,然后向其提交补丁,以添加自定义变量。
请记住,emacs中的实现源总是需要敲击一些键。假设已安装elisp源,键入C-h f,输入函数名称,然后单击链接定义它。
我在ediff中使用q的以下重新绑定。如果任何缓冲区被修改,它会询问是否要保存它们,然后退出。如果没有修改缓冲区,则退出。
(add-hook 'ediff-startup-hook
(lambda ()
(local-set-key (kbd"q") 'my-ediff-quit)))
(defun my-ediff-quit ()
"If any of the ediff buffers have been modified, ask if changes
should be saved. Then quit ediff normally, without asking for
confirmation"
(interactive)
(ediff-barf-if-not-control-buffer)
(let* ((buf-a ediff-buffer-A)
(buf-b ediff-buffer-B)
(buf-c ediff-buffer-C)
(ctl-buf (current-buffer))
(modified (remove-if-not 'buffer-modified-p
(list buf-a buf-b buf-c))))
(let ((save (if modified (yes-or-no-p "Save changes?")nil)))
(loop for buf in modified do
(progn
(set-buffer buf)
(if save
(save-buffer)
(set-buffer-modified-p nil))))
(set-buffer ctl-buf)
(ediff-really-quit nil))))