unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "प्रद्युम्न परांजपे" <pradyparanjpe@gmail.com>
To: 71718@debbugs.gnu.org
Subject: bug#71718: Unicode symbols to represent which key special keys
Date: Sat, 22 Jun 2024 14:31:15 +0530	[thread overview]
Message-ID: <CABt=8OY9KzzvpYxXbzH1mKnGPQKWQ4BQB1ekCnubdzdwrBb==w@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1495 bytes --]

Tags: patch

This patch corresponds to the pull request #372
<https://github.com/justbur/emacs-which-key/pull/372>.

This is a proposed feature enhancement in which-key to allow
propertized special key: a single user-defined unicode character that
will replace special keys such as SPC, TAB, RET, ESC, DEL, backspace, ...

Commit:

    Unicode symbols to represent which key special keys

    * lisp/which-key.el (which-key-speical-keys):Use
    symbols to represent special keys.  If value of
    ``which-key-special-keys`` is an *alist* of cons
    cells, whose cars are special keys such as SPC,
    TAB,  ... and the cdrs are symbol strings, replace
    the special keys with corresponding symbols.

    For backward-compatibility, if
    ``which-key-special-keys`` is an ordinary list of
    keys, old logic of truncation to single character
    works.


In GNU Emacs 29.3.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.42, cairo version 1.18.0) of 2024-06-04 built on
 ekadanta.anubandha.home
Repository revision: 00360258caddc0d8cf29ba3d9971125a06f8959b
Repository branch: emacs-29
System Description: Arch Linux

Configured using:
 'configure --prefix=/home/pradyumna/.local --with-native-compilation
 --with-imagemagick --with-gnutls --with-gif --with-tree-sitter
 --with-mailutils --with-harfbuzz --with-modules --with-cairo
 --with-jpeg --with-rsvg --with-xft --with-xpm --with-png --with-pgtk
 --with-dbus --with-tiff --with-webp --with-json'


-- 
Pradyumna Swanand Paranjape

[-- Attachment #1.2: Type: text/html, Size: 1839 bytes --]

[-- Attachment #2: which-key-symbolize.diff --]
[-- Type: text/x-patch, Size: 2612 bytes --]

diff --git a/lisp/which-key.el b/lisp/which-key.el
index 1de599e5497..7d986b7cb05 100644
--- a/lisp/which-key.el
+++ b/lisp/which-key.el
@@ -239,12 +239,20 @@ which-key-highlighted-command-list
   :package-version "1.0" :version "30.1")
 
 (defcustom which-key-special-keys '()
-  "These keys will automatically be truncated to one character.
+  "These keys will be truncated to first character or provided unicode symbol.
 They also have `which-key-special-key-face' applied to them.  This
-is disabled by default.  An example configuration is
-
-\(setq which-key-special-keys \\='(\"SPC\" \"TAB\" \"RET\" \"ESC\" \"DEL\")\)"
-  :type '(repeat string)
+is disabled by default.  Example configurations are
+
+\(setq which-key-special-keys \\='(\"SPC\" \"TAB\" \"RET\" \"ESC\" \"DEL\")\) OR
+
+\(setq which-key-special-keys
+      \\='((\"SPC\" . \"␣\")
+        (\"TAB\" . \"↹\")
+        (\"RET\" . \"⏎\")
+        (\"ESC\" . \"⎋\")
+        (\"DEL\" . \"⌦\")
+        (\"backspace\" . \"⌫\"))\)"
+  :type '(repeat (choice string cons))
   :package-version "1.0" :version "30.1")
 
 (defcustom which-key-buffer-name " *which-key*"
@@ -1686,7 +1694,10 @@ which-key--propertize-key
 `which-key-special-key-face'."
   (let ((key-w-face (which-key--propertize key 'face 'which-key-key-face))
         (regexp (concat "\\("
-                        (mapconcat #'identity which-key-special-keys
+                        (mapconcat #'identity
+                                   (if (consp (car which-key-special-keys))
+                                       (mapcar #'car which-key-special-keys)
+                                     which-key-special-keys)
                                    "\\|")
                         "\\)"))
         (case-fold-search nil))
@@ -1695,8 +1706,12 @@ which-key--propertize-key
                (string-match regexp key))
           (let ((beg (match-beginning 0)) (end (match-end 0)))
             (concat (substring key-w-face 0 beg)
-                    (which-key--propertize (substring key-w-face beg (1+ beg))
-                                           'face 'which-key-special-key-face)
+                    (which-key--propertize
+                     (or (cdr
+                          (assoc (substring key-w-face beg end)
+                                 which-key-special-keys #'string=))
+                         (substring key-w-face beg (1+ beg)))
+                     'face 'which-key-special-key-face)
                     (substring key-w-face end
                                (which-key--string-width key-w-face))))
         key-w-face))))

             reply	other threads:[~2024-06-22  9:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-22  9:01 प्रद्युम्न परांजपे [this message]
2024-06-22 18:17 ` bug#71718: Unicode symbols to represent which key special keys Jeremy Bryant via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-23 15:29 ` bug#71718: Unicode symbols to represent which key special keys, " Robert Pluim
2024-06-28  6:13   ` प्रद्युम्न परांजपे
2024-06-28  7:40     ` Robert Pluim
2024-06-28 17:59       ` Jeremy Bryant via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABt=8OY9KzzvpYxXbzH1mKnGPQKWQ4BQB1ekCnubdzdwrBb==w@mail.gmail.com' \
    --to=pradyparanjpe@gmail.com \
    --cc=71718@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).