使用键作为前缀和命令 [英] Use key as both prefix and command

查看:89
本文介绍了使用键作为前缀和命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用键作为其他键的前缀和命令本身。

I'd like to know how to use a key as both a prefix for other keys and a command itself.


  1. 我可以用 key-chord.el 通过将关键和弦绑定到第一个键之后的命令,但它有几个问题

  1. I can sorta do this with key-chord.el, by binding the key chords to the commands following the first key but it has several issues


  • 只能与字母数字键一起使用

  • 不是真的,因为我必须在超时之前快速按键*

例如 easy-kill expand-region 支持此功能,但它们具有复杂的代码库,我的lisp技能是'壮观...

Some packages such as easy-kill and expand-region support this functionality, but they have complex codebases, and my lisp skills aren't spectacular...

我该怎么做?我真的很喜欢< menu> 绑定到 evil-ex ,但我也想将< menu> 作为所有运动(如箭头键)的前缀,将标记设置为无和的 cua-selection-mode

How would I manage to do this? I'd really like <menu> to be bound to evil-ex, but I'd like to also bind <menu> as a prefix for all movements (like arrow-keys) that sets the mark like a chordless cua-selection-mode.

由于evil-ex没有跟随运动,没有运动自我插入,这将是一个完美的用例。 < menu> 是完美的,因为它正好在箭头键和其他动作键旁边(例如,结束,家庭等),并且它没有修改。

Since evil-ex isn't followed by movements and no movement self inserts, this would be a perfect use-case. <menu> is perfect because it's right next to the arrow keys and other motions keys (eg. end, home etc.) and it's unmodified.

推荐答案

似乎你想要一些类似 smartrep ,它允许将密钥指定为多个命令的公共前缀。唯一要丢失的东西是将命令绑定到公用的前缀键,所以你需要用 smartrep 内部一点点您的功能是

It seems that you want something like smartrep which enables specifying a key as a common prefix for several commands. The only thing you'll be missing out-of-the-box is binding a command to the common prefix key, so you'll need to get your hands dirty with smartrep internals a bit. The function you're after is

(smartrep-read-event-loop
  '((KEY1 command)
    (KEY2 command)
    ...))

这是一段代码这可能会让你开始:

Here's a piece of code that may get you started:

(defun my-command-with-prefix ()
  (interactive)

  (invoke-prefix-command)

  (initialize-event-loop)

  ;; The form
  ;;
  ;;   (condition-case ERR FORM (quit QUIT-HANDLER))
  ;;
  ;; is there to catch C-g key presses and make sure that
  ;; finalization code is run.
  (condition-case e
      (smartrep-read-event-loop
       '(("a" . command1)
         ("b" . command2)
         ("c" . command3)))

    (quit nil))

  ;; finalize loop
  (finalize-event-loop))

上面的代码片段基本上是一个经过蒸馏的代码发现的代码这里

The snippet above is essentially a distilled version of code found here.

这篇关于使用键作为前缀和命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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