Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs: Symbol's value as variable is void

Tags:

emacs

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)
like image 993
user2030677 Avatar asked Aug 26 '14 18:08

user2030677


1 Answers

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.

like image 105
Tom Tromey Avatar answered Oct 23 '22 11:10

Tom Tromey