This question already has an answer here:

System: Windows 10, Emacs 26.1, Helm 3.0

In my init.el:

;; Shell commands history
(define-key shell-mode-map (kbd "C-c C-l") 'helm-comint-input-ring)

When I start Emacs I get the following error:

Warning (initialization): An error occurred while loading ‘d:/Programs/emacs/.emacs.d/init.el’: Symbol's value as variable is void: shell-mode-map To ensure normal operation, you should investigate and remove the cause of the error in your initialization file. Start Emacs with the ‘--debug-init’ option to view a complete error backtrace.

What is at fault?

marked as duplicate by Stefan, Drew, Dan Sep 24 '18 at 15:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • This is also a duplicate of the other question you posted 20 minutes after this one. – Drew Sep 24 '18 at 15:09

shell-mode-map is a variable that is defined in the file shell.el which is not loaded yet, so the variable is undefined.

Two common solutions:

  • (require 'shell) before you try use the variable. That loads the file into emacs, so the variable is now defined. You can then use it normally. If you have to do this with many libraries, that might slow down initialization enough to be noticeable.

  • protect the setting of the variable so that it will be done after the library is loaded:

    (with-eval-after-load "shell" (define-key shell-mode-map (kbd "C-c C-l") 'helm-comint-input-ring))


The variable shell-mode-map doesn't exist. Since it doesn't exist, define-key won't be able to add a key binding to it.

The solution you want is to wait until the variable exists, by deferring the call to define-key until later. Here's an example:

(eval-after-load "shell"
  '(define-key shell-mode-map (kbd "C-c C-l") 'helm-comint-input-ring))

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