Xref: utzoo comp.emacs:8976 gnu.emacs:3706 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!rutgers!aramis.rutgers.edu!paul.rutgers.edu!sparky.rutgers.edu!gaynor From: gaynor@sparky.rutgers.edu (Silver) Newsgroups: comp.emacs,gnu.emacs Subject: Re: little kill-region hack Message-ID: Date: 30 Aug 90 10:25:41 GMT References: <1990Aug29.022757.2855@athena.mit.edu> Distribution: comp Organization: Rutgers Univ., New Brunswick, N.J. Lines: 80 To summarize acevedo@james-tiptree-jr.mit.edu (Gabriel) article: > [The perhaps too-convenient binding of kill-region often causes grief. It is > not uncommon to inadvertantly kill a region which is too large for undo to > handle. Fortunately the auto-save mechanism can be used to recover in this > situation. What follows is a version of kill-region which performs an > aut-osave before killing regions which exceed undo's capabilities.] RTFIN. GNU Emacs's Info node on killing, Info -> Emacs -> Killing, explains that kill commands save their text (as opposed to delete commands, which do not). The variable in which they save it is kill-ring. Killed text is prepended to the front of this list, knocking off the rearmost (oldest) element if the length of kill-ring exceeds kill-ring-max. Standard access to these kills is provided by the yank and yank-pop functions. See their documentation. I feel that the auto-save mechanism is there more to protect you from yourself (your own intentional changes) and system mishaps than from typos. Although the kill-region-safe you proposed is correct enough, it tends to get in the way, no?, slowing down normal editing. I regularly shuffle large portions of text in large files, and the function you propose would keep me waiting with all the saving and beat on the system. And, as pointed out above, a standard and convenient method for recovering killed text already exists. What I find to be a much more serious problem is not the fact that kill-region can kill arbitrarily large portions of text, but that it does so very, very quietly. Misstriking C-e and C-s is probably the most common circumstance. However, the function is used too often and is too useful to cripple with a lot of bells and whistles and confirmations like (ding) (message "You have invoked kill-region.") (or (sit-for 1) (sleep-for 1)) (ding) (message "You have invoked KILL-REGION.") (or (sit-for 1) (sleep-for 1)) (ding) (message "You have invoked kill-region.") (or (sit-for 1) (sleep-for 1)) (ding) (message "You have invoked KILL-REGION.") (or (sit-for 1) (sleep-for 1)) (ding) (message "You have invoked kill-region.") (or (sit-for 1) (sleep-for 1)) (if (and (y-or-n-p "Kill region? ") (yes-or-no-p "Really kill region? ") (yes-please-or-no-thank-you-p "Doing so may expire the oldest kill. Continue? ") (yes-god-dammit-or-no-you-have-been-most-kind-p "About to kill region; confirm? ")) (kill-region begin end) (message "Better safe than sorry...")) Instead, I propose the following. Make kill-region print out the number of characters killed. This doesn't step on toes, but still lets you know that you've killed something, and even provides a little useful information. I think I've posted this before, but what the hell... Regards, [Ag] _______________________________________________________________________________ (fset 'old-kill-region (symbol-function 'kill-region)) (defvar kill-region-silently nil "If non-nil, kill-region silently kills text. Otherwise, kill-region pipes up with a brief message of the number of characters being killed.") (defun kill-region (begin end &optional obey) "kill-region: Kill between point and mark. The text is deleted but saved in the kill ring. The command C-y can retrieve it from there. \(If you want to kill and then yank immediately, use ESC w.\) When used interactively, the number of characters killed is displayed in a brief message if kill-region-silently is non-nil. This is the primitive for programs to kill text \(as opposed to deleting it\). Supply two arguments, character numbers indicating the stretch of text to be killed. Optional third argument, if non-nil, means obey kill-region-silently even if non-interactively called. Any command that calls this function is a \"kill command\". If the previous command was also a kill command, the text killed this time appends to the text killed last time to make one entry in the kill ring." (interactive "r") (and (or (interactive-p) obey) (not kill-region-silently) (if (eq 1 (- end begin)) (message "Killing %d character" (- end begin)) (message "Killing %d characters" (- end begin)))) (old-kill-region begin end))