将 `helm-toggle-visible-mark-forward` 绑定到 `helm-map` 中的键

Binding `helm-toggle-visible-mark-forward` to a key in `helm-map`

设置

我有这些 Helm 命令的键绑定:

  (define-key helm-map (kbd "C-a")       #'helm-select-action)
  (define-key helm-map (kbd "C-n")       #'helm-next-page)
  (define-key helm-map (kbd "C-p")       #'helm-previous-page)
  (define-key helm-map (kbd "TAB")       #'helm-next-line)
  (define-key helm-map (kbd "<backtab>") #'helm-previous-line)
  (define-key helm-map (kbd "C-TAB")     #'helm-toggle-visible-mark-forward)

问题

除最后一行 helm-toggle-visible-mark-forward 外,所有这些都有效。当我在 Helm 完成 window 中点击 C-TAB 时,我收到错误消息 <C-tab> is undefined.

我试过的

使用\t

(define-key helm-map (kbd "C-\t")     #'helm-toggle-visible-mark-forward)

-- 结果相同,<C-tab> is undefined

使用<C-tab>

(define-key helm-map (kbd "<C-tab>")     #'helm-toggle-visible-mark-forward)

-- wrong type argument, commandp

删除#

(define-key helm-map (kbd "C-TAB")     'helm-toggle-visible-mark-forward)

-- 结果相同,<C-tab> is undefined

使用M-TAB

(define-key helm-map (kbd "M-TAB")     #'helm-toggle-visible-mark-forward)

-- wrong type argument, commandp

使用 lambda

(define-key helm-map (kbd "M-TAB")     (lambda () (interactive) (helm-toggle-visible-mark-forward)))

-- symbol's function definition is void: helm-toggle-visible-mark-forward

问题

是否可以重新绑定helm-toggle-visible-mark-forward?如果是这样,我做错了什么?

改用这个:

(define-key helm-map (kbd "<C-tab>")     #'helm-toggle-visible-mark-forward)

将 Emacs 帮助 returns 的表单传递给 kbdC-h k 后跟 ControlTab 告诉你:

<C-tab> runs the command ...

参见 Elisp 手册,节点 Function Keys,它是这样说的:

backspace, tab, newline, return, delete

These keys correspond to common ASCII control characters that have special keys on most keyboards.

In ASCII, C-i and <TAB> are the same character. If the terminal can distinguish between them, Emacs conveys the distinction to Lisp programs by representing the former as the integer 9, and the latter as the symbol tab.

Most of the time, it’s not useful to distinguish the two. So normally local-function-key-map (*note Translation Keymaps::) is set up to map tab into 9. Thus, a key binding for character code 9 (the character C-i) also applies to tab. Likewise for the other symbols in this group. The function read-char likewise converts these events into characters.


但是你说你已经试过了

(define-key helm-map (kbd "<C-tab>")     #'helm-toggle-visible-mark-forward)

并且 Emacs 告诉了你这一点——当你试图将它绑定到 M-TAB 时它告诉你同样的事情(这与 C-M-i 是一样的):

 -- wrong type argument, commandp

这意味着 helm-toggle-visible-mark-forward 未定义为命令。您是否加载了定义该功能的文件?该函数的定义是否有一个 interactive 规范(所以它实际上是一个 命令 )?

并且此尝试还表明您​​尚未加载定义函数的文件:

(define-key helm-map (kbd "M-TAB")     (lambda () (interactive) (helm-toggle-visible-mark-forward)))

  -- symbol's function definition is void: helm-toggle-visible-mark-forward

(另一种可能是您加载了一个文件,该文件的命令名称几乎相同,但您拼错了命令名称。)

helm-toggle-visible-mark-forwardhelm-toggle-visible-mark-backward were added in v3.6.1. The latest release(截至 2020 年 4 月 25 日)是 v3.6.0。因此,如果要使用这些功能,则需要从源代码安装。否则,它们将是 undefined.

作为一种变通方法,您可以在您的键绑定之前将它们直接添加到您的配置中,如下所示:

  ;; Adding these functions here until they become available in the main source in version 3.6.1
  (defun helm-toggle-visible-mark-forward ()
    (interactive)
    (helm-toggle-visible-mark 1))

  (defun helm-toggle-visible-mark-backward ()
    (interactive)
    (helm-toggle-visible-mark -1))

  (define-key helm-map (kbd "<C-tab>")     #'helm-toggle-visible-mark-forward)