Following the Mode Tutorial, I /almost/ finished my own mode (my-mode). Now I only have the problem, that my mode-map settings seem to be ignored:

(defvar my-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map [(return)] 'newline-and-indent)
    (define-key map [(meta-y)] 'imenu )
    (define-key map [(control-c) (control-c)] 'compile )
  "Keymap for `my-mode'.")

(define-derived-mode my-mode fundamental-mode "My"
  "A major mode for editing My files."
  :syntax-table my-mode-syntax-table
  (setq-local comment-start "// ")
  (setq-local comment-end "")
  (setq-local comment-start-skip "\\s<+\\s-*")
  (setq-local font-lock-defaults
              '(my-font-lock-keywords nil t)
  (setq-local tab-width 2)
  (setq-local default-tab-width 2)
  (setq-local indent-line-function 'my-indent-line)
  (setq-local compile-command (my-compiler-command))
  (setq-local imenu-generic-expression
              '((nil "^\\s *EventList\\s +\\(\\sw+\\)" 1)) )

The elisp-info tells me that:

• The new mode has its own sparse keymap, named `VARIANT-map`.
  `define-derived-mode` makes the parent mode’s keymap the
  parent of the new map, unless `VARIANT-map` is already set and
  already has a parent.

So I think that my map should be active. When I open a file that uses that buffer, my-mode-map is defined:

my-mode-map is a variable defined in `my.el`.
Its value is (keymap
 (control-c keymap
            (control-c . compile))
 (meta-y . imenu)
 (return . newline-and-indent))

But (describe-key-briefly) tells me: C-c C-c is undefined

On my last post, I made the error that I didn't restart Emacs from scratch, when reproducing this error. This time I did so and I still see this behaviour...

Why is my map not active?

1 Answer 1


It is active, but your uses of define-key are not correct. See the manual. For example, the correct way to get the C-c C-c binding using that syntax is

(define-key my-mode-map [(control ?c) (control ?c)] 'compile)

Here's IMO a more readable way to do it using kbd

(defvar my-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "<return>") 'newline-and-indent)
    (define-key map (kbd "M-y") 'imenu)
    (define-key map (kbd "C-c C-c") 'compile)
  "Keymap for `my-mode'.")

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.