Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

which-key binding in one key map showing up in another #186

Closed
willbush opened this issue Jun 3, 2020 · 8 comments
Closed

which-key binding in one key map showing up in another #186

willbush opened this issue Jun 3, 2020 · 8 comments

Comments

@willbush
Copy link

willbush commented Jun 3, 2020

I have run into a situation where the which-key binding: "n" '(:ignore t :which-key "dired-narrow") in one key map is showing up in another.

I have setup a simple init.el that can reproduce the issue:

;;; init.el -*- lexical-binding: t; -*-

(require 'package)

(add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/"))

(package-initialize)

;; bootstrap use-package with package.el
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(require 'use-package)

;; ensure everything is installed
(setq use-package-always-ensure t)

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

(use-package evil :config (evil-mode +1))

(use-package general)

(general-def
  :prefix ","
  :states 'normal
  :keymaps 'org-mode-map
  "n" 'org-move-subtree-down
  "e" 'org-move-subtree-up
  "m" 'org-do-promote
  "i" 'org-do-demote)

(use-package dired-narrow
  :config
  (general-def
    :prefix ","
    :states 'normal
    :keymaps 'dired-mode-map
    "n" '(:ignore t :which-key "dired-narrow")
    "nn" 'dired-narrow
    "nf" 'dired-narrow-fuzzy
    "nr" 'dired-narrow-regexp))

When I open an org file and press the prefix , "dired-narrow" shows up as a which-key suggestion.

Screenshot from 2020-06-03 03-06-54

@noctuid
Copy link
Owner

noctuid commented Jun 3, 2020

Since there is no binding to match against, you'll need to use :major-modes to have the keybinding only show up in dired. I'll add a note to the readme about this.

@willbush
Copy link
Author

willbush commented Jun 6, 2020

I'm not sure what the correct etiquette is. Should I close the issue or did you want to after adding a note in the readme?

@noctuid
Copy link
Owner

noctuid commented Jun 10, 2020

I'm going to leave it open until I add a note to the readme.

@dantheobserver
Copy link

dantheobserver commented Jun 14, 2020

I'm getting something similar and when I add the :marjor-modes

(general-create-definer minor-mode-def
  :prefix ","
  :non-normal-perfix "M-,")
general-evil-define-key '(normal visual) elisp
  :prefix ","
  "e" '(:ignore t :which-key "eval")
...

  "p" '(:ignore t :which-key "pretty-print" :major-modes 'elisp)
...

(minor-mode-def '(normal motion) 'evil-org
  "c" '(:ignore t :which-key "clock" :major-modes 'org-mode)
...

  "p" '(:ignore t :which-key "pomodoro" :major-modes 'org-mode)
...
)

and p shows up as "+prefix" in org-mode, but pretty prent properly in elisp.

@tshu-w
Copy link

tshu-w commented Jan 11, 2021

@dantheobserver maybe you should set minor-mode-def with :major-modes t like this?

(general-create-definer despot-def
    :states '(normal insert visual motion emacs)
    :keymaps 'override
    :major-modes t
    :prefix ","
    :non-normal-prefix "M-,")

@paultopia
Copy link

Ooh, thank you for this issue. I just got here from noticing this problem myself.

I confess to not understanding the existing documentation for :major-mode, but I am just cargo-cult-style sticking :major-modes t into all my general-create-definer invocations in the hopes that this just fixes the problem. If there isn't any disadvantage to something like that, is there maybe a case for making this the default? It's hard to think of a situation where people would want which-key hints showing up in major modes in which the underlying keybindings aren't actually what they say they are...

@tshu-w
Copy link

tshu-w commented Feb 3, 2021

It's hard to think of a situation where people would want which-key hints showing up in major modes in which the underlying keybindings aren't actually what they say they are...

I have a definer like spacemacs's SPC, it should be work in global.

@noctuid
Copy link
Owner

noctuid commented Jul 30, 2021

Closing in favor of #193. Adding :major-modes won't be necessary once this is implemented. Everything should just work without extra keywords.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants