[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Simple copy & paste problem
From: |
David Combs |
Subject: |
Re: Simple copy & paste problem |
Date: |
Wed, 08 Dec 2010 15:27:32 -0000 |
In article <87fwyl9haf.fsf@kuiper.lan.informatimago.com>,
Pascal J. Bourguignon <pjb@informatimago.com> wrote:
>
>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/
That function, delete-region-and-yank, is not part
of standard emacs -- its yours, you wrote it.
What, writing code is so easy that it flies off
your fingers as fast as you can type?
No, of course not. So, pjb, what do you have,
a whole library of these useful tools that you wrote?
With a little annotation of why you wrote function x,
and how it works, you'd have something you could,
if you felt super generous, provide it to everyone,
the library.
(For all I know, you already have!)
(With sufficient annotation (commenting), it'd be good
for additional examples of using elisp).
Thanks!
David