all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: Simple copy & paste problem
Date: Wed, 11 Aug 2010 19:43:20 +0200	[thread overview]
Message-ID: <87fwyl9haf.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: mailman.4.1281546350.9082.help-gnu-emacs@gnu.org

Andrea Crotti <andrea.crotti.0@gmail.com> writes:

> This is probably very stupid but every time I step into it and it's very
> annoying.
>
> Supposing I want to copy something from Safari to emacs.
> So I
> - select and copy
> - select and kill the text I want to substitute
> - try to paste
>
> ARGH! Now the text I copied from safari is disappeared...


> A workardound is to delete first and then copy-paste.

or:

- select and copy
- yank (it's called yank in emacs, not paste).
- select and kill the text you wanted to substitute


> But is there a smarter way to solve this?
> Something like
> "if I copied something from the os keep it as first in the kill ring"?

Use delete-region-and-yank instead of yank:

(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.
  (message "arg=%S" arg)
  (cond
    (mark-active                        ; delete region
     (let ((str (buffer-substring (point) (mark))))
       (delete-region (point) (mark))
       (if (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))))


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/


       reply	other threads:[~2010-08-11 17:43 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.4.1281546350.9082.help-gnu-emacs@gnu.org>
2010-08-11 17:43 ` Pascal J. Bourguignon [this message]
2010-09-05  1:44   ` Simple copy & paste problem David Combs
2010-09-05  1:55     ` Pascal J. Bourguignon
2010-08-11 18:11 ` notbob
2010-08-11 16:51 Andrea Crotti
2010-08-11 17:51 ` Drew Adams
2010-08-11 18:10   ` Andrea Crotti
2010-08-11 19:05 ` Glauber Alex Dias Prado
2010-08-11 19:15 ` Joel James Adamson
2010-08-11 20:06   ` Thierry Volpiatto
2010-08-11 22:44     ` Andrea Crotti
2010-08-12 17:25     ` Joel James Adamson
2010-08-12 18:14       ` Thierry Volpiatto
     [not found]   ` <mailman.4.1281557372.27891.help-gnu-emacs@gnu.org>
2010-09-05  1:59     ` David Combs
2010-08-12  5:42 ` Jonathan Groll
2010-08-13  2:35 ` Kevin Rodgers
2010-08-25 13:47 ` Leo
     [not found] ` <mailman.0.1281553020.25709.help-gnu-emacs@gnu.org>
2010-09-05  1:48   ` David Combs
2010-09-29 21:20     ` David Combs
     [not found] ` <mailman.4.1282744218.27059.help-gnu-emacs@gnu.org>
2010-09-05  2:02   ` David Combs

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=87fwyl9haf.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.