From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: dkcombs@panix.com (David Combs) Newsgroups: gmane.emacs.help Subject: Re: Simple copy & paste problem Date: Sun, 5 Sep 2010 01:44:25 +0000 (UTC) Organization: Public Access Networks Corp. Message-ID: References: <87fwyl9haf.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1291870675 14140 80.91.229.12 (9 Dec 2010 04:57:55 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 9 Dec 2010 04:57:55 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 09 05:57:51 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PQYZg-0004ZA-Ds for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 05:57:48 +0100 Original-Received: from localhost ([127.0.0.1]:33045 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQYZf-0001Af-Sf for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 23:57:48 -0500 Original-Path: usenet.stanford.edu!newsfeed.berkeley.edu!ucberkeley!newsfeed-00.mathworks.com!panix!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 61 Original-NNTP-Posting-Host: panix3.panix.com Original-X-Trace: reader1.panix.com 1283651065 25180 166.84.1.3 (5 Sep 2010 01:44:25 GMT) Original-X-Complaints-To: abuse@panix.com Original-NNTP-Posting-Date: Sun, 5 Sep 2010 01:44:25 +0000 (UTC) X-Newsreader: trn 4.0-test76 (Apr 2, 2001) Original-Xref: usenet.stanford.edu gnu.emacs.help:181146 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:76693 Archived-At: In article <87fwyl9haf.fsf@kuiper.lan.informatimago.com>, Pascal J. Bourguignon 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