From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: Simple copy & paste problem Date: Sun, 05 Sep 2010 03:55:52 +0200 Organization: Informatimago Message-ID: <87lj7hgdhz.fsf@kuiper.lan.informatimago.com> References: <87fwyl9haf.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1291870806 14796 80.91.229.12 (9 Dec 2010 05:00:06 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 9 Dec 2010 05:00:06 +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 06:00:02 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 1PQYbo-0005f0-Rg for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 06:00:01 +0100 Original-Received: from localhost ([127.0.0.1]:34782 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQYbo-00029m-DV for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 00:00:00 -0500 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 81 Original-X-Trace: individual.net NvskCAFmPCsorRcFXaairQwa6aOexAOR7a/j+6Tf3FSLiDqLIf Cancel-Lock: sha1:NGUyMmRiZmUyMzRkOTJkM2E3MWE0ZWZkNjVlOTAzNjU4YmMxYTNmMA== sha1:ridvcUntdHNSt1bv/dRql8iJGM4= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.101 (Gnus v5.10.10) Emacs/23.2 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:181148 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:76696 Archived-At: dkcombs@panix.com (David Combs) writes: > 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? 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/