From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dieter Wilhelm Newsgroups: gmane.emacs.devel Subject: Re: Suggestion for C-t (transpose-chars) Date: Fri, 27 Jul 2007 02:28:08 +0200 Organization: The Church of Emacs Message-ID: <874pjq4rmv.fsf@debby.local.net> References: <87lkdbl8az.fsf@debby.local.net> <871wf2lxb2.fsf@debby.local.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1185496055 4829 80.91.229.12 (27 Jul 2007 00:27:35 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 27 Jul 2007 00:27:35 +0000 (UTC) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jul 27 02:27:33 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IEDg0-0002Tl-Im for ged-emacs-devel@m.gmane.org; Fri, 27 Jul 2007 02:27:28 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IEDfz-0003ie-Rb for ged-emacs-devel@m.gmane.org; Thu, 26 Jul 2007 20:27:27 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IEDfx-0003iR-6y for emacs-devel@gnu.org; Thu, 26 Jul 2007 20:27:25 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IEDfv-0003iF-Lj for emacs-devel@gnu.org; Thu, 26 Jul 2007 20:27:23 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IEDfv-0003iC-GT for emacs-devel@gnu.org; Thu, 26 Jul 2007 20:27:23 -0400 Original-Received: from moutng.kundenserver.de ([212.227.126.179]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IEDfu-0004WE-Dh; Thu, 26 Jul 2007 20:27:22 -0400 Original-Received: from [89.12.113.244] (helo=debby.local.net) by mrelayeu.kundenserver.de (node=mrelayeu3) with ESMTP (Nemesis), id 0MKxQS-1IEDfs2BCr-0004ga; Fri, 27 Jul 2007 02:27:20 +0200 Original-Received: from dieter by debby.local.net with local (Exim 4.63) (envelope-from ) id 1IEDge-0005zA-3A; Fri, 27 Jul 2007 02:28:08 +0200 In-Reply-To: (Eli Zaretskii's message of "Fri\, 20 Jul 2007 23\:06\:36 +0300") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) X-Provags-ID: V01U2FsdGVkX19a6C/+LykL1nWn2GKe5DDowGbkMxNzs/A7pYv ROBS9MknKXo/x3g3+qlGsFww6x81XpF04TbV6dbpFTdBQbLmrk mi8oH1dX+8O4eibBN+sbgjCcVDnHnkt X-detected-kernel: Linux 2.6? (barebone, rare!) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:75609 Archived-At: Eli Zaretskii writes: > > I'd rather you posted it here, as diffs to the appropriate Emacs Lisp > file. Fine, here's my first idea. I'll test it a while and see whether it's really an improvement to the original defun (here called drag-chars). Could I marry the two behaviours into one function in checking for example whether the arguments are given with an C-u prefix or not? Dieter Index: simple.el =================================================================== --- simple.el (revision 6) +++ simple.el (working copy) @@ -3957,6 +3957,27 @@ (select-window orig-window)))) (defun transpose-chars (arg) + "Interchange characters around point. +With prefix arg ARG, effect is to interchange adjacent characters +ARG characters before point (ARG characters after point if ARG is +negative). If no argument and at end of line, the previous two +characters are exchanged." + (interactive "*P") + (when (and (null arg) (eolp)) + (setq arg 2)) + (let* ((p (point)) + (p1 (- p (prefix-numeric-value arg))) + (p2 (1+ p1))) + (when (< p1 (point-min)) + (error "Beginning of buffer or narrowed region")) + (when (> p2 (point-max)) + (error "End of buffer or narrowed region")) + (setq c (delete-and-extract-region p1 p2)) + (goto-char p2) + (insert c) + (goto-char p))) + +(defun drag-chars (arg) "Interchange characters around point, moving forward one character. With prefix arg ARG, effect is to take character before point and drag it forward past ARG other characters (backward if ARG negative). -- Best wishes H. Dieter Wilhelm Darmstadt, Germany