chenyanming / calibredb.el

Emacs calibre client - An Ebook Management Solution in Emacs.
GNU General Public License v3.0
318 stars 16 forks source link

Keybindings don't work in evil-mode (even when evil-mode is set to `evil-emacs-state`) #71

Closed yaqubroli closed 1 year ago

yaqubroli commented 1 year ago

I've been trying to get calibredb-search's normal keybindings to function in evil-mode, but, for example when I type o, evil sees it as a regular text buffer and tries to treat it as such, so I get this in *Messages*:

evil-open-below: Buffer is read-only: #<buffer *calibredb-search*>

My attempt to mitigate this in my org config file is as follows:

** Integrate with Calibre
Use calibre db.
#+begin_src emacs-lisp
  (use-package calibredb
    :defer t
    :config
    (setq calibredb-root-dir "~/Books")
    (setq calibredb-db-dir (expand-file-name "metadata.db" calibredb-root-dir))

    (defun disable-evil-in-calibredb-search ()
      "Switch to `emacs` state if the major mode is `calibredb-search`."
      (when (and (boundp 'evil-mode) evil-mode)
        (evil-emacs-state)))

    :hook (calibredb-search-mode . disable-evil-in-calibredb-search))
#+end_src

I also tried a minimal version of this:

** Integrate with Calibre
Use calibre db.
#+begin_src emacs-lisp
  (use-package calibredb
    :defer t
    :config
    (setq calibredb-root-dir "~/Books")
    (setq calibredb-db-dir (expand-file-name "metadata.db" calibredb-root-dir))
    :hook (calibredb-search-mode . evil-emacs-state))
#+end_src
yaqubroli commented 1 year ago

Nevermind. It turns out that I was configuring it wrong; all I need to do is place this in the config block to tell evil to silence its own keybindings when I'm in calibredb-search:

(evil-set-initial-state 'calibredb-search-mode 'emacs)