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

Composition not being used in which-key buffer #340

Closed hmelman closed 2 years ago

hmelman commented 2 years ago

I've defined the following so that I can insert these emoji glyphs via C-x 8 n and a number. Note that these emoji are composed of three characters: an ascii number, (#xfe0f) VARIATION SELECTOR-16 and (#x20e3) COMBINING ENCLOSING KEYCAP

(let ((map (make-sparse-keymap)))
  (define-key map "1" (string-to-vector "1️⃣"))
  (define-key map "2" (string-to-vector "2️⃣"))
  (define-key map "3" (string-to-vector "3️⃣"))
  (define-key map "4" (string-to-vector "4️⃣"))
  (define-key map "5" (string-to-vector "5️⃣"))
  (define-key map "6" (string-to-vector "6️⃣"))
  (define-key map "7" (string-to-vector "7️⃣"))
  (define-key map "8" (string-to-vector "8️⃣"))
  (define-key map "9" (string-to-vector "9️⃣"))
  (define-key map "0" (string-to-vector "0️⃣"))
  (define-key ctl-x-map "8n" (cons "Numbers" map)))

But when I type C-x 8 n and pause so which-key displays help, the characters are not composed as I would like them to be. This screen shot shows this, with the above code shown to verify that these glyphs render in other buffers.

Screen Shot 2022-04-22 at 4 33 24 PM

I couldn't make much progress debugging this. I could switch to the " *which-key*" buffer but I couldn't inspect anything in it because whenever I typed emacs changed to a different buffer. But in Emacs 28, eval'ing the above and enabling which-key and typing C-x 8 n should replicate this. I'm doing this on a macos 11.6.5.

FYI, I first asked this in Emacs Bug #54970, if there are underlying emacs issues to resolve, this can be followed up there.

justbur commented 2 years ago

I'm not sure why you're using string-to-vector, but if I remove those calls and map to the emoji directly it seems to work fine, i.e.,

(let ((map (make-sparse-keymap)))
  (define-key map "1" "1️⃣")
  (define-key map "2" "2️⃣")
  (define-key map "3" "3️⃣")
  (define-key map "4" "4️⃣")
  (define-key map "5" "5️⃣")
  (define-key map "6" "6️⃣")
  (define-key map "7" "7️⃣")
  (define-key map "8" "8️⃣")
  (define-key map "9" "9️⃣")
  (define-key map "0" "0️⃣")
  (define-key ctl-x-map "8n" (cons "Numbers" map)))
hmelman commented 2 years ago

Yes that seems to work fine in Emacs 28. I'm not sure why I thought to use string-to-vector but since opening this I understand emoji much better. Thanks for looking at it.