Emacs: Symbol's value as variable is void

37,087

What this means is that, at the point at which you invoke define-key, c-mode-base-map is not yet defined by anything.

The usual fix is to find out where this is defined and require that module. In this case:

(require 'cc-mode)

However there are other possible fixes as well, for example setting the key-binding in a mode hook, or using eval-after-load. Which one you use is up to you; I tend to do the KISS approach since I don't generally care about startup time; but if you do you may want something lazier.

Share:
37,087

Related videos on Youtube

user2030677
Author by

user2030677

Updated on July 24, 2022

Comments

  • user2030677
    user2030677 5 months

    This is my ~/.emacs file:

    (setq-default c-basic-offset 4 c-default-style "linux")
    (setq-default tab-width 4 indent-tabs-mode t)
    (define-key c-mode-base-map (kbd "RET") 'newline-and-indent)
    

    I'm getting a warning when I open up emacs:

    Warning (initialization): An error occurred while loading c:/home/.emacs:

    Symbol's value as variable is void: c-mode-base-map

    To ensure normal operations, 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.

    I ran --debug-init and this is what it returned. I don't know what I means:

    Debugger entered--Lisp error: (void-variable c-mode-base-map)

    (define-key c-mode-base-map (kbd "RET") (quote newline-and-indent)) 
    eval-buffer(#<buffer *load*> nil "c:/home/.emacs" nil t)
    ; Reading at buffer position 311
    load-with-code-conversion("c:/home/.emacs" "c:/home/.emacs" t t)
    load("~/.emacs" t t)
    
  • user2030677
    user2030677 over 8 years
    Thanks. I'm also getting the same thing for achead:include-directories. Any ideas?
  • Tom Tromey
    Tom Tromey over 8 years
    No clue about that one. It sounds like something from an extension, not something distributed with Emacs.

Related