home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / packages / pending-del.el < prev    next >
Encoding:
Text File  |  1995-04-28  |  4.0 KB  |  120 lines

  1. ;; pending-del.el --- Making insertions replace any selected text.
  2.  
  3. ;; Copyright (C) 1992, 1994 Free Software Foundation, Inc.
  4.  
  5. ;; Author: Matthieu Devin <devin@lucid.com>, 14 Jul 92.
  6.  
  7. ;; This file is part of XEmacs.
  8.  
  9. ;; XEmacs is free software; you can redistribute it and/or modify it
  10. ;; under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation; either version 2, or (at your option)
  12. ;; any later version.
  13.  
  14. ;; XEmacs is distributed in the hope that it will be useful, but
  15. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. ;; General Public License for more details.
  18.  
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  21. ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. ;;; Code:
  24.  
  25. (defvar pending-delete-verbose
  26.   1
  27.   "*nil disables on/off messages for pending-del mode
  28. 1 suppresses messages on loading
  29. t enables all messages")
  30.  
  31. (defun delete-active-region (&optional killp)
  32.   (if (and (not buffer-read-only)
  33.        (extentp zmacs-region-extent)
  34.        (eq (current-buffer) (extent-buffer zmacs-region-extent))
  35.        (extent-start-position zmacs-region-extent)
  36.        (<= (extent-start-position zmacs-region-extent) (point))
  37.        (<= (point) (extent-end-position zmacs-region-extent)))
  38.       (progn
  39.     (if killp
  40.         (kill-region (extent-start-position zmacs-region-extent)
  41.              (extent-end-position zmacs-region-extent))
  42.       (delete-region (extent-start-position zmacs-region-extent)
  43.              (extent-end-position zmacs-region-extent)))
  44.     (zmacs-deactivate-region)
  45.     t)))
  46.  
  47. (defun pending-delete-pre-hook ()
  48.   (let ((type (and (symbolp this-command)
  49.            (get this-command 'pending-delete))))
  50.     (cond ((eq type 'kill)
  51.        (delete-active-region t))
  52.       ((eq type 'supersede)
  53.        (if (delete-active-region ())
  54.            (setq this-command '(lambda () (interactive)))))
  55.       (type
  56.        (delete-active-region ())))))
  57.  
  58. (put 'self-insert-command 'pending-delete t)
  59.  
  60. (put 'yank 'pending-delete t)
  61. (put 'x-yank-clipboard-selection 'pending-delete t)
  62.  
  63. (put 'delete-backward-char 'pending-delete 'supersede)
  64. (put 'backward-delete-char-untabify 'pending-delete 'supersede)
  65. (put 'delete-char 'pending-delete 'supersede)
  66. (put 'c-electric-delete 'pending-delete 'supersede)
  67.  
  68. ;; Don't delete for these.  They're more problematic than helpful.
  69. ;;
  70. ;; (put 'newline-and-indent 'pending-delete t)
  71. ;; (put 'newline 'pending-delete t)
  72. ;; (put 'open-line 'pending-delete t)
  73.  
  74. (put 'insert-register 'pending-delete t)
  75.  
  76. ;;;###autoload
  77. (defun pending-delete-on (verbose)
  78.   "Turn on pending delete.
  79. When it is ON, typed text replaces the selection if the selection is active.
  80. When it is OFF, typed text is just inserted at point."
  81.   (interactive "P")
  82.   (add-hook 'pre-command-hook 'pending-delete-pre-hook)
  83.   (and verbose
  84.     (message "Pending delete is ON, use M-x pending-delete to turn it OFF")))
  85.  
  86. ;;;###autoload
  87. (defun pending-delete-off (verbose)
  88.   "Turn off pending delete.
  89. When it is ON, typed text replaces the selection if the selection is active.
  90. When it is OFF, typed text is just inserted at point."
  91.   (interactive "P")
  92.   (remove-hook 'pre-command-hook 'pending-delete-pre-hook)
  93.   (and verbose (message "pending delete is OFF")))
  94.  
  95. ;;;###autoload
  96. (defun pending-delete (&optional arg)
  97.   "Toggle automatic deletion of the selected region.
  98. With a positive argument, turns it on.
  99. With a non-positive argument, turns it off.
  100. When active, typed text replaces the selection."
  101.   (interactive "P")
  102.   (let* ((was-on (not (not (memq 'pending-delete-pre-hook pre-command-hook))))
  103.      (on-p (if (null arg)
  104.            (not was-on)
  105.         (> (prefix-numeric-value arg) 0))))
  106.     (cond ((eq on-p was-on)
  107.        nil)
  108.       (on-p
  109.        (pending-delete-on pending-delete-verbose))
  110.       (t
  111.        (pending-delete-off pending-delete-verbose)))))
  112.   
  113. ;; Add pending-del mode.  Assume that if we load it then we obviously wanted
  114. ;; it on, even if it is already on.
  115. (pending-delete-on (eq pending-delete-verbose t))
  116.  
  117. (provide 'pending-del)
  118.  
  119. ;;; pending-del.el ends here
  120.