Subject: bug#58376: [PATCH] Set the PARENTS argument for language environments

From: Visuwesh <[email-masked]>
Date: Sun, 09 Oct 2022 20:20:36 +0530

[ஞாயிறு அக்டோபர் 09, 2022] Eli Zaretskii wrote:

>> If I do something like:
>> 
>> (set-language-info-alist
>>  "Kharoshthi" '((charset unicode)
>>        (coding-system utf-8)
>>        (coding-priority utf-8)
>>        (input-method . "kharoshthi")
>>                 (sample-text . "Kharoṣṭhī (𐨑𐨪𐨆𐨛𐨁) 𐨣𐨨𐨲𐨪𐨆 𐨐𐨪𐨅𐨨𐨁")
>>        (documentation . "\
>> Language environment for Gāndhārī, Sanskrit, and other languages
>> using the Kharoṣṭhī script."))
>>  '("Misc" "Indian"))
>> 
>> Then compile and open emacs -Q
>> Now opening Options>Multilingual Environment>Set Language Environment>Indian
>> It only has the Kharoshthi entry
>> Options>Multilingual Environment>Set Language Environment>Misc now also has an Indian submenu with
>> only Kharoshthi entry.
>
> Hmm...  Either we don't understand what PARENTS mean (could it mean a
> hierarchy of several menu levels?), or there is a bug.
>
> If you want to work on that, please do; otherwise I'll just install
> your original patch.

Attached patch puts the "Kharosthi" item in both Indian and Misc
submenus without overwriting.

diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el
index 48e5c9aa1f..f39a4da439 100644
--- a/lisp/international/mule-cmds.el
+++ b/lisp/international/mule-cmds.el
@@ -1208,6 +1208,16 @@ set-language-info-internal
 			  (list 'const lang))
 			(sort (mapcar 'car language-info-alist) 'string<))))))

+(defun set-language-info-setup-keymap (lang-env alist describe-map setup-map)
+  "Setup menu items for LANG-ENV.
+See `set-language-info-alist' for details of other arguments."
+  (let ((doc (assq 'documentation alist)))
+    (when doc
+      (define-key-after describe-map (vector (intern lang-env))
+	(cons lang-env 'describe-specified-language-support))))
+  (define-key-after setup-map (vector (intern lang-env))
+    (cons lang-env 'setup-specified-language-environment)))
+
 (defun set-language-info-alist (lang-env alist &optional parents)
   "Store ALIST as the definition of language environment LANG-ENV.
 ALIST is an alist of KEY and INFO values.  See the documentation of
@@ -1252,16 +1262,11 @@ set-language-info-alist
 		  (define-key-after setup-map (vector parent-symbol)
 		    (cons parent map))))
 	    (setq setup-map (symbol-value map))
-	    (setq l (cdr l)))))
-
-    ;; Set up menu items for this language env.
-    (let ((doc (assq 'documentation alist)))
-      (when doc
-	(define-key-after describe-map (vector (intern lang-env))
-	  (cons lang-env 'describe-specified-language-support))))
-    (define-key-after setup-map (vector (intern lang-env))
-      (cons lang-env 'setup-specified-language-environment))
-
+	    (setq l (cdr l))
+            (set-language-info-setup-keymap lang-env alist describe-map setup-map)
+            (setq describe-map describe-language-environment-map)
+            (setq setup-map setup-language-environment-map)))
+      (set-language-info-setup-keymap lang-env alist describe-map setup-map))
     (dolist (elt alist)
       (set-language-info-internal lang-env (car elt) (cdr elt)))

The problem is that when looping, the variables setup-map and
describe-map gets outdated and causes the overwrite.  The solution I
came up with was to update them both to their default after each
iteration.  This involved moving the keymap-setting forms to a separate
function.