unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#36156: [PATCH] Make toolbar show keyboard equivalents in its tooltips
@ 2019-06-10  1:14 Stefan Kangas
  2019-06-10  2:06 ` Noam Postavsky
  2019-08-24 20:40 ` Juri Linkov
  0 siblings, 2 replies; 13+ messages in thread
From: Stefan Kangas @ 2019-06-10  1:14 UTC (permalink / raw)
  To: 36156

[-- Attachment #1: Type: text/plain, Size: 258 bytes --]

I have implemented the following item from etc/TODO:

** The toolbar should show keyboard equivalents in its tooltips.

I'm an absolute beginner to Emacs internals and had a lot of fun
solving this.  Please let me know what you think.

Thanks,
Stefan Kangas

[-- Attachment #2: 0001-Make-toolbar-show-keyboard-equivalents-in-its-toolti.patch --]
[-- Type: application/octet-stream, Size: 3671 bytes --]

From 082f6405334d4cffaa77cf17dccb3e64e923cdfd Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Sun, 9 Jun 2019 04:27:09 +0200
Subject: [PATCH] Make toolbar show keyboard equivalents in its tooltips

* src/keyboard.c (parse_tool_bar_item): Add equivalent key binding to
the tooltip string of toolbar buttons.
* etc/NEWS: Announce it.
* etc/TODO: Remove its entry.
* src/fns.c (concat4): New function.
* src/lisp.h (concat4): Declare.
---
 etc/NEWS       |  3 +++
 etc/TODO       |  2 --
 src/fns.c      |  7 +++++++
 src/keyboard.c | 13 +++++++++++++
 src/lisp.h     |  1 +
 5 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index c9da98b0ad..7726443551 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -121,6 +121,9 @@ This is intended mostly to help developers.
 ** Emacs now requires GTK 2.24 and GTK 3.10 for the GTK 2 and GTK 3
 builds respectively.
 
+---
+** The toolbar now shows the equivalent key binding in its tooltips.
+
 \f
 * Startup Changes in Emacs 27.1
 
diff --git a/etc/TODO b/etc/TODO
index f8c2d285ee..b9c8c0aae9 100644
--- a/etc/TODO
+++ b/etc/TODO
@@ -176,8 +176,6 @@ See the 'test' directory for examples.
 ** In Emacs Info, examples of using Customize should be clickable
    and they should create Custom buffers.
 
-** The toolbar should show keyboard equivalents in its tooltips.
-
 ** Add function to redraw the tool bar.
 
 ** Redesign the load-history data structure so it can cope better
diff --git a/src/fns.c b/src/fns.c
index eaa2c07fbe..f089503939 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -536,6 +536,13 @@ concat3 (Lisp_Object s1, Lisp_Object s2, Lisp_Object s3)
   return concat (3, ((Lisp_Object []) {s1, s2, s3}), Lisp_String, 0);
 }
 
+/* ARGSUSED */
+Lisp_Object
+concat4 (Lisp_Object s1, Lisp_Object s2, Lisp_Object s3, Lisp_Object s4)
+{
+  return concat (4, ((Lisp_Object []) {s1, s2, s3, s4}), Lisp_String, 0);
+}
+
 DEFUN ("append", Fappend, Sappend, 0, MANY, 0,
        doc: /* Concatenate all the arguments and make the result a list.
 The result is a list whose elements are the elements of all the arguments.
diff --git a/src/keyboard.c b/src/keyboard.c
index bb4d185c91..02ae05e08d 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -8297,6 +8297,19 @@ parse_tool_bar_item (Lisp_Object key, Lisp_Object item)
   if (CONSP (get_keymap (PROP (TOOL_BAR_ITEM_BINDING), 0, 1)))
     return 0;
 
+  /* If there is a key binding, add it to the help, which will be
+     displayed as a tooltip for this entry. */
+  Lisp_Object binding = PROP (TOOL_BAR_ITEM_BINDING);
+  Lisp_Object keys = Fwhere_is_internal (binding, Qnil, Qt, Qnil, Qnil);
+  if (!NILP (keys))
+    {
+      AUTO_STRING (beg, "  [");
+      AUTO_STRING (end, "]");
+      Lisp_Object orig = PROP (TOOL_BAR_ITEM_HELP);
+      Lisp_Object desc = Fkey_description (keys, Qnil);
+      set_prop (TOOL_BAR_ITEM_HELP, concat4 (orig, beg, desc, end));
+    }
+
   /* Enable or disable selection of item.  */
   if (!EQ (PROP (TOOL_BAR_ITEM_ENABLED_P), Qt))
     set_prop (TOOL_BAR_ITEM_ENABLED_P,
diff --git a/src/lisp.h b/src/lisp.h
index 77fc22d118..4faf9d0bf1 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3613,6 +3613,7 @@ #define CONS_TO_INTEGER(cons, type, var)				\
 extern Lisp_Object do_yes_or_no_p (Lisp_Object);
 extern Lisp_Object concat2 (Lisp_Object, Lisp_Object);
 extern Lisp_Object concat3 (Lisp_Object, Lisp_Object, Lisp_Object);
+extern Lisp_Object concat4 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object);
 extern bool equal_no_quit (Lisp_Object, Lisp_Object);
 extern Lisp_Object nconc2 (Lisp_Object, Lisp_Object);
 extern Lisp_Object assq_no_quit (Lisp_Object, Lisp_Object);
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2019-08-26  6:26 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-10  1:14 bug#36156: [PATCH] Make toolbar show keyboard equivalents in its tooltips Stefan Kangas
2019-06-10  2:06 ` Noam Postavsky
2019-06-10  3:30   ` Stefan Kangas
2019-06-10 16:54     ` Eli Zaretskii
2019-06-11 21:28       ` Stefan Kangas
2019-06-22  9:13         ` Eli Zaretskii
2019-08-24 20:40 ` Juri Linkov
2019-08-25 11:03   ` Stefan Kangas
2019-08-25 11:46     ` Eli Zaretskii
2019-08-25 12:58       ` Stefan Kangas
2019-08-25 13:10         ` Eli Zaretskii
2019-08-25 20:18           ` Juri Linkov
2019-08-26  6:26             ` Eli Zaretskii

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).