~l3kn/org-fc#10: 
Make keymaps easy to customize

#7

The defaults correspond to known evil-mode commands, and I don't appreciate the overrides. I currently remapped most of the org-fc defaults as sequences prefixed by a :localleader.

However, this doesn't remove the default keymaps, which are accidentally executed when I assume I'm doing some evil-mode stuff. I assume this is because you are using a defvar, but I don't know for sure.

I would really appreciate if this was easily customizable.

Status
REPORTED
Submitter
~xyank
Assigned to
No-one
Submitted
4 years ago
Updated
4 years ago
Labels
Feature

~xyank 4 years ago

Here's my remapping code. I use Doom Emacs, in case you are wondering:

(map! :map org-fc-review-flip-mode-map
    :localleader [return] #'org-fc-review-flip
    :localleader "RET"    #'org-fc-review-flip
    :localleader "n"      #'org-fc-review-flip
    :localleader "s"      #'org-fc-review-suspend-card
    :localleader "q"      #'org-fc-review-quit)

  (map! :map org-fc-review-rate-mode-map
    :localleader "a" #'org-fc-review-rate-again
    :localleader "h" #'org-fc-review-rate-hard
    :localleader "g" #'org-fc-review-rate-good
    :localleader "e" #'org-fc-review-rate-easy
    :localleader "s" #'org-fc-review-suspend-card
    :localleader "q" #'org-fc-review-quit)

~l3kn 4 years ago

I don't think defining the keymaps with defvar instead of defcustom makes a difference, e.g. org-mode-map is a defvar, too.

Is there a way to replace the whole keymap with one you've defined instead of adding new keys to the existing ones?

~xyank 4 years ago

I tried (makunbound 'org-fc-review-flip-mode-map) and then manually declaring the variable again in my config.el using the keymaps I wanted, but that didn't seem to work at all. The above mapping code works as long as:

  1. In rate-mode, when I am in insert-mode (I am using Doom Emacs, which uses evil mode), I do not press a, h, g, e, s, and q, which trigger the default keymaps of org-fc-review-rate-mode-map.
  2. In flip-mode, when I am in insert-mode, I do not press RET, n, s, or q, which again triggers the default keymaps of org-fc-review-flip-mode-map.

This is my current config code related to org-fc and keymaps:

(map! :map org-fc-review-flip-mode-map
    :localleader [return] #'org-fc-review-flip
    :localleader "RET"    #'org-fc-review-flip
    :localleader "n"      #'org-fc-review-flip
    :localleader "s"      #'org-fc-review-suspend-card
    :localleader "q"      #'org-fc-review-quit)

  (map! :map org-fc-review-rate-mode-map
    :localleader "a" #'org-fc-review-rate-again
    :localleader "h" #'org-fc-review-rate-hard
    :localleader "g" #'org-fc-review-rate-good
    :localleader "e" #'org-fc-review-rate-easy
    :localleader "s" #'org-fc-review-suspend-card
    :localleader "q" #'org-fc-review-quit)

  (add-hook! '(org-fc-review-flip-mode-hook org-fc-review-rate-mode-hook)
             #'evil-normalize-keymaps)
  (require 'org-fc-keymap-hint)

I plan to test this a bit more later on and hopefully get it fixed, but for now, this janky solution is workable. If you have any insight as to the issue, please tell me.

~l3kn 4 years ago

You can remove all bindings from a keymap with (setq org-fc-review-flip-mode-map (make-sparse-keymap)), maybe that works better than makunbound.

~xyank 4 years ago

You can remove all bindings from a keymap with (setq org-fc-review-flip-mode-map (make-sparse-keymap)), maybe that works better than makunbound.

Tried this:

(setq org-fc-review-flip-mode-map (make-sparse-keymap))
(map! :map org-fc-review-flip-mode-map
    :localleader [return] #'org-fc-review-flip
    :localleader "RET"    #'org-fc-review-flip
    :localleader "n"      #'org-fc-review-flip
    :localleader "s"      #'org-fc-review-suspend-card
    :localleader "q"      #'org-fc-review-quit)

;; same for rate-mode and dashboard-mode

  (add-hook! '(org-fc-review-flip-mode-hook org-fc-review-rate-mode-hook)
             #'evil-normalize-keymaps)
  (require 'org-fc-keymap-hint)

Unfortunately the keymaps stopped working entirely. Using describe-variable on the variables show that the bindings are there, but they just don't work in practice.

~xyank 4 years ago*

I've finally found a sustainable workaround for this issue by adding some code in the init block of use-package:

(use-package! org-fc
  :init
  ;; Remove flip mode and rate mode default keypmappings
  (defvar org-fc-review-flip-mode-map
    (let ((map (make-sparse-keymap)))
      map)
    "Keymap for `org-fc-flip-mode'.")

  (defvar org-fc-review-rate-mode-map
    (let ((map (make-sparse-keymap)))
      map)
    "Keymap for `org-fc-rate-mode'.")

  ;; Make dashboard mappings more convenient
  (defvar org-fc-dashboard-mode-map
    (let ((map (make-sparse-keymap)))
      (define-key map (kbd "C-c C-r") 'org-fc-review-dashboard-context)
      (define-key map (kbd "C-c C-q") 'quit-window)
      (define-key map (kbd "C-c C-g") 'org-fc-dashboard-view)
      map))
)

The above piece of code ensures that the original keymaps do not ever function. I have defined my own keymaps for them instead.

i still don't understand why using makunbound + a new defvar doesn't work, and that I need to create empty defvars before the package is even loaded, to be honest, but I'm satisfied with this solution, and I'm sure other evil users will also be satisfied.

~xyank referenced this from #21 4 years ago

Register here or Log in to comment, or comment via email.