5

I'm trying to define a prefix keymap for a minor mode, but I'm getting a result I've not seen yet:

`link-grammar-mode' Minor Mode Bindings:
key             binding
---             -------

<C-.>           link-grammar-prefix-map

<C-.> <p>       link-grammar-parse-paragraph
<C-.> <r>       link-grammar-parse-region
<C-.> <s>       link-grammar-parse-sentence

Here's how I've defined it:

(define-prefix-command 'link-grammar-prefix-map)

(define-key link-grammar-prefix-map [s] 'link-grammar-parse-sentence)
(define-key link-grammar-prefix-map [p] 'link-grammar-parse-paragraph)
(define-key link-grammar-prefix-map [r] 'link-grammar-parse-region)

(define-minor-mode link-grammar-mode
  "Enables display of the parse of the natural language text
produced by link-grammar parser library"
  :initial-value nil
  :lighter " LG"
  :keymap '(([C-.] . link-grammar-prefix-map))
  :group 'link-grammar
  (run-hooks link-grammar-hooks)
  (message "link-grammar minor mode activated"))

Could please anyone explain what happened? I can see the map added to minor-mode-map-alist, but the keys aren't "activated".

1
  • 1
    See the Elisp manual, node Key Sequences, for possible values of the KEY argument to define-key.
    – Drew
    Oct 10, 2014 at 15:28

1 Answer 1

4

Some events understood by Emacs are characters which in turn are just integers. So a key which is an integer can be greater or smaller than another such key.

Then there are events which are represented using symbols, e.g. return. Functions that take events as arguments accept different representations for these events. For return one can use "<return>" or [return]. However the vector representation is only intended for "symbol events", you can not use it for character events. So [s] is wrong, there is no such event; instead use [?s] or "s".

5
  • [s] is wrong, there is no such event; instead use "s". You can also use [?s].
    – Drew
    Oct 10, 2014 at 15:25
  • Thank you! But could you please also comment on this: gnu.org/software/emacs/manual/html_node/elisp/… ? Specifically, [C-backspace]? Is this also an event? How do you tell, which is a key and which is an event? How do you know what events are available?
    – wvxvw
    Oct 10, 2014 at 15:45
  • 1
    Here you go Input Events. The short answer is use the kbd function to conveniently define keys.
    – Vamsi
    Oct 10, 2014 at 15:50
  • Thanks, I just found that page too, so most of my questions are answered except for [C-backspace] (notice how there isn't a backslash before C - is this perhaps an error in documentation?).
    – wvxvw
    Oct 10, 2014 at 15:52
  • 2
    An easy way to find out how emacs sees a key is to use C-h k mapped to describe-key. C-h k C-backspace gives me <C-backspace> so emacs will definitely recognize this angled braces form. Use this with the kbd function.
    – Vamsi
    Oct 10, 2014 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.