关于“杀戮环保存”的建议 [英] Advice for "kill-ring-save"
问题描述
我想评估某些条件,然后再允许用户复制文本。据我所知,我需要一个有关 kill-ring-save
的建议。如果不满足条件,我需要忽略用户复制该文本的请求,如果满足,则允许它。我怎样才能做到这一点?
I want to evaluate certain conditions before allowing a user to copy a text. As far as I know, I need an advice for "kill-ring-save"
. I need to ignore the user request to Copy that text if conditions are not met and allow it if are satisfied. How can I do this?
(更新)
-有关约束的更多信息:仅在Emacs的特定模式(例如NXML模式)下,才应应用此建议,并且仅当一个/多个时才应使用
(UPDATE) -- MORE ABOUT CONSTRAINTS: only in specific mode of Emacs (e.g. NXML mode) this advice should be applied and only when one/more specific conditions are met.
推荐答案
快速概念验证;
(defvar moo nil)
(defadvice kill-ring-save (around kill-ring-check-constraints activate compile)
"If in `nxml-mode', don't save to kill ring if `moo' is `nil'."
(if (and (eq major-mode 'nxml-mode) (null moo))
(message "Not copied.")
ad-do-it) )
为响应以下评论,添加了其他主要模式约束。如果您希望在每种模式下都这样做,只需进行模式检查即可。
The additional major-mode constraint was added in response to comments below. If you want this in every mode, just take out the mode check.
这篇关于关于“杀戮环保存”的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!