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

119 views Asked by At

Setup

I have these key bindings of Helm commands:

  (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)

Problem

All of these work except for the last line, helm-toggle-visible-mark-forward. When I hit C-TAB in the Helm completion window, I get the error message, <C-tab> is undefined.

What I've Tried

Using \t

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

   -- same result, <C-tab> is undefined

Using <C-tab>

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

   -- wrong type argument, commandp

Removing #

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

  -- same result, <C-tab> is undefined

Using M-TAB

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

  -- wrong type argument, commandp

Using a 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

Question

Is it possible to rebind helm-toggle-visible-mark-forward? If so, what am I doing wrong?

2

There are 2 answers

0
iluvfugu On BEST ANSWER

helm-toggle-visible-mark-forward and helm-toggle-visible-mark-backward were added in v3.6.1. The latest release (as of 2020-04-25) is v3.6.0. Hence, you would need to install from source if you want to use these functions. Otherwise, they will be undefined.

As a workaround, you can add them directly to your configs before your key bindings like so:

  ;; 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)
1
Drew On

Use this instead:

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

Pass the form that Emacs help returns for a key sequence you press to kbd. C-h k followed by Control with Tab tells you:

<C-tab> runs the command ...

See the Elisp manual, node Function Keys, which says this:

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.


But you say that you already tried

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

and Emacs told you this -- and it told you the same thing when you tried to bind it to M-TAB (which is the same thing as C-M-i):

 -- wrong type argument, commandp

That means that helm-toggle-visible-mark-forward isn't defined as a command. Did you load the file that defines that function? And does that function's definition have an interactive spec (so it is in fact a command)?

And this attempt also suggests that you have not loaded the file that defines the function:

(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

(Another possibility is that you loaded a file that has a command with almost the same name, and you misspelled the command name.)