all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Replacing huge hidden selection when pasting text
Date: Thu, 24 Dec 2015 06:48:55 +0100	[thread overview]
Message-ID: <8760zoiego.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: 5da6a556-646f-42ba-9bae-f5bf4387f09e@googlegroups.com

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


  parent reply	other threads:[~2015-12-24  5:48 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-24  1:01 Replacing huge hidden selection when pasting text Alexandre Oberlin
2015-12-24  1:37 ` Drew Adams
2015-12-24 13:27   ` Alexandre Oberlin
2015-12-24 23:04     ` Stefan Monnier
2015-12-25  1:18     ` Pascal J. Bourguignon
     [not found]     ` <mailman.529.1451006347.843.help-gnu-emacs@gnu.org>
2016-01-02 21:40       ` Alexandre Oberlin
2016-01-02 22:03         ` Marcin Borkowski
     [not found]         ` <mailman.1550.1451772215.843.help-gnu-emacs@gnu.org>
2016-01-02 22:28           ` Alexandre Oberlin
2016-01-02 23:04             ` Drew Adams
     [not found]             ` <mailman.1551.1451775915.843.help-gnu-emacs@gnu.org>
2016-01-03  0:11               ` Alexandre Oberlin
2016-01-03  0:28                 ` Michael Heerdegen
     [not found]                 ` <mailman.1554.1451780942.843.help-gnu-emacs@gnu.org>
2016-01-03  0:41                   ` Alexandre Oberlin
2016-01-03  1:07                     ` Michael Heerdegen
2016-01-03  2:10                     ` Robert Thorpe
2016-01-03  2:11                 ` Drew Adams
2016-01-03  2:25                 ` Michael Heerdegen
2016-01-03  3:10                   ` Drew Adams
2016-01-03  3:21                     ` Drew Adams
2016-01-03  4:09                 ` Yuri Khan
2016-01-03  5:08                   ` Random832
     [not found]                   ` <mailman.1572.1451797753.843.help-gnu-emacs@gnu.org>
2016-01-13 17:13                     ` Alexandre Oberlin
2016-01-14 14:07                       ` Stefan Monnier
     [not found]                       ` <mailman.2334.1452780465.843.help-gnu-emacs@gnu.org>
2016-01-14 15:35                         ` Alexandre Oberlin
2016-01-14 16:11                           ` Kaushal Modi
2016-01-14 17:20                             ` Eli Zaretskii
2016-01-14 16:36                           ` Michael Heerdegen
2016-01-14 16:41                           ` Eli Zaretskii
     [not found]                           ` <mailman.2341.1452787916.843.help-gnu-emacs@gnu.org>
2016-01-14 16:45                             ` Alexandre Oberlin
2016-01-14 17:05                               ` Kaushal Modi
2016-01-14 19:37                           ` Stefan Monnier
     [not found]                           ` <mailman.2359.1452800411.843.help-gnu-emacs@gnu.org>
2016-01-14 23:41                             ` Alexandre Oberlin
     [not found]                 ` <mailman.1570.1451794187.843.help-gnu-emacs@gnu.org>
2016-01-13 16:42                   ` Alexandre Oberlin
2016-01-13 17:54                     ` Yuri Khan
     [not found]                     ` <mailman.2302.1452707668.843.help-gnu-emacs@gnu.org>
2016-01-14 13:57                       ` Alexandre Oberlin
     [not found]                 ` <mailman.1564.1451787927.843.help-gnu-emacs@gnu.org>
2016-01-13 17:26                   ` Alexandre Oberlin
     [not found]     ` <mailman.528.1450998293.843.help-gnu-emacs@gnu.org>
2016-01-14 14:00       ` Alexandre Oberlin
2016-01-14 15:02         ` Stefan Monnier
2015-12-24  5:48 ` Pascal J. Bourguignon [this message]
2015-12-24 14:40 ` Andreas Röhler
2015-12-27 22:15 ` Robert Thorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8760zoiego.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.