定义键盘退出的新功能并突出显示 [英] define a new function for keyboard-quit and highlight clearup
问题描述
i-search
之后,我想要使用 Cg
清除高亮,但我想 所以我在我的 init.el
中定义了一个函数: / p>
(defun keyboard-quit-cleanup()
键盘退出后清理highligh
(键盘-quit)
(lazy-highlight-cleanup))
(全局设置键(kbdCg)'(键盘退出清理))
无论如何,它不起作用。这里有什么问题?
谢谢!
恐怕:)
-
您的
全局设置键
被破坏:(global-set-key(kbdCg)'keyboard-quit-cleanup)
不:
(global-set-key(kbdCg)'(keyboard-quit-cleanup))
(你在哪里看到那个?)
-
你的自定义函数不是交互式命令,所以你不能把它绑定到关键。它需要是:
(defun keyboard-quit-cleanup()
清除键盘退出后的亮点。
(交互式)
...)
-
想要使用
FORCE
参数lazy-highlight-cleanup
-
当您希望为标准行为添加额外的行为时,您可能希望使用挂钩(优先)或某些建议。在这种情况下,我们可以使用一个方便的钩子。
请参阅 Ch v
isearch -mode-end-hook
RET(add-hook'isearch-mode-end-hook'my-isearch-end)
(defun my-isearch-end()
isearch-mode-end-hook的自定义行为'
(当isearch-mode-end-hook-quit
(lazy-highlight-cleanup t)))
Cg 绑定到 isearch-abort
isearch-mode-map
keymap。
(编辑:评论,搞乱了全局绑定肯定是一个坏主意,绝对有一些与之相关的特殊行为,你不想冒险破坏它。)
(我假设你有 lazy-highlight-cleanup
设置为 nil
通常情况下,默认情况下会进行清理。)
I am pretty new to elisp, and i was trying to define a function to set highlight behavior while searching. The goal is: after i-search
, I want to be able to clear the highlight with C-g
, but I want the highlight to remain if I press enter.
So i defined a function in my init.el
as:
(defun keyboard-quit-cleanup ()
"clean up highligh after keyboard quit"
(keyboard-quit)
(lazy-highlight-cleanup))
(global-set-key (kbd "C-g") '(keyboard-quit-cleanup))
how-ever, it doesn't work. What's wrong here?
thanks!
Lots of things, I'm afraid :)
Your
global-set-key
is broken:(global-set-key (kbd "C-g") 'keyboard-quit-cleanup)
not:
(global-set-key (kbd "C-g") '(keyboard-quit-cleanup))
(where did you see that??)
Your custom function is not an interactive command, so you cannot bind it to a key. It needs to be:
(defun keyboard-quit-cleanup () "Clean up highlights after keyboard quit." (interactive) ...)
You probably want to use the
FORCE
argument tolazy-highlight-cleanup
You're binding the wrong thing.
C-g is bound to
isearch-abort
in theisearch-mode-map
keymap.(edit: and as per tripleee's comment, messing with the global binding is surely a bad idea. There's definitely some special behaviour associated with it, and you don't want to risk breaking it.)
As you're looking to add an additional behaviour to a standard behaviour, you probably want to use a hook (by preference) or some advice. In this case there's a convenient hook we can use.
See C-hv
isearch-mode-end-hook
RET(add-hook 'isearch-mode-end-hook 'my-isearch-end) (defun my-isearch-end () "Custom behaviours for `isearch-mode-end-hook'." (when isearch-mode-end-hook-quit (lazy-highlight-cleanup t)))
(I assume you have lazy-highlight-cleanup
set to nil
normally, as otherwise the clean-up happens by default.)
这篇关于定义键盘退出的新功能并突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!