Advice for “kill-ring-save”

情到浓时终转凉″ 提交于 2019-12-09 21:10:39

问题


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?

(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.


回答1:


Quick proof of concept; you don't tell what your constraints are, so this is necessarily vague / useless.

(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.



来源:https://stackoverflow.com/questions/12260577/advice-for-kill-ring-save

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