changeset 6167:1ad8f8ccdc2b

(substitute-key-definition): Avoid infinite recursion.
author Karl Heuer <kwzh@gnu.org>
date Thu, 03 Mar 1994 16:27:06 +0000
parents 64fe0cc0138e
children 17abb6c60749
files lisp/subr.el
diffstat 1 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/subr.el	Thu Mar 03 15:59:31 1994 +0000
+++ b/lisp/subr.el	Thu Mar 03 16:27:06 1994 +0000
@@ -133,6 +133,9 @@
 ;      (copy-sequence keymap)
 ;      (copy-alist keymap)))
 
+(defvar key-substitution-in-progress nil
+ "Used internally by substitute-key-definition.")
+
 (defun substitute-key-definition (olddef newdef keymap &optional oldmap prefix)
   "Replace OLDDEF with NEWDEF for any keys in KEYMAP now defined as OLDDEF.
 In other words, OLDDEF is replaced with NEWDEF where ever it appears.
@@ -141,7 +144,9 @@
   (or prefix (setq prefix ""))
   (let* ((scan (or oldmap keymap))
 	 (vec1 (vector nil))
-	 (prefix1 (vconcat prefix vec1)))
+	 (prefix1 (vconcat prefix vec1))
+	 (key-substitution-in-progress
+	  (cons scan key-substitution-in-progress)))
     ;; Scan OLDMAP, finding each char or event-symbol that
     ;; has any definition, and act on it with hack-key.
     (while (consp scan)
@@ -163,7 +168,9 @@
 		(setq inner-def (symbol-function inner-def)))
 	      (if (eq defn olddef)
 		  (define-key keymap prefix1 (nconc (nreverse skipped) newdef))
-		(if (keymapp defn)
+		(if (and (keymapp defn)
+			 (not (memq inner-def
+				    key-substitution-in-progress)))
 		    (substitute-key-definition olddef newdef keymap
 					       inner-def
 					       prefix1)))))
@@ -189,7 +196,9 @@
 		    (if (eq defn olddef)
 			(define-key keymap prefix1
 			  (nconc (nreverse skipped) newdef))
-		      (if (keymapp defn)
+		      (if (and (keymapp defn)
+			       (not (memq inner-def
+					  key-substitution-in-progress)))
 			  (substitute-key-definition olddef newdef keymap
 						     inner-def
 						     prefix1)))))