[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Simple copy & paste problem
From: |
Pascal J. Bourguignon |
Subject: |
Re: Simple copy & paste problem |
Date: |
Wed, 08 Dec 2010 15:27:33 -0000 |
User-agent: |
Gnus/5.101 (Gnus v5.10.10) Emacs/23.2 (gnu/linux) |
dkcombs@panix.com (David Combs) writes:
> 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?
Exactly.
> No, of course not.
Yes, indeed.
> So, pjb, what do you have,
> a whole library of these useful tools that you wrote?
Of course, I don't like to do twice the same thing.
> 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.
I have, and I do.
> (For all I know, you already have!)
Indeed.
> (With sufficient annotation (commenting), it'd be good
> for additional examples of using elisp).
Why don't you try to follow this little
link you can find in all my signatures: ---------------+
Why do you think we take the pain of |
putting such links in our signatures? |
V
--
__Pascal Bourguignon__ http://www.informatimago.com/