gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

wimpy-del.el - confirmation for large region deletion


From: Drew Adams
Subject: wimpy-del.el - confirmation for large region deletion
Date: Tue, 16 Jan 2001 21:35:20 -0500

;;; wimpy-del.el --- Require confirmation for large region deletion.
;; 
;; Filename: wimpy-del.el
;; Description: Require confirmation for large region deletion.
;; Author: Bard Bloom, address@hidden
;;      Drew Adams
;; Maintainer: Drew Adams
;; Copyright (C) 1996-2001, Drew Adams, all rights reserved.
;; Copyright (C) Bard Bloom, June 1989
;; Created: Wed Nov 22 14:57:17 1995
;; Version: $Id: wimpy-del.el,v 1.6 2001/01/09 22:40:29 dadams Exp $
;; Last-Updated: Tue Jan  9 14:39:40 2001
;;           By: dadams
;;     Update #: 131
;; Keywords: local
;; Compatibility: GNU Emacs 20.x
;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;;; Commentary:
;;
;;    Require confirmation for large region deletion.
;;  Replacements for `kill-region' and `clipboard-kill-region'.  
;;
;;  Original code by Bard Bloom, address@hidden
;;  Modifications by Drew Adams.
;;
;;  This provides `kill-region-wimpy', a replacement for
;;  `kill-region'.  If the region is larger than `wimpy-delete-size'
;;  characters, then `kill-region-wimpy' asks you if you really want
;;  to delete it.  The prompt tells you how big the region is, and
;;  indicates the region's text.  This can thus also be used as an
;;  alternative to `C-x C-x' to determine where the region is.
;;
;;  Similarly, `clipboard-kill-region-wimpy' is provided as a
;;  replacement for `clipboard-kill-region'.
;;
;;  New functions defined here:
;;
;;    `clipboard-kill-region-wimpy', `kill-region-wimpy'.
;;
;;  New user options (variables) defined here:
;;
;;    `wimpy-delete-dopey-message', `wimpy-delete-size'.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;;; Change log:
;; 
;; RCS $Log: wimpy-del.el,v $
;; RCS Revision 1.6  2001/01/09 22:40:29  dadams
;; RCS Adapted file header for Emacs Lisp Archive.
;; RCS
;; RCS Revision 1.5  2001/01/08 19:44:21  dadams
;; RCS *** empty log message ***
;; RCS
;; RCS Revision 1.4  2001/01/03 23:21:46  dadams
;; RCS *** empty log message ***
;; RCS
;; RCS Revision 1.3  2001/01/03 17:48:50  dadams
;; RCS *** empty log message ***
;; RCS
;; RCS Revision 1.2  2000/11/28 20:46:28  dadams
;; RCS Optional require's via 3rd arg=t now.
;; RCS
;; RCS Revision 1.1  2000/09/14 17:24:45  dadams
;; RCS Initial revision
;; RCS
; Revision 1.1  1997/03/19  11:05:36  dadams
; Initial revision
;
; Revision 1.9  1996/06/20  12:14:44  dadams
; (trivial)
;
; Revision 1.8  1996/06/06  15:08:23  dadams
; Update of file dependency comments (e.g. "Autoloaded from...").
;
; Revision 1.7  1996/03/08  14:40:23  dadams
; 1. Copyright.
; 2. drew-strings.el -> strings.el, drew-windows.el -> frame-fns.el
;
; Revision 1.6  1996/02/12  10:10:45  dadams
; Updated header keywords (for finder).
;
; Revision 1.5  1996/02/06  10:35:29  dadams
; (trivial) kill-region-wimpy: No message if wimpy-delete-dopey-message is nil.
;
; Revision 1.4  1995/12/28  15:47:07  dadams
; 1. Removed requires of drew-strings.el and drew-windows.el, since autoloaded.
; 2. Added ;;;###autoloads.
;
; Revision 1.3  1995/12/28  07:50:28  dadams
; kill-region-wimpy: Interactive allows for completion.el: Use inactive mark 
too.
;
; Revision 1.2  1995/12/05  13:00:47  dadams
; kill-region-wimpy: Take completion.el into account: Remove the most
; recent completion.
;
; Revision 1.1  1995/12/01  15:30:21  dadams
; Initial revision
;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;;; Code: 

(require 'cl) ;; when

(require 'frame-fns nil t) ;; (no error if not found): flash-ding
(require 'strings nil t) ;; (no error if not found): region-description


(provide 'wimpy-del)

;; Free vars here: CMPL-LAST-INSERT-LOCATION, CMPL-ORIGINAL-STRING,
;;                 COMPLETION-TO-ACCEPT

;;;;;;;;;;;;;;;;;

;;;###autoload
(defvar wimpy-delete-size 2000
   "*`kill-region-wimpy' asks you to confirm killing more than this many chars.
Setting this to nil inhibits deletion confirmation altogether.")

;;;###autoload
(defvar wimpy-delete-dopey-message "OK, region not killed."
  "*Message `kill-region-wimpy' displays when told not to delete the region.
If nil, no message is displayed.")

;; CMPL-LAST-INSERT-LOCATION, CMPL-ORIGINAL-STRING and COMPLETION-TO-ACCEPT
;; are free here.
;;;###autoload
(defun kill-region-wimpy (beg end)
  "Kill the text between BEG and END, putting it in the kill ring.
\(Interactively, uses the region.)

If the previous command was a completion, just remove the completion.

Else, if the region is > `wimpy-delete-size', you must confirm the kill."
  (interactive
   (if (and (eq last-command 'complete) ; See `completion.el'.
            (boundp 'cmpl-last-insert-location))
       (let ((mark-even-if-inactive t))
         (list (region-beginning) (region-end)))
     (list (region-beginning) (region-end))))
  (cond (;; Remove the most recent completion----See `completion.el'.
         (and (eq last-command 'complete) (boundp 'cmpl-last-insert-location))
         (delete-region (point) cmpl-last-insert-location)
         (insert cmpl-original-string)  ; Defined in `completion.el'.
         (setq completion-to-accept nil)) ; Defined in `completion.el'.
        ;; Only kill large region if user confirms.
        ((and wimpy-delete-size 
              (> (- end beg) wimpy-delete-size)
              (progn (when (fboundp 'flash-ding) (flash-ding))
                     (not (y-or-n-p
                           (if (fboundp 'region-description)
                               (region-description
                                (- (frame-width) 6)
                                "Really kill?:     " "    " beg end)
                             (message "Really kill region (%d chars)? "
                                      (- end beg)))))))
         (when (and (interactive-p) wimpy-delete-dopey-message)
           (message "%s" wimpy-delete-dopey-message)))
        (t (kill-region beg end))))     ; Kill small region.

;;; Identical to `clipboard-kill-region', defined in `menu-bar.el', 
;;; except that it uses `kill-region-wimpy' instead of `kill-region'.
;;;###autoload
(defun clipboard-kill-region-wimpy (beg end)
  "Kill the region, and save it in the X clipboard.
\(Interactively, uses the region.)

If the previous command was a completion, just remove the completion.

Else, if the region is > `wimpy-delete-size', you must confirm the kill."
  (interactive "r")
  (let ((x-select-enable-clipboard t))
    (kill-region-wimpy beg end)))

;;; For use in menu-bar.
(put 'clipboard-kill-region-wimpy 'menu-enable 'mark-active)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; `wimpy-del.el' ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]