我如何立即退出ediff而不必键入“ y”


13

当我退出ediff时,系统q会询问我是否真的要退出。我宁愿立即退出。定制之下没有什么显而易见的。有一个解决方案在这里它通过重新定义似乎工作q的关键,但我不知道的功能是如何工作的细节。戒烟真正意味着戒烟最简单的方法是什么?

Answers:


13

您可以建议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


如果它将通知是否有任何不同的缓冲区已更改,那将是完美的。
CodyChan

5

不幸的是,我认为您必须重新绑定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,输入函数名称,然后单击链接定义它。


1

我在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))))
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.