how to answer yes or no automatically in emacs

自闭症网瘾萝莉.ら 提交于 2019-12-09 15:50:19

问题


I binded function semantic-symref to key C-c C-r like this:

(global-set-key (kbd "C-c C-r") 'semantic-symref)

everytime I pressed C-c C-r, it prompted:

Find references for xxxxx? (y or n)

How can I answer it automatically? I tryed using lambda function like this, but failed

(global-set-key (kbd "C-c C-r") (lambda() (interactive) (semantic-symref "yes")))


回答1:


The answer by @huitseeker is quite neat and effective. After four years, with flet and defadvice being obsolete, I wrote the following functions to answer yes automatically. Maybe it's useful for someone.

(defun my/return-t (orig-fun &rest args)
  t)
(defun my/disable-yornp (orig-fun &rest args)
  (advice-add 'yes-or-no-p :around #'my/return-t)
  (advice-add 'y-or-n-p :around #'my/return-t)
  (let ((res (apply orig-fun args)))
    (advice-remove 'yes-or-no-p #'my/return-t)
    (advice-remove 'y-or-n-p #'my/return-t)
    res))

(advice-add 'projectile-kill-buffers :around #'my/disable-yornp)



回答2:


You can advice semantic-symref with something like :

(defadvice semantic-symref (around stfu activate)
      (flet ((yes-or-no-p (&rest args) t)
             (y-or-n-p (&rest args) t))
        ad-do-it))

Beware that you're locally bypassing all confirmations, so you may catch further (other) questions triggered by semantic-symref itself.



来源:https://stackoverflow.com/questions/6591043/how-to-answer-yes-or-no-automatically-in-emacs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!