From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: Replacing huge hidden selection when pasting text Date: Thu, 24 Dec 2015 06:48:55 +0100 Organization: Informatimago Message-ID: <8760zoiego.fsf@kuiper.lan.informatimago.com> References: <5da6a556-646f-42ba-9bae-f5bf4387f09e@googlegroups.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1450936234 31038 80.91.229.3 (24 Dec 2015 05:50:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 24 Dec 2015 05:50:34 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 24 06:50:23 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aByn8-00064E-BG for geh-help-gnu-emacs@m.gmane.org; Thu, 24 Dec 2015 06:50:22 +0100 Original-Received: from localhost ([::1]:59010 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aByn7-0006VR-Px for geh-help-gnu-emacs@m.gmane.org; Thu, 24 Dec 2015 00:50:21 -0500 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 53 Original-X-Trace: individual.net 7uPtQJYP2eeYzKTmPnIHGwFDVhSc7X3borp3T0DxHJW667bPTO Cancel-Lock: sha1:YTM4NTZkNDE1MGMzMmIwN2E3MzM1YzFkZDQ3M2JmOWIwOTFjMWZjMQ== sha1:Ru/7+vILPOcdtkuSQ5SvKx+9+K8= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:216168 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:108458 Archived-At: Alexandre Oberlin writes: > I have stopped hoping that the current maintainers of Emacs still have > an ounce of common sense. How on Earth can it be possible (and quite > easy) to allow replacing a huge hidden selection when pasting text > without any warning ? I have lost large amounts of data with this > incredibly stupid behavior. There isn't even a warning when saving a > file which has shrunk a lot, like there once was. How can I DEFINITELY > avoid overwriting an invisible selection in all versions of Emacs? This is not possible, with the default configuration of emacs. You must have explicitely asked for it, in your ~/.emacs file. To get this behavior, I had to put: (defun delete-region-and-yank (&optional arg) "Deletes region if mark is active and yanks the last kill. Always replaces the region with the yank, whether the region was selected via keyboard or mouse. Also works for normal yank even with ARGS (thus it can be mapped to \C-y)" (interactive "*P") ; raw, like yank. (cond (mark-active ; delete region (let ((str (buffer-substring (point) (mark)))) (delete-region (point) (mark)) (if (cl:string= str (current-kill 0 1)) (let ((str2 (current-kill 1 1))) (kill-new str2 t)))) (if arg (yank arg) (yank))) ;; else no region selected: ((consp arg) ; delete forward sexp (set-mark (point)) (forward-sexp 1) (delete-region-and-yank)) (arg (yank arg)) (t (yank)))) (global-set-key (kbd "C-y") 'delete-region-and-yank) in my ~/.emacs ! By default, C-y is bound to yank, which inserts the text from the kill ring at the end of the region. -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk