changeset 79169:c6da63ecc892

(tpu-edt-old-global-values): New var. (tpu-edt-off): Use it. (tpu-edt-on): Set it. Make sure the tpu-global-map is not already on the global-map before adding it to global-map.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 22 Oct 2007 04:42:10 +0000
parents a14b49f75b09
children dc61ca9d9d55
files lisp/ChangeLog lisp/emulation/tpu-edt.el
diffstat 2 files changed, 19 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Mon Oct 22 04:26:47 2007 +0000
+++ b/lisp/ChangeLog	Mon Oct 22 04:42:10 2007 +0000
@@ -1,5 +1,10 @@
 2007-10-22  Stefan Monnier  <monnier@iro.umontreal.ca>
 
+	* emulation/tpu-edt.el (tpu-edt-old-global-values): New var.
+	(tpu-edt-off): Use it.
+	(tpu-edt-on): Set it.  Make sure the tpu-global-map is not already on
+	the global-map before adding it to global-map.
+
 	* menu-bar.el (global-buffers-menu-map): New var.
 	(global-map, menu-bar-update-buffers): Use it.
 	* msb.el (msb-menu-bar-update-buffers): Use it.
--- a/lisp/emulation/tpu-edt.el	Mon Oct 22 04:26:47 2007 +0000
+++ b/lisp/emulation/tpu-edt.el	Mon Oct 22 04:42:10 2007 +0000
@@ -273,6 +273,7 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'cl))
 ;; we use picture-mode functions
 (require 'picture)
 
@@ -2435,6 +2436,7 @@
 	   (tpu-error (message "Sorry, couldn't copy - %s." (cdr conditions)))))
     (kill-buffer "*TPU-Notice*")))
 
+(defvar tpu-edt-old-global-values nil)
 
 ;;;
 ;;;  Start and Stop TPU-edt
@@ -2443,6 +2445,8 @@
 (defun tpu-edt-on ()
   "Turn on TPU/edt emulation."
   (interactive)
+  ;; To clean things up (and avoid cycles in the global map).
+  (tpu-edt-off)
   ;; First, activate tpu-global-map, while protecting the original keymap.
   (set-keymap-parent tpu-global-map global-map)
   (setq global-map tpu-global-map)
@@ -2453,9 +2457,12 @@
   (tpu-set-mode-line t)
   (tpu-advance-direction)
   ;; set page delimiter, display line truncation, and scrolling like TPU
-  (setq-default page-delimiter "\f")
-  (setq-default truncate-lines t)
-  (setq scroll-step 1)
+  (dolist (varval '((page-delimiter . "\f")
+                    (truncate-lines . t)
+                    (scroll-step . 1)))
+    (push (cons (car varval) (default-value (car varval)))
+          tpu-edt-old-global-values)
+    (set-default (car varval) (cdr varval)))
   (tpu-set-control-keys)
   (and window-system (tpu-load-xkeys nil))
   (tpu-arrow-history)
@@ -2472,9 +2479,9 @@
   (tpu-reset-control-keys nil)
   (remove-hook 'post-command-hook 'tpu-search-highlight)
   (tpu-set-mode-line nil)
-  (setq-default page-delimiter "^\f")
-  (setq-default truncate-lines nil)
-  (setq scroll-step 0)
+  (while tpu-edt-old-global-values
+    (let ((varval (pop tpu-edt-old-global-values)))
+      (set-default (car varval) (cdr varval))))
   ;; Remove tpu-global-map from the global map.
   (let ((map global-map))
     (while map
@@ -2482,7 +2489,7 @@
         (if (eq tpu-global-map parent)
             (set-keymap-parent map (keymap-parent parent))
           (setq map parent)))))
-  (ad-disable-regexp "\\`tpu-")
+  (ignore-errors (ad-disable-regexp "\\`tpu-"))
   (setq tpu-edt-mode nil))
 
 (provide 'tpu-edt)