定义键盘退出的新功能并突出显示 [英] define a new function for keyboard-quit and highlight clearup

查看:208
本文介绍了定义键盘退出的新功能并突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很喜欢elisp,而且我正在尝试定义一个功能来在搜索时设置高亮行为。目标是:在 i-search 之后,我想要使用 Cg 清除高亮,但我想



所以我在我的 init.el 中定义了一个函数: / p>

 (defun keyboard-quit-cleanup()
键盘退出后清理highligh
(键盘-quit)
(lazy-highlight-cleanup))
(全局设置键(kbdCg)'(键盘退出清理))

无论如何,它不起作用。这里有什么问题?



谢谢!

解决方案

恐怕:)


  1. 您的全局设置键被破坏:

     (global-set-key(kbdCg)'keyboard-quit-cleanup)

    不:

     (global-set-key(kbdCg)'(keyboard-quit-cleanup))

    (你在哪里看到那个?)


  2. 你的自定义函数不是交互式命令,所以你不能把它绑定到关键。它需要是:

     (defun keyboard-quit-cleanup()
    清除键盘退出后的亮点。
    (交互式)
    ...)


  3. 想要使用 FORCE 参数 lazy-highlight-cleanup




  4. Cg 绑定到 isearch-abort isearch-mode-map keymap。



    (编辑:评论,搞乱了全局绑定肯定是一个坏主意,绝对有一些与之相关的特殊行为,你不想冒险破坏它。)


  5. 当您希望为标准行为添加额外的行为时,您可能希望使用挂钩(优先)或某些建议。在这种情况下,我们可以使用一个方便的钩子。



    请参阅 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)))


(我假设你有 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 :)

  1. 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??)

  2. 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)
      ...)
    

  3. You probably want to use the FORCE argument to lazy-highlight-cleanup

  4. You're binding the wrong thing.

    C-g is bound to isearch-abort in the isearch-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.)

  5. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆