joaotavora / sly

Sylvester the Cat's Common Lisp IDE
1.26k stars 142 forks source link

Can't reference sly-mrepl-mode or sly-db-mode in emacs configuration. #507

Closed NicholasBHubbard closed 2 years ago

NicholasBHubbard commented 2 years ago

Sly version: 1.0.43

With the following configuration I get the error Symbol's value as variable is void: sly-mrepl-mode-map.

(require 'sly-autoloads)
(define-key sly-mrepl-mode-map (kbd "M-q") '(lambda () (interactive) (print "foo")))

Similarly if I wrap the keybinding in a with-eval-after-load 'sly then I get the same error but not until I start up sly with M-x sly:

(require 'sly-autoloads)
(with-eval-after-load 'sly
  (define-key sly-mrepl-mode-map (kbd "M-q") '(lambda () (interactive) (print "foo"))))

Here is the backtrace:

Debugger entered--Lisp error: (void-variable sly-mrepl-mode-map)
  (define-key sly-mrepl-mode-map (kbd "M-q") '(lambda nil (interactive) (print "foo")))
  eval-buffer(#<buffer  *load*> nil "/home/nick/.emacs.d/init.el" nil t)  ; Reading at buffer position 42664
  load-with-code-conversion("/home/nick/.emacs.d/init.el" "/home/nick/.emacs.d/init.el" t t)
  load("/home/nick/.emacs.d/init" noerror nomessage)
  startup--load-user-init-file(#f(compiled-function () #<bytecode 0x4be3e9>) #f(compiled-function () #<bytecode 0x4be70d>) t)
  command-line()
  normal-top-level()

I get an identical error if I try to use sly-db-mode-map as well.

However, if I leave the sly-mrepl-mode-map reference out of my config, then start up sly with M-x sly and the evaluate the sly-mrepl-mode-map expression then I get the desired behavior and M-q is bound in the sly repl.

I am not sure how I am supposed to reference sly-mrepl or sly-db from my configuration.

A similar issue seems to have been brought up before in issue #120 but the solution provided was to wrap the sly-mrepl functionality in a with-eval-after-load 'sly block but as shown above this did not work for me.

joaotavora commented 2 years ago

Use eval-after-load happily, but do it for sly-mrepl, not sly. Should work. sly-mrepl is provided after sly is provided.

NicholasBHubbard commented 2 years ago

Ahh it works now thanks. I apologize because now that I look back at #120 I see you made it clear that you need to eval-after-load sly-mrepl.