From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: Transposing words over middle words Date: Wed, 22 Nov 2017 16:33:09 -0500 Message-ID: References: <871skywvp4.fsf@hornfels.zedat.fu-berlin.de> <83o9o2i4xz.fsf@gnu.org> <20171116152231522684703@bob.proulx.com> <23054.41962.848150.764633@mail.eng.it> <23054.42180.139282.82688@mail.eng.it> <873757zgwp.fsf@fliptop> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1511386453 12442 195.159.176.226 (22 Nov 2017 21:34:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 22 Nov 2017 21:34:13 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Nov 22 22:34:10 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHcej-0002j9-FB for geh-help-gnu-emacs@m.gmane.org; Wed, 22 Nov 2017 22:34:05 +0100 Original-Received: from localhost ([::1]:41409 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHceq-0007kL-P1 for geh-help-gnu-emacs@m.gmane.org; Wed, 22 Nov 2017 16:34:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44572) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHceA-0007j3-CO for help-gnu-emacs@gnu.org; Wed, 22 Nov 2017 16:33:31 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eHce7-0007wL-9t for help-gnu-emacs@gnu.org; Wed, 22 Nov 2017 16:33:30 -0500 Original-Received: from [195.159.176.226] (port=34243 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eHce7-0007vg-3T for help-gnu-emacs@gnu.org; Wed, 22 Nov 2017 16:33:27 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1eHcdp-0007gb-NY for help-gnu-emacs@gnu.org; Wed, 22 Nov 2017 22:33:09 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 33 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:+s3fiYOCXIHKIHJVN51S+gZe/cU= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:115059 Archived-At: >> Than again, maybe M-t should work like `C-0 M-t` whenever the region >> is active so you don't even need the C-u at all. > Here is an advice to make that happen, respecting possible prefixes. > (defun tn-transpose-dwim-advice (transpose-subr &rest args) > (if (and (use-region-p) (= (cadr args) 1)) > ;; MOVER dwim SPECIAL > (apply transpose-subr (car args) 0 (cddr args)) > (apply transpose-subr args))) > (advice-add 'transpose-subr :around #'tn-transpose-dwim-advice) Indeed, thanks. The equivalent direct patch to the source code is below, Stefan diff --git a/lisp/simple.el b/lisp/simple.el index 84fedbc537..4eaeaf15f6 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -7173,7 +7173,7 @@ transpose-subr (progn (funcall mover (- x)) (point)))))) pos1 pos2) (cond - ((= arg 0) + ((or (= arg 0) (and (= arg 1) (use-region-p))) (save-excursion (setq pos1 (funcall aux 1)) (goto-char (or (mark) (error "No mark set in this buffer")))