Subject: Re: bug#36603: [PATCH] Simplify calling convention of describe_map

From: Stefan Kangas <[email-masked]>
Date: Thu, 11 Jul 2019 19:37:44 +0200

Stefan Kangas <[email-masked]> writes:
> (I'll send the patch in a separate message once this is assigned a bug
> number.)

Patch attached.

Thanks,
Stefan Kangas
From 5e35a437cb3d65919b8a547e421e69b3192c75f9 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <[email-masked]>
Date: Thu, 11 Jul 2019 19:18:12 +0200
Subject: [PATCH] Simplify calling convention of describe_map (Bug#36603)

* src/keymap.c (describe_map): Simplify calling convention.
(describe_map_tree): Use new convention.
---
 src/keymap.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/keymap.c b/src/keymap.c
index fc04c565a1..38be73bad8 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -89,11 +89,8 @@
 static Lisp_Object store_in_keymap (Lisp_Object, Lisp_Object, Lisp_Object);
 
 static Lisp_Object define_as_prefix (Lisp_Object, Lisp_Object);
-static void describe_command (Lisp_Object, Lisp_Object);
-static void describe_translation (Lisp_Object, Lisp_Object);
 static void describe_map (Lisp_Object, Lisp_Object,
-                          void (*) (Lisp_Object, Lisp_Object),
-			  bool, Lisp_Object, Lisp_Object *, bool, bool);
+			  bool, bool, Lisp_Object, bool, bool);
 static void describe_vector (Lisp_Object, Lisp_Object, Lisp_Object,
                              void (*) (Lisp_Object, Lisp_Object), bool,
                              Lisp_Object, Lisp_Object, bool, bool);
@@ -2924,7 +2921,7 @@ describe_map_tree (Lisp_Object startmap, bool partial, Lisp_Object shadow,
 		   Lisp_Object prefix, const char *title, bool nomenu,
 		   bool transl, bool always_title, bool mention_shadow)
 {
-  Lisp_Object maps, orig_maps, seen, sub_shadows;
+  Lisp_Object maps, orig_maps, sub_shadows;
   bool something = 0;
   const char *key_heading
     = "\
@@ -2932,7 +2929,6 @@ describe_map_tree (Lisp_Object startmap, bool partial, Lisp_Object shadow,
 ---             -------\n";
 
   orig_maps = maps = Faccessible_keymaps (startmap, prefix);
-  seen = Qnil;
   sub_shadows = Qnil;
 
   if (nomenu)
@@ -2999,9 +2995,8 @@ describe_map_tree (Lisp_Object startmap, bool partial, Lisp_Object shadow,
 	    sub_shadows = Fcons (XCDR (XCAR (tail)), sub_shadows);
 	}
 
-      describe_map (Fcdr (elt), elt_prefix,
-		    transl ? describe_translation : describe_command,
-		    partial, sub_shadows, &seen, nomenu, mention_shadow);
+      describe_map (Fcdr (elt), elt_prefix, partial, transl,
+		    sub_shadows, nomenu, mention_shadow);
 
     skip: ;
     }
@@ -3112,9 +3107,8 @@ describe_map_compare (const void *aa, const void *bb)
 
 static void
 describe_map (Lisp_Object map, Lisp_Object prefix,
-	      void (*elt_describer) (Lisp_Object, Lisp_Object),
-	      bool partial, Lisp_Object shadow,
-	      Lisp_Object *seen, bool nomenu, bool mention_shadow)
+	      bool transl, bool partial, Lisp_Object shadow,
+	      bool nomenu, bool mention_shadow)
 {
   Lisp_Object tail, definition, event;
   Lisp_Object tem;
@@ -3122,6 +3116,12 @@ describe_map (Lisp_Object map, Lisp_Object prefix,
   Lisp_Object kludge;
   bool first = 1;
 
+  Lisp_Object seen_orig = Qnil;
+  Lisp_Object *seen = &seen_orig;
+
+  void (*elt_describer) (Lisp_Object, Lisp_Object) =
+    transl ? describe_translation : describe_command;
+
   /* These accumulate the values from sparse keymap bindings,
      so we can sort them and handle them in order.  */
   ptrdiff_t length_needed = 0;
-- 
2.11.0