justbur / emacs-which-key

Emacs package that displays available keybindings in popup
GNU General Public License v3.0
1.73k stars 87 forks source link

The texts for the same key in different keymaps are overridden each other #352

Closed goofansu closed 1 year ago

goofansu commented 1 year ago

Minimal config:

;; Package manager
(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 6))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

(straight-use-package 'use-package)
(setq straight-use-package-by-default t)

;; Keybindings
(use-package general
  :config
  (general-define-key
   :prefix "C-c m"
   :keymaps 'org-mode-map
   "t" '(:ignore t :which-key "tasks")
   "tt" #'org-todo
   )

  (general-define-key
   :prefix "C-c m"
   :keymaps 'emacs-lisp-mode-map
   "t" '(:ignore t :which-key "eval")
   "tt" #'eval-defun
   ))

(use-package which-key
  :config (which-key-mode))

Demo

https://github.com/justbur/emacs-which-key/assets/1143191/e376eded-3117-484d-a30e-90f1d4cd7ff9

Reproduce

With the Minimal config below:

  1. Visiting an emacs-lisp mode file, C-c m t shows +eval;
  2. Visiting an org mode file, C-c m t shows +tasks;
  3. Visiting the file in step 1, C-c m t shows +tasks too, which is unexpected.

But I don't confirm whether it is a bug in which-key or general.el.

goofansu commented 1 year ago

Seems the same as https://github.com/noctuid/general.el/issues/186, closing.

goofansu commented 1 year ago

For anyone encounters the problem, the solution is to add :major-modes t, for example:

(use-package general
  :config
  (general-define-key
   :prefix "C-c m"
   :keymaps 'org-mode-map
   :major-modes t
   "t" '(:ignore t :wk "tasks")
   "tt" #'org-todo
   )

  (general-define-key
   :prefix "C-c m"
   :keymaps 'emacs-lisp-mode-map
   :major-modes t
   "t" '(:ignore t :wk "eval")
   "tt" #'eval-defun
   ))

References