cofi / evil-leader

<leader> key for evil
GNU General Public License v3.0
315 stars 22 forks source link

evil-leader-mode: Wrong type argument: keymapp, nil #12

Closed adinapoli closed 11 years ago

adinapoli commented 11 years ago

Hello there,

I have a file called "evil-conf.el" which my .emacs imports:

(when (not (package-installed-p 'evil))
  (package-install 'evil))
(when (not (package-installed-p 'evil-leader))
  (package-install 'evil-leader))

(require 'elscreen)
(require 'evil-leader)
(require 'evil)

(setq evil-leader/in-all-states t)
(setq evil-leader/leader ",")
(evil-mode nil)
(global-evil-leader-mode 1)
(evil-mode 1)
[... more conf ...]

This works fine when emacs loads up, but if I try within Emacs to do "load-file" and then ".emacs" I get the error:

evil-leader-mode: Wrong type argument: keymapp, nil

It's annoying, because it force me to close Emacs each time I change .emacs. I know the error stems from that file due to messages:

Loading /Users/adinapoli/.emacs...
Loading /Users/adinapoli/.emacs.d/hsenv.el (source)...done
Loading /Users/adinapoli/.emacs.d/util.el (source)...done
Loading /Users/adinapoli/.emacs.d/evil-conf.el (source)...
evil-leader-mode: Wrong type argument: keymapp, nil

Any idea? I've also tried to remove the (set-leader) instruction, but the error persist, interestingly. Thanks! A.

suvash commented 11 years ago

I tried using the evil-leader with same results. Emacs would throw the above mentioned error on start. Since I'm not the best at hacking elisp already, I've attached a screenshot of the error.

screen shot 2013-07-30 at 12 38 31 pm

Below is the config I tried using,

(require 'evil-leader)
(global-evil-leader-mode)
cofi commented 11 years ago

Sorry I somehow missed that issue. @adinapoli Please provide the full evil/evil-leader related config. Also, note that (evil-mode nil) enables (as of emasc24) evil, which means you first enable evil and then evil-leader (this leads to existing buffers don't enable evil-leader-mode), just remove that line. Finally, please provide the output emacs --debug-init.

@suvash Please provide the full evil/evil-leader related config.

suvash commented 11 years ago

Following is the relevant section of my config. Just adding the evil-leader package, require it and trying to use it breaks as above.

........

(require 'package)
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/") t)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-initialize)

(when (not package-archive-contents)
  (package-refresh-contents))

(defvar my-packages '(evil evil-leader linum-relative crosshairs helm base16-theme)
  "A list of packages to ensure are installed at launch.")

(dolist (p my-packages)
  (when (not (package-installed-p p))
    (package-install p)))

;;===============================================================================
;; PACKAGES CONFIGURATION
;;===============================================================================

(require 'evil-leader)
(global-evil-leader-mode)

(require 'evil)
(evil-mode 1)

.....
adinapoli commented 11 years ago

This is the complete file which is triggering the error:

(when (not (package-installed-p 'evil))
  (package-install 'evil))
(when (not (package-installed-p 'evil-leader))
  (package-install 'evil-leader))

(require 'elscreen)
(require 'evil-leader)
(require 'evil)

(setq evil-leader/in-all-states t)
(setq evil-leader/leader ",")
(global-evil-leader-mode 1)
(evil-mode 1)

(evil-set-toggle-key "C-a")
(setq evil-default-state 'normal)
(define-key evil-insert-state-map "j" #'cofi/maybe-exit)

(evil-define-command cofi/maybe-exit ()
  :repeat change
  (interactive)
  (let ((modified (buffer-modified-p)))
    (insert "j")
    (let ((evt (read-event (format "Insert %c to exit insert state" ?j)
                           nil 0.5)))
      (cond
       ((null evt) (message ""))
       ((and (integerp evt) (char-equal evt ?j))
        (delete-char -1)
        (set-buffer-modified-p modified)
        (push 'escape unread-command-events))
       (t (setq unread-command-events (append unread-command-events
                                              (list evt))))))))

;; M-x via "\" in terminal
(define-key evil-normal-state-map (kbd "\\") 'execute-extended-command)

;; Fix the problem if the buffer is readonly. The problem is
;; that (interactive) signals an error when the buffer name starts with *
;; This is a backdoorish hack.
(add-hook 'evil-local-mode-hook (lambda ()
                                  (when buffer-read-only (evil-normal-state))))

(setq evil-normal-state-tag   (propertize "N" 'face '((:background "green" :foreground "black")))
      evil-emacs-state-tag    (propertize "E" 'face '((:background "orange" :foreground "black")))
      evil-insert-state-tag   (propertize "I" 'face '((:background "red")))
      evil-motion-state-tag   (propertize "M" 'face '((:background "blue")))
      evil-visual-state-tag   (propertize "V" 'face '((:background "grey80" :foreground "black")))
      evil-operator-state-tag (propertize "O" 'face '((:background "purple"))))

;; Better navigation between windows
(define-key evil-normal-state-map (kbd "C-h") 'windmove-left)
(define-key evil-normal-state-map (kbd "C-l") 'windmove-right)
(define-key evil-normal-state-map (kbd "C-k") 'windmove-up)
(define-key evil-normal-state-map (kbd "C-j") 'windmove-down)
(define-key evil-normal-state-map (kbd "C-u") 'evil-scroll-page-up)

;; .. and buffers
(define-key evil-normal-state-map (kbd "H") 'previous-buffer)
(define-key evil-normal-state-map (kbd "L") 'next-buffer)

(defun safe-kill-buffer ()
   "Kill current buffer just if not modified."
   (interactive)
     (if (buffer-modified-p)
         (message "Can't kill buffer: Buffer was modified!")
     (kill-buffer (current-buffer))))

(defun safe-kill-buffer-and-screen ()
  (interactive)
  (if (buffer-modified-p)
      (message "Can't kill screen: Buffer was modified!")
    (progn
      (safe-kill-buffer)
      (elscreen-kill))))

;; A more effective bd
(evil-ex-define-cmd "bd" 'safe-kill-buffer-and-screen)
(evil-ex-define-cmd "Bk" 'kill-all-buffers)
(evil-ex-define-cmd "bk" (lambda ()
                           (interactive)
                           (kill-buffer (current-buffer))))
(define-key evil-visual-state-map (kbd "gv") 'exchange-point-and-mark)

;; Select when starting in Emacs rather than Evil.
(cl-loop for (mode . state) in '((shell-mode                   . emacs)
                                 (term-mode                    . emacs)
                                 (notmuch-show-mode            . normal)
                                 (notmuch-search-mode          . normal)
                                 (nav-mode                     . normal)
                                 (org-agenda-mode              . normal)
                                 (erc-mode                     . normal))
         do (evil-set-initial-state mode state))

(provide 'evil-conf)
;;; evil-conf.el ends here

--debug-init here doesn't help because the error is not generated at init, I need to remember how to enable debugging to track the error down.

EDIT: Interestingly enough, if I remove the line you suggest @cofi , the error is "elicited" and showed at init time:

Debugger entered--Lisp error: (wrong-type-argument keymapp nil)
2    define-key(nil "," (keymap))
3    evil-leader-mode()
4    run-hooks(evil-local-mode-hook evil-local-mode-on-hook)
5    evil-local-mode(1)
6    evil-initialize()
7    ad-Orig-evil-mode(1)
8    evil-mode(1)
9    eval-buffer(#<buffer  *load*-767154> nil "/Users/adinapoli/.emacs.d/evil-conf.el" nil t)  ; Reading at buffer position 316
10   load-with-code-conversion("/Users/adinapoli/.emacs.d/evil-conf.el" "/Users/adinapoli/.emacs.d/evil-conf.el" nil nil)
11   load("/Users/adinapoli/.emacs.d/evil-conf.el" nil nil t)
12   load-file("~/.emacs.d/evil-conf.el")
13   (progn (load-file (format "%s/%s%s" "~/.emacs.d" pkg-name ".el")) (require pkg-name))
14   (progn (progn (load-file (format "%s/%s%s" "~/.emacs.d" pkg-name ".el")) (require pkg-name)))
15   (if (file-exists-p (format "%s/%s%s" "~/.emacs.d" pkg-name ".el")) (progn (progn (load-file (format "%s/%s%s" "~/.emacs.d" pkg-name ".el")) (require pk$
16   load-and-use(evil-conf)
17   eval-buffer(#<buffer  *load*> nil "/Users/adinapoli/.emacs" nil t)  ; Reading at buffer position 2820
load-with-code-conversion("/Users/adinapoli/.emacs" "/Users/adinapoli/.emacs" t t)
     load("~/.emacs" t t)
     #[0 "^H\205\262^@     \306=\203^Q^@\307^H\310Q\202;^@ \311=\204^^^@\307^H\312Q\202;^@\313\307\314\315#\203*^@\316\202;^@\313\307\314\317#\203:^@\320\nB$
     command-line()
     normal-top-level()
cofi commented 11 years ago

@adinapoli --debug-init effectively sets debug-on-error to t so it's not only for init but provides a means to enable it before something errors out.

I could track it down with suvash's config (strangely it didn't trigger for me although I use a similar order): It could be that the local maps have not been initialized yet, though I have no clue how it could happen.

Please try commit 8c7644d.

adinapoli commented 11 years ago

Any chance you'll put this on MELPA or is not considered a "stable" release?

cofi commented 11 years ago

I usually put it on Marmalade ELPA but I will do so only if it solves the issue - I don't want to spam with possibly broken updates.

suvash commented 11 years ago

Yes, that did the trick. The errors are gone, lemme see if i can run other config

suvash commented 11 years ago

All good. Please go ahead and push it to ELPA. Cheers.

cofi commented 11 years ago

Thanks for testing. It's up.

adinapoli commented 11 years ago

Just for your own curiosity, it's working for me too. Thanks for addressing the issue :)