Search code examples
emacselisp

define-key: Symbol's function definition is void: lisp-interaction-mode-map


I've got a snippet I want to bind to a key:

(define-key (lisp-interaction-mode-map) (kdb "C-c e")
  (let ((result (eval (read (buffer-substring
                             (point-at-bol) (point-at-eol))))))
    (goto-char (point-at-eol))
    (insert (format " ; %s" result))))

however, when C-c v that in *scratch*, I get

define-key: Symbol's function definition is void: lisp-interaction-mode-map

Solution

  • You have parentheses around lisp-interaction-mode-map, which Lisp interprets to mean that you want to call the function named lisp-interaction-mode-map. Instead, you want to use it as variable.

    I also did some other edits you'll need to get what you have to work. I assumed you wrote read in order to prompt for a user-inputted string:

    (define-key lisp-interaction-mode-map (kbd "C-c C-e")
      (lambda (result)
        (interactive (list (read-from-minibuffer (buffer-substring (point-at-bol) (point-at-eol)))))
        (goto-char (point-at-eol))
        (insert (format " ; %s" result))))