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

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

Re: Replacing huge hidden selection when pasting text


From: Pascal J. Bourguignon
Subject: Re: Replacing huge hidden selection when pasting text
Date: Thu, 24 Dec 2015 06:48:55 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Alexandre Oberlin <alxobr@gmail.com> 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


reply via email to

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