From xemacs-m  Thu Jul 10 01:10:07 1997
Received: from jagor.srce.hr (hniksic@jagor.srce.hr [161.53.2.130])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id BAA26425
	for <xemacs-beta@xemacs.org>; Thu, 10 Jul 1997 01:10:06 -0500 (CDT)
Received: (from hniksic@localhost)
	by jagor.srce.hr (8.8.6/8.8.6) id IAA01767;
	Thu, 10 Jul 1997 08:10:05 +0200 (MET DST)
To: XEmacs Developers <xemacs-beta@xemacs.org>
Subject: [PATCH] pending-del changes
X-Attribution: Hrv
X-Face: Mie8:rOV<\c/~z{s.X4A{!?vY7{drJ([U]0O=W/<W*SMo/Mv:58:*_y~ki>xDi&N7XG
        KV^$k0m3Oe/)'e%3=$PCR&3ITUXH,cK>]bci&<qQ>Ff%x_>1`T(+M2Gg/fgndU%k*ft
        [(7._6e0n-V%|%'[c|q:;}td$#INd+;?!-V=c8Pqf}3J
From: Hrvoje Niksic <hniksic@srce.hr>
Date: 10 Jul 1997 08:10:05 +0200
Message-ID: <kig20574ev6.fsf@jagor.srce.hr>
Lines: 277
X-Mailer: Gnus v5.4.59/XEmacs 20.3(beta12) - "Helsinki"

I have made pending-delete a minor mode, which is IMHO much more
logical, because it now adheres to the standard minor-mode toggling
semantics.  BTW, if you can think of a good modeline identification,
tell me.  The "P-Del" looks kinda ugly, but I couldn't think of
anything better.

Also, I made the toolbar-paste button work as expected (as per reports
on c.e.x.).  Several functions have been simplified to be marginally
more efficient.

The NEWS file is updated for this.  The update also includes the
zmacs-regions part, since Ben blessed my approach.


1997-07-10  Hrvoje Niksic  <hniksic@srce.hr>

	* packages/pending-del.el (pending-delete-pre-hook): Don't quote
 	lambda.
	(pending-delete-pre-hook): Use `error-message-string'.
	(pending-delete): Treat as minor mode; define the standard turn-on 
	and turn-off functions.
	(delete-active-region): Simplified.

	* packages/pending-del.el: Don't turn on by default.

--- lisp/packages/pending-del.el.orig	Thu Jul 10 03:47:38 1997
+++ lisp/packages/pending-del.el	Thu Jul 10 07:27:38 1997
@@ -3,6 +3,8 @@
 ;; Copyright (C) 1992, 1994 Free Software Foundation, Inc.
 
 ;; Author: Matthieu Devin <devin@lucid.com>, 14 Jul 92.
+;; Maintainer: Hrvoje Niksic <hniksic@srce.hr>
+;; Version 2.0
 
 ;; This file is part of XEmacs.
 
@@ -23,49 +25,58 @@
 
 ;;; Synched up with: Not in FSF.
 
+;;; Commentary:
+
+;; Much of this code was revamped by Hrvoje Niksic, July 1997, with
+;; version number set to 2.x.
+
+;; Pending-del is now a major mode, with all the normal toggle
+;; functions.  It should be somewhat faster, too.
+
+
 ;;; Code:
 
-(defvar pending-delete-verbose
-  1
-  "*nil disables on/off messages for pending-del mode
-1 suppresses messages on loading
-t enables all messages")
-
-(defun delete-active-region (&optional killp)
-  (if (and (not buffer-read-only)
-	   (extentp zmacs-region-extent)
-	   (eq (current-buffer) (extent-buffer zmacs-region-extent))
-	   (extent-start-position zmacs-region-extent)
-	   (<= (extent-start-position zmacs-region-extent) (point))
-	   (<= (point) (extent-end-position zmacs-region-extent)))
-      (progn
-	(if killp
-	    (kill-region (extent-start-position zmacs-region-extent)
-			 (extent-end-position zmacs-region-extent))
-	  (delete-region (extent-start-position zmacs-region-extent)
-			 (extent-end-position zmacs-region-extent)))
-	(zmacs-deactivate-region)
-	t)))
+(defvar pending-delete nil
+  "Non-nil when pending-delete is activated.")
+
+(add-minor-mode 'pending-delete " P-Del")
+
+
+(defun pending-delete-active-region (&optional killp)
+  (when (and (region-active-p)
+	     (eq (extent-object zmacs-region-extent) (current-buffer))
+	     (not buffer-read-only))
+    ;; Here we used to check whether the point lies between the
+    ;; beginning and end of the extent.  I don't see how it is
+    ;; necessary, as the C code makes sure that this is so; it only
+    ;; slow things down.
+    (if killp
+	(kill-region (region-beginning) (region-end))
+      (delete-region (region-beginning) (region-end)))
+    (zmacs-deactivate-region)
+    t))
 
 (defun pending-delete-pre-hook ()
-  ;; don't ever signal an error in pre-command-hook!
   (condition-case e
       (let ((type (and (symbolp this-command)
 		       (get this-command 'pending-delete))))
 	(cond ((eq type 'kill)
-	       (delete-active-region t))
+	       (pending-delete-active-region t))
 	      ((eq type 'supersede)
-	       (if (delete-active-region ())
-		   (setq this-command '(lambda () (interactive)))))
+	       (if (pending-delete-active-region ())
+		   (setq this-command (lambda () (interactive)))))
 	      (type
-	       (delete-active-region ()))))
+	       (pending-delete-active-region ()))))
     (error
-     (warn "Error caught in `pending-delete-pre-hook': %s" e))))
+     (warn "Error caught in `pending-delete-pre-hook': %s"
+	   (error-message-string e)))))
 
+
 (put 'self-insert-command 'pending-delete t)
 
 (put 'yank 'pending-delete t)
 (put 'x-yank-clipboard-selection 'pending-delete t)
+(put 'toolbar-paste 'pending-delete t)
 
 (put 'delete-backward-char 'pending-delete 'supersede)
 (put 'backward-delete-char-untabify 'pending-delete 'supersede)
@@ -86,46 +97,48 @@
 
 (put 'insert-register 'pending-delete t)
 
+
 ;;;###autoload
-(defun pending-delete-on (verbose)
-  "Turn on pending delete.
-When it is ON, typed text replaces the selection if the selection is active.
-When it is OFF, typed text is just inserted at point."
-  (interactive "P")
-  (add-hook 'pre-command-hook 'pending-delete-pre-hook)
-  (and verbose
-    (message "Pending delete is ON, use M-x pending-delete to turn it OFF")))
+(defun turn-on-pending-delete (&optional ignored)
+  "Turn on pending delete minor mode unconditionally."
+  (interactive)
+  (pending-delete 1))
 
 ;;;###autoload
-(defun pending-delete-off (verbose)
-  "Turn off pending delete.
-When it is ON, typed text replaces the selection if the selection is active.
-When it is OFF, typed text is just inserted at point."
-  (interactive "P")
-  (remove-hook 'pre-command-hook 'pending-delete-pre-hook)
-  (and verbose (message "pending delete is OFF")))
+(defun turn-off-pending-delete (&optional ignored)
+  "Turn off pending delete minor mode unconditionally."
+  (interactive)
+  (pending-delete 0))
+
+;; Provide old functions, for compatibility.
+
+;;;###autoload
+(define-obsolete-function-alias 'pending-delete-on 'turn-on-pending-delete)
+;;;###autoload
+(define-obsolete-function-alias 'pending-delete-off 'turn-off-pending-delete)
 
 ;;;###autoload
 (defun pending-delete (&optional arg)
-  "Toggle automatic deletion of the selected region.
+  "Toggle pending delete minor mode.
+When the pending delete is on, typed text replaces the selection (if any).
 With a positive argument, turns it on.
-With a non-positive argument, turns it off.
-When active, typed text replaces the selection."
+With a non-positive argument, turns it off."
   (interactive "P")
-  (let* ((was-on (not (not (memq 'pending-delete-pre-hook pre-command-hook))))
-	 (on-p (if (null arg)
-		   (not was-on)
-		(> (prefix-numeric-value arg) 0))))
-    (cond ((eq on-p was-on)
-	   nil)
-	  (on-p
-	   (pending-delete-on pending-delete-verbose))
-	  (t
-	   (pending-delete-off pending-delete-verbose)))))
-  
-;; Add pending-del mode.  Assume that if we load it then we obviously wanted
-;; it on, even if it is already on.
-(pending-delete-on (eq pending-delete-verbose t))
+  (setq pending-delete
+	(if (null arg)
+	    (not pending-delete)
+	  (> (prefix-numeric-value arg) 0)))
+  (if pending-delete
+      (add-hook 'pre-command-hook 'pending-delete-pre-hook)
+    (remove-hook 'pre-command-hook 'pending-delete-pre-hook)))
+
+
+;; The following code used to turn the mode on unconditionally.
+;; However, this is a very bad idea -- since pending-del is
+;; autoloaded, (turn-on-pending-delete) is as easy to add to `.emacs'
+;; as (require 'pending-del) used to be.
+
+;(pending-delete-on (eq pending-delete-verbose t))
 
 (provide 'pending-del)
 
--- lisp/x11/x-toolbar.el.orig	Thu Jul 10 07:54:33 1997
+++ lisp/x11/x-toolbar.el	Thu Jul 10 07:55:07 1997
@@ -25,6 +25,9 @@
 ;; order to get different behaviour.
 ;;
 
+(eval-when-compile
+  (require 'pending-del))
+
 (defgroup toolbar nil
   "Configure XEmacs Toolbar functions and properties"
   :group 'environment)
@@ -97,6 +100,11 @@
 
 (defun toolbar-paste ()
   (interactive)
+  ;; This horrible kludge is for pending-delete to work correctly.
+  (and (boundp 'pending-delete)
+       pending-delete
+       (let ((this-command toolbar-paste-function))
+	 (pending-delete-pre-hook)))
   (call-interactively toolbar-paste-function))
 
 (defcustom toolbar-undo-function 'undo
--- etc/NEWS.orig	Thu Jul 10 07:57:28 1997
+++ etc/NEWS	Thu Jul 10 08:08:33 1997
@@ -138,20 +138,29 @@
 creating a new frame with `C-x 5 2' also raises and selects that
 frame.  The behavior of window system frames is unchanged.
 
-** Zmacs region is selectively deactivated when an error is signaled.
+** Zmacs region is not deactivated when an error is signaled.
 
-The behavior of the zmacs region can now be controlled in the event of a
-signaled error.  The new variable `errors-deactivate-region' may be set
-to nil to avoid losing the zmacs region.  When this is in effect, to
-deactivate the region, you have to press C-g explicitly, in the buffer
-where the region is active.  This can be a win under many circumstances,
-but can lead to potentially confusing situations when isearch is in effect.
+The behavior of the zmacs region can now be controlled in the event of
+a signaled error.  The new variable `errors-deactivate-region' may be
+set to nil to revert to the old behaviour.  As before, typing C-g
+deactivate the region.
 
-To control just keeping the region when moving against the endpoints of a
-buffer, the existing variable `signal-error-on-buffer-boundary' can be set
-to nil.
+** Pending-delete changes.
 
-NOTE:  This feature is enabled by default in 20.3beta.
+*** Pending-delete is now a minor mode, with the normal minor-mode
+semantics and toggle functions.  Old functions are left for
+compatibility.
+
+*** Loading pending-del no longer turns on pending-delete mode.  In
+fact, it is no longer necessary to explicitly load pending-del.  All
+you need to do to turn on tpu-edt is run the tpu-edt function.  Here's
+how to run pending-delete instead of loading the file:
+
+  Within XEmacs:   Type      M-x pending-delete <ret>
+                    not      M-x load-library <ret> pending-delete <ret>
+  
+  In .emacs:       Use       (turn-on-pending-delete)
+                   not       (load "pending-del")
 
 ** Abbreviations can now contain non-word characters.
 



-- 
Hrvoje Niksic <hniksic@srce.hr> | Student at FER Zagreb, Croatia
--------------------------------+--------------------------------
main(){printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-0x60);}

