Shep
Shep

Reputation: 8370

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

I'm trying to remap some keys in dired like this:

(add-hook 'dired-mode-hook
  (lambda ()
    (require 'dired )
    (define-key dired-mode-map (kbd "M-o") nil)))
    (define-key dired-mode-map (kbd "M-o") 'other-window)
    ))

Unfortunately this doesn't seem to work, I get this error

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

Which is werid, because I should be loading in dired. What could I be doing wrong?

Upvotes: 8

Views: 4487

Answers (1)

lawlist
lawlist

Reputation: 13457

The original poster has two (2) many [pun intended] closing parentheses at this point: (define-key dired-mode-map (kbd "M-o") nil))) -- i.e., two (2) closing parentheses at the end of that line need to be eliminated. Furthermore, I do not see a reason to set the binding to nil before redefining it.

The following is another way of accomplishing the same goal. Add any additional key bindings after the progn statement as desired.

(eval-after-load "dired" '(progn
  (define-key dired-mode-map (kbd "M-o") 'other-window) ))

Upvotes: 12

Related Questions