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

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

问题描述

我想知道如何将一个键用作其他键的前缀和命令本身.

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

我将如何设法做到这一点?我真的希望

绑定到 evil-ex,但我也想绑定 作为所有动作(如箭头键)的前缀,将标记设置为无和弦 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.

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

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