unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Transposing words over middle words
@ 2017-11-15 23:17 Bob Proulx
  2017-11-15 23:35 ` Eric Abrahamsen
                   ` (3 more replies)
  0 siblings, 4 replies; 69+ messages in thread
From: Bob Proulx @ 2017-11-15 23:17 UTC (permalink / raw)
  To: help-gnu-emacs

TL;DR: How can I transpose words jumping over middle words?

Of course we all know about C-t transpose-chars.  And there is the
corresponding M-t transpose-words too.  Here is the documentation.

       ‘M-t’ transposes the word before point with the word after point
    (‘transpose-words’).  It moves point forward over a word, dragging the
    word preceding or containing point forward as well.  The punctuation
    characters between the words do not move.  For example, ‘FOO, BAR’
    transposes into ‘BAR, FOO’ rather than ‘BAR FOO,’.

When modifying a list of comma separated s strings this works great.
But often I find myself wanting to transpose words in an "and"
structure.

  Jack and Jill went up the hill.

With the point on the space after Jack the easiest way I know to
transpose those words is to M-d to kill-word forward deleting the
"and" leaving.

  Jack and Jill went up the hill.
      ^ point is here: M-d
  Jack Jill went up the hill.

Then M-t to transpose those words:

  Jack Jill went up the hill.
      ^ point is here: M-t
  Jill Jack went up the hill.

Then restore the "and" which is somewhat inelegant

  Jill Jack went up the hill.
      ^ point is here: C-b C-y
  Jill and Jack went up the hill.

Obviously I can use other brute force make the change.

  Jack and Jill went up the hill.
           ^ point is here: M-d
  Jack and  went up the hill.
           ^ point is here: M-b M-b
  Jack and  went up the hill.
  ^ point is here: C-y M-d M-f
  Jill and  went up the hill.
          ^ point is here: C-f C-y
  Jill and Jack went up the hill.

That or something similar is usually what I do.  This is one of those
nuisance items I have always wished had a better way to accomplish but
just always worked through it by brute force.  But transpose-words has
always been taunting me that it almost does what I want with M-t but
doesn't work in this situation.

Is there a way to use M-t to transpose words skipping over middle
words like it does for punctuation?  Perhaps there isn't a better way.

Thanks,
Bob



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-15 23:17 Transposing words over middle words Bob Proulx
@ 2017-11-15 23:35 ` Eric Abrahamsen
  2017-11-16  6:03   ` Emanuel Berg
  2017-11-16  0:04 ` Emanuel Berg
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 69+ messages in thread
From: Eric Abrahamsen @ 2017-11-15 23:35 UTC (permalink / raw)
  To: help-gnu-emacs

Bob Proulx <bob@proulx.com> writes:

> TL;DR: How can I transpose words jumping over middle words?
>
> Of course we all know about C-t transpose-chars.  And there is the
> corresponding M-t transpose-words too.  Here is the documentation.
>
>        ‘M-t’ transposes the word before point with the word after point
>     (‘transpose-words’).  It moves point forward over a word, dragging the
>     word preceding or containing point forward as well.  The punctuation
>     characters between the words do not move.  For example, ‘FOO, BAR’
>     transposes into ‘BAR, FOO’ rather than ‘BAR FOO,’.
>
> When modifying a list of comma separated s strings this works great.
> But often I find myself wanting to transpose words in an "and"
> structure.

I use Emacs more for prose composition than I do for coding, and I've
often wanted this. Over the years I've written a bunch of small
functions for making it easier to write prose (slurping spaces before
punctuation after deleting a word, etc), but eventually have discarded
most of them in favor of just hitting a few extra keys. I could never
get the DWIM behavior DWIM-ish enough, and it was more of a headache
watching for and correcting the mis-fires than it was just banging more
keys.

Anyway, the function you want is pretty easy to write. As I recall, I
dropped it because I couldn't decide what to do about multiple
invocations. `transpose-words' is actually "drag word forward". What
should this function do if you call it multiple times in a row?

Eric




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-15 23:17 Transposing words over middle words Bob Proulx
  2017-11-15 23:35 ` Eric Abrahamsen
@ 2017-11-16  0:04 ` Emanuel Berg
  2017-11-18 17:07   ` ken
  2017-11-16 19:34 ` Charles A. Roelli
       [not found] ` <mailman.3765.1510789425.27995.help-gnu-emacs@gnu.org>
  3 siblings, 1 reply; 69+ messages in thread
From: Emanuel Berg @ 2017-11-16  0:04 UTC (permalink / raw)
  To: help-gnu-emacs

Bob Proulx wrote:

> TL;DR: How can I transpose words jumping over
> middle words?

(defun transpose-over-word ()
  (interactive)
  (transpose-subr 'forward-word 2)
  (backward-word 1)
  (transpose-subr 'forward-word -1)
  )
(local-set-key (kbd "M-a") #'transpose-over-word) ; try it
;; Wolvie and Jubilee
;;       ^
;;      point at invocation

> Of course we all know about C-t
> transpose-chars. And there is the
> corresponding M-t transpose-words too.

... and many other transpose-*'es as well :)

> Here is the documentation.
>
> ‘M-t’ transposes the word before point with
> the word after point (‘transpose-words’).
> It moves point forward over a word, dragging
> the word preceding or containing point
> forward as well. The punctuation characters
> between the words do not move. For example,
> ‘FOO, BAR’ transposes into ‘BAR, FOO’ rather
> than ‘BAR FOO,’.

The documentation shouldn't say what *doesn't*
happen. Before long, people will start to think
that is what actually happens...

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-15 23:35 ` Eric Abrahamsen
@ 2017-11-16  6:03   ` Emanuel Berg
  0 siblings, 0 replies; 69+ messages in thread
From: Emanuel Berg @ 2017-11-16  6:03 UTC (permalink / raw)
  To: help-gnu-emacs

Eric Abrahamsen wrote:

> What should this function do if you call it
> multiple times in a row?

It can only do one thing - over and over :)

Where should point be after invocation? I just
let it be in my suggestion.

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
       [not found] <mailman.3764.1510787840.27995.help-gnu-emacs@gnu.org>
@ 2017-11-16  7:04 ` Loris Bennett
  2017-11-16  8:41   ` Joost Kremers
  2017-11-16 16:06   ` Eli Zaretskii
  2017-11-16 21:55 ` Michael Piotrowski
  2017-11-16 23:05 ` Joseph C. Fineman
  2 siblings, 2 replies; 69+ messages in thread
From: Loris Bennett @ 2017-11-16  7:04 UTC (permalink / raw)
  To: help-gnu-emacs

Hi Bob,

Bob Proulx <bob@proulx.com> writes:

> TL;DR: How can I transpose words jumping over middle words?
>
> Of course we all know about C-t transpose-chars.  And there is the
> corresponding M-t transpose-words too.  Here is the documentation.
>
>        ‘M-t’ transposes the word before point with the word after point
>     (‘transpose-words’).  It moves point forward over a word, dragging the
>     word preceding or containing point forward as well.  The punctuation
>     characters between the words do not move.  For example, ‘FOO, BAR’
>     transposes into ‘BAR, FOO’ rather than ‘BAR FOO,’.
>
> When modifying a list of comma separated s strings this works great.
> But often I find myself wanting to transpose words in an "and"
> structure.
>
>   Jack and Jill went up the hill.
>
> With the point on the space after Jack the easiest way I know to
> transpose those words is to M-d to kill-word forward deleting the
> "and" leaving.
>
>   Jack and Jill went up the hill.
>       ^ point is here: M-d
>   Jack Jill went up the hill.
>
> Then M-t to transpose those words:
>
>   Jack Jill went up the hill.
>       ^ point is here: M-t
>   Jill Jack went up the hill.
>
> Then restore the "and" which is somewhat inelegant
>
>   Jill Jack went up the hill.
>       ^ point is here: C-b C-y
>   Jill and Jack went up the hill.
>
> Obviously I can use other brute force make the change.
>
>   Jack and Jill went up the hill.
>            ^ point is here: M-d
>   Jack and  went up the hill.
>            ^ point is here: M-b M-b
>   Jack and  went up the hill.
>   ^ point is here: C-y M-d M-f
>   Jill and  went up the hill.
>           ^ point is here: C-f C-y
>   Jill and Jack went up the hill.
>
> That or something similar is usually what I do.  This is one of those
> nuisance items I have always wished had a better way to accomplish but
> just always worked through it by brute force.  But transpose-words has
> always been taunting me that it almost does what I want with M-t but
> doesn't work in this situation.
>
> Is there a way to use M-t to transpose words skipping over middle
> words like it does for punctuation?  Perhaps there isn't a better way.

Assuming I'm at the end of the three words where the transposition
should take place, I usually do

   Jack and Jill went up the hill.
                ^ point is here: M-b
   Jack and Jill went up the hill.
            ^ point is here: M-t
   Jack Jill and went up the hill.
                ^ point is here: M-b M-b
   Jack Jill and went up the hill.
        ^ point is here: M-t M-t
   Jill and Jack went up the hill.

It seems moderately elegant to me, because it involves a fairly simple
ordering of only two different functions.  Having said that, I don't do
it that regularly and so still often screw it up.

Cheers,

Loris

-- 
This signature is currently under construction.


^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16  7:04 ` Transposing words over middle words Loris Bennett
@ 2017-11-16  8:41   ` Joost Kremers
  2017-11-16  8:47     ` Joost Kremers
  2017-11-16 16:06   ` Eli Zaretskii
  1 sibling, 1 reply; 69+ messages in thread
From: Joost Kremers @ 2017-11-16  8:41 UTC (permalink / raw)
  To: Loris Bennett; +Cc: help-gnu-emacs


On Thu, Nov 16 2017, Loris Bennett wrote:
> Assuming I'm at the end of the three words where the 
> transposition
> should take place, I usually do
>
>    Jack and Jill went up the hill.
>                 ^ point is here: M-b
>    Jack and Jill went up the hill.
>             ^ point is here: M-t
>    Jack Jill and went up the hill.
>                 ^ point is here: M-b M-b
>    Jack Jill and went up the hill.
>         ^ point is here: M-t M-t
>    Jill and Jack went up the hill.
>
> It seems moderately elegant to me, because it involves a fairly 
> simple
> ordering of only two different functions.  Having said that, I 
> don't do
> it that regularly and so still often screw it up.

There is a slightly quicker way of doing it (with | indicating 
point):

    Jack |and Jill went up the hill.

         M-2 M-t

    and Jill Jack| went up the hill.

        M-2 M-b (or M-b M-b)

    and |Jill Jack went up the hill.

        M-t

    Jill and Jack went up the hill.

But yeah, I've also been in the situation where I wished there 
were a function 'transpose two words while pretending the word 
point is on isn't there'...

-- 
Joost Kremers
Life has its moments



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16  8:41   ` Joost Kremers
@ 2017-11-16  8:47     ` Joost Kremers
  0 siblings, 0 replies; 69+ messages in thread
From: Joost Kremers @ 2017-11-16  8:47 UTC (permalink / raw)
  To: Loris Bennett; +Cc: help-gnu-emacs


On Thu, Nov 16 2017, Joost Kremers wrote:
> On Thu, Nov 16 2017, Loris Bennett wrote:
>> Assuming I'm at the end of the three words where the 
>> transposition
>> should take place, I usually do
>>
>>    Jack and Jill went up the hill.
>>                 ^ point is here: M-b
>>    Jack and Jill went up the hill.
>>             ^ point is here: M-t
>>    Jack Jill and went up the hill.
>>                 ^ point is here: M-b M-b
>>    Jack Jill and went up the hill.
>>         ^ point is here: M-t M-t
>>    Jill and Jack went up the hill.
>>
>> It seems moderately elegant to me, because it involves a fairly 
>> simple
>> ordering of only two different functions.  Having said that, I 
>> don't do
>> it that regularly and so still often screw it up.
>
> There is a slightly quicker way of doing it (with | indicating 
> point):

Come to think of it, in terms of key presses, it's not quicker at 
all... ;-) Anyway, I thought using a prefix argument would help, 
but when it's only a single word you're jumping over, it doesn't.



-- 
Joost Kremers
Life has its moments



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16  7:04 ` Transposing words over middle words Loris Bennett
  2017-11-16  8:41   ` Joost Kremers
@ 2017-11-16 16:06   ` Eli Zaretskii
  2017-11-16 22:26     ` Bob Proulx
  1 sibling, 1 reply; 69+ messages in thread
From: Eli Zaretskii @ 2017-11-16 16:06 UTC (permalink / raw)
  To: help-gnu-emacs

> From: "Loris Bennett" <loris.bennett@fu-berlin.de>
> Date: Thu, 16 Nov 2017 08:04:39 +0100
> 
> Assuming I'm at the end of the three words where the transposition
> should take place, I usually do
> 
>    Jack and Jill went up the hill.
>                 ^ point is here: M-b
>    Jack and Jill went up the hill.
>             ^ point is here: M-t
>    Jack Jill and went up the hill.
>                 ^ point is here: M-b M-b
>    Jack Jill and went up the hill.
>         ^ point is here: M-t M-t
>    Jill and Jack went up the hill.

Why not

  . move point to "Jack", type C-SPC
  . type M-2 M-f to move point to "Jill"
  . type M-0 M-t to swap words

?



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-15 23:17 Transposing words over middle words Bob Proulx
  2017-11-15 23:35 ` Eric Abrahamsen
  2017-11-16  0:04 ` Emanuel Berg
@ 2017-11-16 19:34 ` Charles A. Roelli
  2017-11-16 19:41   ` Emanuel Berg
                     ` (2 more replies)
       [not found] ` <mailman.3765.1510789425.27995.help-gnu-emacs@gnu.org>
  3 siblings, 3 replies; 69+ messages in thread
From: Charles A. Roelli @ 2017-11-16 19:34 UTC (permalink / raw)
  To: Bob Proulx; +Cc: help-gnu-emacs

> Date: Wed, 15 Nov 2017 16:17:12 -0700
> From: Bob Proulx <bob@proulx.com>
> 
> TL;DR: How can I transpose words jumping over middle words?

I would just select the two words with the mouse (point and mark
anywhere in both words will do), then use M-t with a zero prefix
argument:

     A numeric argument of zero is assigned a special meaning (because
  otherwise a command with a repeat count of zero would do nothing): to
  transpose the character (word, expression, line) ending after point with
  the one ending after the mark.

(info "(emacs) Transpose")



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16 19:34 ` Charles A. Roelli
@ 2017-11-16 19:41   ` Emanuel Berg
  2017-11-16 20:09   ` Marcin Borkowski
  2017-11-16 22:28   ` Bob Proulx
  2 siblings, 0 replies; 69+ messages in thread
From: Emanuel Berg @ 2017-11-16 19:41 UTC (permalink / raw)
  To: help-gnu-emacs

Charles A. Roelli wrote:

> I would just select the two words with the
> mouse

What do you mean?

:)

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16 19:34 ` Charles A. Roelli
  2017-11-16 19:41   ` Emanuel Berg
@ 2017-11-16 20:09   ` Marcin Borkowski
  2017-11-16 21:15     ` Emanuel Berg
  2017-11-16 21:18     ` Emanuel Berg
  2017-11-16 22:28   ` Bob Proulx
  2 siblings, 2 replies; 69+ messages in thread
From: Marcin Borkowski @ 2017-11-16 20:09 UTC (permalink / raw)
  To: Charles A. Roelli; +Cc: help-gnu-emacs, Bob Proulx


On 2017-11-16, at 20:34, Charles A. Roelli <charles@aurox.ch> wrote:

>> Date: Wed, 15 Nov 2017 16:17:12 -0700
>> From: Bob Proulx <bob@proulx.com>
>> 
>> TL;DR: How can I transpose words jumping over middle words?
>
> I would just select the two words with the mouse (point and mark
> anywhere in both words will do), then use M-t with a zero prefix
> argument:
>
>      A numeric argument of zero is assigned a special meaning (because
>   otherwise a command with a repeat count of zero would do nothing): to
>   transpose the character (word, expression, line) ending after point with
>   the one ending after the mark.
>
> (info "(emacs) Transpose")

I had no idea!  How cool is that?  Thanks a lot!!!

Best,

-- 
Marcin Borkowski



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16 20:09   ` Marcin Borkowski
@ 2017-11-16 21:15     ` Emanuel Berg
  2017-11-16 22:55       ` Bob Proulx
  2017-11-16 21:18     ` Emanuel Berg
  1 sibling, 1 reply; 69+ messages in thread
From: Emanuel Berg @ 2017-11-16 21:15 UTC (permalink / raw)
  To: help-gnu-emacs

Marcin Borkowski wrote:

>> A numeric argument of zero is assigned
>> a special meaning (because otherwise
>> a command with a repeat count of zero would
>> do nothing): to transpose the character
>> (word, expression, line) ending after point
>> with the one ending after the mark.
>>
>> (info "(emacs) Transpose")
>
> I had no idea! How cool is that?
> Thanks a lot!!!

Cool indeed, but the mark business makes it as
complicated anyway compared with transposing
two times:

(defun transpose-over-word ()
  (interactive)
  (transpose-subr #'forward-word  2)
  (backward-word 1)
  (transpose-subr #'forward-word -1) )

(defun transpose-over-word-2 ()
  (interactive)
  (backward-char 1)
  (push-mark)
  (forward-word 3)
  (backward-char 1)
  (transpose-words 0)
  (forward-word 1) )

;; Jack and Jill
;;     ^
;;   point here at invocation

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16 20:09   ` Marcin Borkowski
  2017-11-16 21:15     ` Emanuel Berg
@ 2017-11-16 21:18     ` Emanuel Berg
  2017-11-16 22:43       ` Drew Adams
  1 sibling, 1 reply; 69+ messages in thread
From: Emanuel Berg @ 2017-11-16 21:18 UTC (permalink / raw)
  To: help-gnu-emacs

By the way, what does `special' do?

;; FIXME document SPECIAL.
(defun transpose-subr (mover arg &optional special)
;; [...]
    (if special mover
             (lambda (x)
          (cons (progn (funcall mover x) (point))
                (progn (funcall mover (- x)) (point)))))

"Document SPECIAL" - good idea :)

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
       [not found] <mailman.3764.1510787840.27995.help-gnu-emacs@gnu.org>
  2017-11-16  7:04 ` Transposing words over middle words Loris Bennett
@ 2017-11-16 21:55 ` Michael Piotrowski
  2017-11-16 23:05 ` Joseph C. Fineman
  2 siblings, 0 replies; 69+ messages in thread
From: Michael Piotrowski @ 2017-11-16 21:55 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

On 2017-11-16, Bob Proulx <bob@proulx.com> wrote:

> TL;DR: How can I transpose words jumping over middle words?

I wrote conjunct-mode to address exactly this task:

  <https://github.com/mxpiotrowski/conjunct.el>

Best regards

-- 
Prof. Dr.-Ing. Michael Piotrowski                   <mxp@dynalabs.de>
Public key at <http://www.dynalabs.de/mxp/pubkey.txt> (ID 0x1614A044)


^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
       [not found] ` <mailman.3765.1510789425.27995.help-gnu-emacs@gnu.org>
@ 2017-11-16 22:02   ` Michael Piotrowski
  2017-11-16 23:00     ` Bob Proulx
  2017-11-16 23:29     ` Eric Abrahamsen
  0 siblings, 2 replies; 69+ messages in thread
From: Michael Piotrowski @ 2017-11-16 22:02 UTC (permalink / raw)
  To: help-gnu-emacs

On 2017-11-16, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:

> I use Emacs more for prose composition than I do for coding, and I've
> often wanted this.

Me too, so I wrote conjunct-mode to address exactly this task:

  <https://github.com/mxpiotrowski/conjunct.el>

> Over the years I've written a bunch of small functions for making it
> easier to write prose (slurping spaces before punctuation after
> deleting a word, etc), but eventually have discarded most of them in
> favor of just hitting a few extra keys. I could never get the DWIM
> behavior DWIM-ish enough, and it was more of a headache watching for
> and correcting the mis-fires than it was just banging more keys.

Transposing conjuncts often happens when revising formulations, so
conjunct-mode lets you try the effect before committing to it.  This is
clearly a different approach, which probably doesn’t work for everybody
either…

Greetings

-- 
Prof. Dr.-Ing. Michael Piotrowski                   <mxp@dynalabs.de>
Public key at <http://www.dynalabs.de/mxp/pubkey.txt> (ID 0x1614A044)


^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16 16:06   ` Eli Zaretskii
@ 2017-11-16 22:26     ` Bob Proulx
  2017-11-17  5:00       ` Yuri Khan
                         ` (2 more replies)
  0 siblings, 3 replies; 69+ messages in thread
From: Bob Proulx @ 2017-11-16 22:26 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii wrote:
> Why not
> 
>   . move point to "Jack", type C-SPC
>   . type M-2 M-f to move point to "Jill"
>   . type M-0 M-t to swap words
> 
> ?

Oh!  I never knew about that functionality before.

       A numeric argument of zero is assigned a special meaning (because
    otherwise a command with a repeat count of zero would do nothing): to
    transpose the character (word, expression, line) ending after point with
    the one ending after the mark.

That's pretty cool!  I hadn't realized it had this built in.  It still
requires a lot of setup.  One must move to the beginning of one word,
set the mark, move to the beginning of the other word, M-0 M-t or
C-u 0 ESC t if I can't make the meta work on that keyboard.  But it is
quite general and I can think of other cases in my editing where I
might use such a thing.

Thanks!
Bob



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16 19:34 ` Charles A. Roelli
  2017-11-16 19:41   ` Emanuel Berg
  2017-11-16 20:09   ` Marcin Borkowski
@ 2017-11-16 22:28   ` Bob Proulx
  2 siblings, 0 replies; 69+ messages in thread
From: Bob Proulx @ 2017-11-16 22:28 UTC (permalink / raw)
  To: help-gnu-emacs

Charles A. Roelli wrote:
> I would just select the two words with the mouse (point and mark
> anywhere in both words will do), then use M-t with a zero prefix
> argument:
> 
>      A numeric argument of zero is assigned a special meaning (because
>   otherwise a command with a repeat count of zero would do nothing): to
>   transpose the character (word, expression, line) ending after point with
>   the one ending after the mark.

I never knew about this functionalty before.  Pretty cool!  It is still
a little more setup than it might be.  But I can think of other cases
where I might use this capability.

Thanks for teaching me this cool feature!

Bob



^ permalink raw reply	[flat|nested] 69+ messages in thread

* RE: Transposing words over middle words
  2017-11-16 21:18     ` Emanuel Berg
@ 2017-11-16 22:43       ` Drew Adams
  2017-11-16 22:59         ` Emanuel Berg
  0 siblings, 1 reply; 69+ messages in thread
From: Drew Adams @ 2017-11-16 22:43 UTC (permalink / raw)
  To: Emanuel Berg, help-gnu-emacs

> By the way, what does `special' do?
> 
> ;; FIXME document SPECIAL.
> (defun transpose-subr (mover arg &optional special)
>
> "Document SPECIAL" - good idea :)

https://debbugs.gnu.org/cgi/bugreport.cgi?bug=29328



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16 21:15     ` Emanuel Berg
@ 2017-11-16 22:55       ` Bob Proulx
  2017-11-16 23:02         ` Emanuel Berg
  0 siblings, 1 reply; 69+ messages in thread
From: Bob Proulx @ 2017-11-16 22:55 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg wrote:
> Marcin Borkowski wrote:
> > I had no idea! How cool is that?
> > Thanks a lot!!!
> 
> Cool indeed, but the mark business makes it as
> complicated anyway compared with transposing
> two times:

Yes.  Agreed.

> (defun transpose-over-word ()
>   (interactive)
>   (transpose-subr #'forward-word  2)
>   (backward-word 1)
>   (transpose-subr #'forward-word -1) )

This is a nice example of the joy of customizing emacs.  For my tastes
I would want it to move the point with the word being dragged forward
two words.  Here is my modification to the above.

 (defun transpose-over-word ()
   (interactive)
   (transpose-subr #'forward-word  2)
   (backward-word 1)
   (transpose-subr #'forward-word -1) 
   (forward-word 1) )

That actually does exactly what I would want M-1 M-t to do.

Bob



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16 22:43       ` Drew Adams
@ 2017-11-16 22:59         ` Emanuel Berg
  2017-11-17 16:21           ` Drew Adams
  0 siblings, 1 reply; 69+ messages in thread
From: Emanuel Berg @ 2017-11-16 22:59 UTC (permalink / raw)
  To: help-gnu-emacs

Drew Adams wrote:

>> By the way, what does `special' do?
>> 
>> ;; FIXME document SPECIAL. (defun
>> transpose-subr (mover arg &optional special)
>> "Document SPECIAL" - good idea :)
>
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=29328

Good. Now it says so in the source, I said it
here, and you said it on debbugs. That should
be enough.

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16 22:02   ` Michael Piotrowski
@ 2017-11-16 23:00     ` Bob Proulx
  2017-11-16 23:29     ` Eric Abrahamsen
  1 sibling, 0 replies; 69+ messages in thread
From: Bob Proulx @ 2017-11-16 23:00 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Piotrowski wrote:
> Me too, so I wrote conjunct-mode to address exactly this task:
> 
>   <https://github.com/mxpiotrowski/conjunct.el>

Wow.  A lot there!  This looks very cool.

> Transposing conjuncts often happens when revising formulations, so
> conjunct-mode lets you try the effect before committing to it.  This is
> clearly a different approach, which probably doesn’t work for everybody
> either...

Thank you for suggesting this.  I am pulling a copy to play with.
Frankly it might be more than I want but having options to choose from
is always a good thing.

Thanks!
Bob



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16 22:55       ` Bob Proulx
@ 2017-11-16 23:02         ` Emanuel Berg
  0 siblings, 0 replies; 69+ messages in thread
From: Emanuel Berg @ 2017-11-16 23:02 UTC (permalink / raw)
  To: help-gnu-emacs

Bob Proulx wrote:

>> (defun transpose-over-word ()
>>   (interactive)
>>   (transpose-subr #'forward-word  2)
>>   (backward-word 1)
>>   (transpose-subr #'forward-word -1) )
>
> This is a nice example of the joy of
> customizing emacs.

*extending (but I agree, of course)

> For my tastes I would want it to move the
> point with the word being dragged forward two
> words. Here is my modification to the above.
>
>  (defun transpose-over-word ()
>    (interactive)
>    (transpose-subr #'forward-word  2)
>    (backward-word 1)
>    (transpose-subr #'forward-word -1) 
>    (forward-word 1) )
>
> That actually does exactly what I would want
> M-1 M-t to do.

Don't mention it :)

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
       [not found] <mailman.3764.1510787840.27995.help-gnu-emacs@gnu.org>
  2017-11-16  7:04 ` Transposing words over middle words Loris Bennett
  2017-11-16 21:55 ` Michael Piotrowski
@ 2017-11-16 23:05 ` Joseph C. Fineman
  2017-11-17  0:39   ` Emanuel Berg
                     ` (3 more replies)
  2 siblings, 4 replies; 69+ messages in thread
From: Joseph C. Fineman @ 2017-11-16 23:05 UTC (permalink / raw)
  To: help-gnu-emacs

Bob Proulx <bob@proulx.com> writes:

> TL;DR: How can I transpose words jumping over middle words?

I think that, rather than expending cleverness on that particular
problem, and then trying to remember the result, I would write a command
that solved a more general problem & would be easy to remember.  Namely,
after I set the mark successively at the beginning and end of a passage,
and then at the beginning of another passage, and then going to the end
of the latter passage, it would, on being called, exchange the former
with the latter passage (using the mark ring).  Then, in particular, I
could march thru "Jack and Jill" with 3 control-spaces, put point at the
end of "Jill", and hit the command to achieve "Jill and Jack".  I am too
senile to write that on the spot (or, perhaps, at all), but it ought to
be easy.
-- 
---  Joe Fineman    joe_f@verizon.net

||:  Be sincere: fool yourself first.  :||


^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16 22:02   ` Michael Piotrowski
  2017-11-16 23:00     ` Bob Proulx
@ 2017-11-16 23:29     ` Eric Abrahamsen
  2017-11-16 23:30       ` Eric Abrahamsen
  1 sibling, 1 reply; 69+ messages in thread
From: Eric Abrahamsen @ 2017-11-16 23:29 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Piotrowski <mxp@dynalabs.de> writes:

> On 2017-11-16, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:
>
>> I use Emacs more for prose composition than I do for coding, and I've
>> often wanted this.
>
> Me too, so I wrote conjunct-mode to address exactly this task:
>
>   <https://github.com/mxpiotrowski/conjunct.el>

Interesting, thanks a lot for this. I'll take a look.




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16 23:29     ` Eric Abrahamsen
@ 2017-11-16 23:30       ` Eric Abrahamsen
  2017-11-17  0:27         ` put it in MELPA (was: Re: Transposing words over middle words) Emanuel Berg
  0 siblings, 1 reply; 69+ messages in thread
From: Eric Abrahamsen @ 2017-11-16 23:30 UTC (permalink / raw)
  To: help-gnu-emacs

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Michael Piotrowski <mxp@dynalabs.de> writes:
>
>> On 2017-11-16, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:
>>
>>> I use Emacs more for prose composition than I do for coding, and I've
>>> often wanted this.
>>
>> Me too, so I wrote conjunct-mode to address exactly this task:
>>
>>   <https://github.com/mxpiotrowski/conjunct.el>
>
> Interesting, thanks a lot for this. I'll take a look.

Also, I'd recommend putting it in MELPA. Are there any other Lingured
libraries that might be made available?




^ permalink raw reply	[flat|nested] 69+ messages in thread

* put it in MELPA (was: Re: Transposing words over middle words)
  2017-11-16 23:30       ` Eric Abrahamsen
@ 2017-11-17  0:27         ` Emanuel Berg
  2017-11-17  0:30           ` put it in MELPA Eric Abrahamsen
  2017-11-17 15:16           ` put it in MELPA (was: Re: Transposing words over middle words) Tim Visher
  0 siblings, 2 replies; 69+ messages in thread
From: Emanuel Berg @ 2017-11-17  0:27 UTC (permalink / raw)
  To: help-gnu-emacs

> Also, I'd recommend putting it in MELPA.
> Are there any other Lingured libraries that
> might be made available?

How exactly do you put stuff in MELPA?

I ask because I have 100+ Elisp files and
perhaps a dozen are full blown packs complete
with documentation and, aeeh, documentation!

Some of it could be useful to other people -
why not?

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: put it in MELPA
  2017-11-17  0:27         ` put it in MELPA (was: Re: Transposing words over middle words) Emanuel Berg
@ 2017-11-17  0:30           ` Eric Abrahamsen
  2017-11-17 15:16           ` put it in MELPA (was: Re: Transposing words over middle words) Tim Visher
  1 sibling, 0 replies; 69+ messages in thread
From: Eric Abrahamsen @ 2017-11-17  0:30 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <moasen@zoho.com> writes:

>> Also, I'd recommend putting it in MELPA.
>> Are there any other Lingured libraries that
>> might be made available?
>
> How exactly do you put stuff in MELPA?

https://github.com/melpa/melpa/blob/master/CONTRIBUTING.md




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16 23:05 ` Joseph C. Fineman
@ 2017-11-17  0:39   ` Emanuel Berg
  2017-11-17  7:19   ` Eli Zaretskii
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 69+ messages in thread
From: Emanuel Berg @ 2017-11-17  0:39 UTC (permalink / raw)
  To: help-gnu-emacs

Joseph C. Fineman wrote:

>> TL;DR: How can I transpose words jumping
>> over middle words?
>
> I think that, rather than expending
> cleverness on that particular problem, and
> then trying to remember the result,I would
> write a command that solved a more general
> problem

In general, it isn't better to try to solve the
general problem. The layman mechanic might
think an adjustable spanner is superior to
a (fixed size) combination spanner (the
"U-ring") - but on the contrary, it is much
worse, at least as long as you have the whole
set of metric and imperial sizes - and if you
don't, that's another issue. Specific gear for
specific purposes is what wins the day.

In programming, it is better to solve the
specific problem first, like this

    (count-to-five) ; 1 2 3 4 5

Only when you realize you need to count to four
as well you might consider

    (count-to x) ; 1 .. x

and

    (count-to 4)
    (count-to 5)

But even there, this

    (count-to-five)
    (count-to-four)

isn't always wrong. It depends. (This is a toy
example, of course.)

> & would be easy to remember.

Unless there is DWIM interface I'd say the
general solution can be less easy to remember
as you need to feed it argument(s) and/or tweak
it for the particular situation. Which is
slower than the specific solution, both
invocation and execution, as well.

General solutions are more good-looking tho :)

And you can have both at the same time!
Remember, "make the common [frequent] case fast
and the rare case correct."

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16 22:26     ` Bob Proulx
@ 2017-11-17  5:00       ` Yuri Khan
  2017-11-17  5:08         ` Emanuel Berg
  2017-11-17  8:55       ` Gian Uberto Lauri
  2017-11-18 17:11       ` Robert Thorpe
  2 siblings, 1 reply; 69+ messages in thread
From: Yuri Khan @ 2017-11-17  5:00 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

On Fri, Nov 17, 2017 at 5:26 AM, Bob Proulx <bob@proulx.com> wrote:

> That's pretty cool!  I hadn't realized it had this built in.  It still
> requires a lot of setup.  One must move to the beginning of one word,
> set the mark, move to the beginning of the other word, M-0 M-t or
> C-u 0 ESC t if I can't make the meta work on that keyboard.

I imagine it might be a good idea to also transpose words at point and
mark when transient-mark-mode is on and mark is active. Then:

|Jack and Jill

| Ctrl+Shift+→ Ctrl+Shift+→

[Jack and] Jill

| M-t

|Jill and Jack



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-17  5:00       ` Yuri Khan
@ 2017-11-17  5:08         ` Emanuel Berg
  0 siblings, 0 replies; 69+ messages in thread
From: Emanuel Berg @ 2017-11-17  5:08 UTC (permalink / raw)
  To: help-gnu-emacs

Yuri Khan wrote:

> I imagine it might be a good idea to also
> transpose words at point and mark when
> transient-mark-mode is on and mark is active.
> Then:
>
> |Jack and Jill
>
> | Ctrl+Shift+→ Ctrl+Shift+→
>
> [Jack and] Jill
>
> | M-t
>
> |Jill and Jack

?


-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16 23:05 ` Joseph C. Fineman
  2017-11-17  0:39   ` Emanuel Berg
@ 2017-11-17  7:19   ` Eli Zaretskii
       [not found]   ` <mailman.3847.1510879170.27995.help-gnu-emacs@gnu.org>
       [not found]   ` <mailman.3856.1510903218.27995.help-gnu-emacs@gnu.org>
  3 siblings, 0 replies; 69+ messages in thread
From: Eli Zaretskii @ 2017-11-17  7:19 UTC (permalink / raw)
  To: help-gnu-emacs

> From: joe_f@verizon.net (Joseph C. Fineman)
> Date: Thu, 16 Nov 2017 18:05:01 -0500
> 
> I think that, rather than expending cleverness on that particular
> problem, and then trying to remember the result, I would write a command
> that solved a more general problem & would be easy to remember.  Namely,
> after I set the mark successively at the beginning and end of a passage,
> and then at the beginning of another passage, and then going to the end
> of the latter passage, it would, on being called, exchange the former
> with the latter passage (using the mark ring).

Isn't that what the zero argument to M-t already does?



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16 22:26     ` Bob Proulx
  2017-11-17  5:00       ` Yuri Khan
@ 2017-11-17  8:55       ` Gian Uberto Lauri
  2017-11-17  8:58         ` Gian Uberto Lauri
  2017-11-17 20:38         ` Marcin Borkowski
  2017-11-18 17:11       ` Robert Thorpe
  2 siblings, 2 replies; 69+ messages in thread
From: Gian Uberto Lauri @ 2017-11-17  8:55 UTC (permalink / raw)
  To: Bob Proulx; +Cc: help-gnu-emacs

>>>>> "BP" == Bob Proulx <bob@proulx.com> writes:

BP> Eli Zaretskii wrote:
>> Why not
>> 
>> . move point to "Jack", type C-SPC . type M-2 M-f to move point to
>> "Jill" . type M-0 M-t to swap words
>> 
>> ?

BP> Oh!  I never knew about that functionality before.

M-0 M-t is undefined

GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 2.24.30) of 2017-09-29

-- 
 /\           ___                                    Ubuntu: ancient
/___/\_|_|\_|__|___Gian Uberto Lauri_____               African word
  //--\| | \|  |   Integralista GNUslamico            meaning "I can
\/                 coltivatore diretto di software       not install
     già sistemista a tempo (altrui) perso...                Debian"

Warning: gnome-config-daemon considered more dangerous than GOTO



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-17  8:55       ` Gian Uberto Lauri
@ 2017-11-17  8:58         ` Gian Uberto Lauri
  2017-11-17  9:10           ` Eli Zaretskii
  2017-11-17 16:03           ` Stefan Monnier
  2017-11-17 20:38         ` Marcin Borkowski
  1 sibling, 2 replies; 69+ messages in thread
From: Gian Uberto Lauri @ 2017-11-17  8:58 UTC (permalink / raw)
  To: Gian Uberto Lauri; +Cc: help-gnu-emacs, Bob Proulx

>>>>> "CC" == Gian Uberto Lauri <saint@eng.it> writes:

>>>>> "BP" == Bob Proulx <bob@proulx.com> writes:
BP> Eli Zaretskii wrote:
>>> Why not
>>> 
>>> . move point to "Jack", type C-SPC . type M-2 M-f to move point to
>>> "Jill" . type M-0 M-t to swap words
>>> 
>>> ?

BP> Oh!  I never knew about that functionality before.

CC> M-0 M-t is undefined

CC> GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
CC> 2.24.30) of 2017-09-29

C-u 0 M-t works fine.

-- 
 /\           ___                                    Ubuntu: ancient
/___/\_|_|\_|__|___Gian Uberto Lauri_____               African word
  //--\| | \|  |   Integralista GNUslamico            meaning "I can
\/                 coltivatore diretto di software       not install
     già sistemista a tempo (altrui) perso...                Debian"

Warning: gnome-config-daemon considered more dangerous than GOTO



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-17  8:58         ` Gian Uberto Lauri
@ 2017-11-17  9:10           ` Eli Zaretskii
  2017-11-17  9:35             ` Gian Uberto Lauri
  2017-11-17 16:03           ` Stefan Monnier
  1 sibling, 1 reply; 69+ messages in thread
From: Eli Zaretskii @ 2017-11-17  9:10 UTC (permalink / raw)
  To: help-gnu-emacs

> From: "Gian Uberto Lauri" <saint@eng.it>
> Date: Fri, 17 Nov 2017 09:58:44 +0100
> Cc: help-gnu-emacs@gnu.org, Bob Proulx <bob@proulx.com>
> 
> CC> M-0 M-t is undefined
> 
> CC> GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
> CC> 2.24.30) of 2017-09-29
> 
> C-u 0 M-t works fine.

Maybe you tried M-0 on a text-mode frame ("emacs -nw")?

Or maybe your meta key is customized in some weird way?

By default, M-<digit> is the same as "C-u <digit>".  I used M-0
because it is easier to type M-t afterwards: you don't have to move
your finger from the Meta key.




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-17  9:10           ` Eli Zaretskii
@ 2017-11-17  9:35             ` Gian Uberto Lauri
  0 siblings, 0 replies; 69+ messages in thread
From: Gian Uberto Lauri @ 2017-11-17  9:35 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

>>>>> "EZ" == Eli Zaretskii <eliz@gnu.org> writes:

EZ> Maybe you tried M-0 on a text-mode frame ("emacs -nw")?

X11, 3-headed, with WindoMaker

EZ> Or maybe your meta key is customized in some weird way?

It does not seems so... The M- prefixed command work as usual.  But
you gave me an hint. First I tested another instance running on a
clean Emacs instance, and there it works fine.

So i went to my .emacs... And I discovered that I indeed assigned M-0
to a custom keypad, to use 4 extra keys on a external numeric keypad
(got a cheap keyboard w/o it, then a keypad. All with cherry
switches).

Who built the numeric keypad thought that was damn cool send M-0 M-4
M-0 to insert a "[" (actually the sequence works no matter which
Windows keyboard configuration you are using, if you accept that
everybody uses Windows it is not a stupid choice) M-0 M-4 M-1 to
insert a "]" and M-0 M-6 M-1 to issue a "=".

So it was my fault, sorry.

Nevertheless the "transpose with jump" is DAMN useful, worth the extra
work of the C-u!

-- 
 /\           ___                                    Ubuntu: ancient
/___/\_|_|\_|__|___Gian Uberto Lauri_____               African word
  //--\| | \|  |   Integralista GNUslamico            meaning "I can
\/                 coltivatore diretto di software       not install
     già sistemista a tempo (altrui) perso...                Debian"

Warning: gnome-config-daemon considered more dangerous than GOTO



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: put it in MELPA (was: Re: Transposing words over middle words)
  2017-11-17  0:27         ` put it in MELPA (was: Re: Transposing words over middle words) Emanuel Berg
  2017-11-17  0:30           ` put it in MELPA Eric Abrahamsen
@ 2017-11-17 15:16           ` Tim Visher
  1 sibling, 0 replies; 69+ messages in thread
From: Tim Visher @ 2017-11-17 15:16 UTC (permalink / raw)
  To: emacs

You issue a PR against MELPA.
https://github.com/melpa/melpa/blob/master/CONTRIBUTING.md#contributing-new-recipes

On Thu, Nov 16, 2017 at 7:27 PM, Emanuel Berg <moasen@zoho.com> wrote:

> > Also, I'd recommend putting it in MELPA.
> > Are there any other Lingured libraries that
> > might be made available?
>
> How exactly do you put stuff in MELPA?
>
> I ask because I have 100+ Elisp files and
> perhaps a dozen are full blown packs complete
> with documentation and, aeeh, documentation!
>
> Some of it could be useful to other people -
> why not?
>
> --
> underground experts united
> http://user.it.uu.se/~embe8573
>
>
>


^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-17  8:58         ` Gian Uberto Lauri
  2017-11-17  9:10           ` Eli Zaretskii
@ 2017-11-17 16:03           ` Stefan Monnier
  2017-11-17 16:19             ` Robert Pluim
                               ` (3 more replies)
  1 sibling, 4 replies; 69+ messages in thread
From: Stefan Monnier @ 2017-11-17 16:03 UTC (permalink / raw)
  To: help-gnu-emacs

> C-u 0 M-t works fine.

BTW, I'd argue that C-u M-t should work as well: currently it is treated
like C-u 4 M-t, but I think it's a poor choice.


        Stefan




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-17 16:03           ` Stefan Monnier
@ 2017-11-17 16:19             ` Robert Pluim
  2017-11-17 20:41               ` Marcin Borkowski
  2017-11-17 16:42             ` Eli Zaretskii
                               ` (2 subsequent siblings)
  3 siblings, 1 reply; 69+ messages in thread
From: Robert Pluim @ 2017-11-17 16:19 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> C-u 0 M-t works fine.
>
> BTW, I'd argue that C-u M-t should work as well: currently it is treated
> like C-u 4 M-t, but I think it's a poor choice.

How would you distinguish that from someone actually typing C-u 4 M-t?
The interactive arg is '4' in both cases, no?

Robert



^ permalink raw reply	[flat|nested] 69+ messages in thread

* RE: Transposing words over middle words
  2017-11-16 22:59         ` Emanuel Berg
@ 2017-11-17 16:21           ` Drew Adams
  2017-11-17 20:52             ` Emanuel Berg
  0 siblings, 1 reply; 69+ messages in thread
From: Drew Adams @ 2017-11-17 16:21 UTC (permalink / raw)
  To: Emanuel Berg, help-gnu-emacs

> >> By the way, what does `special' do?
> >>
> >> ;; FIXME document SPECIAL. (defun
> >> transpose-subr (mover arg &optional special)
> >> "Document SPECIAL" - good idea :)
> >
> > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=29328
> 
> Good. Now it says so in the source, I said
> it here, and you said it on debbugs.
> That should be enough.

Alas, far from enough.

The bug was was closed summarily, under the pretext
that it's impossible to describe parameter SPECIAL,
and that this is only an "internal subroutine" so
it need not have complete doc.

IOW, we don't know how to describe it, and we don't
need to tell _you_ what it is anyway, lusers.
Oh, and asking for this information is annoying
"bike-shedding".  Circulez ! Il n'y a rien a voir.

So the full gamut of lame reasons: It's internal;
it's unimportant; and we couldn't possibly describe
it even if we wanted to.

Anyone trying to define their own transposition
function will likely need to use `transpose-subr'
(that's what its for).  So I can't imagine why it
should be considered "internal".

To me, this is like saying that `sort-subr' is
internal.  A whole section of the Elisp manual is
devoted to that workhorse "subroutine".

http://www.gnu.org/software/emacs/manual/html_node/elisp/Sorting.html



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-17 16:03           ` Stefan Monnier
  2017-11-17 16:19             ` Robert Pluim
@ 2017-11-17 16:42             ` Eli Zaretskii
  2017-11-17 22:53               ` Stefan Monnier
       [not found]             ` <mailman.3897.1510936953.27995.help-gnu-emacs@gnu.org>
  2017-11-17 22:55             ` Stefan Monnier
  3 siblings, 1 reply; 69+ messages in thread
From: Eli Zaretskii @ 2017-11-17 16:42 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Fri, 17 Nov 2017 11:03:37 -0500
> 
> > C-u 0 M-t works fine.
> 
> BTW, I'd argue that C-u M-t should work as well: currently it is treated
> like C-u 4 M-t, but I think it's a poor choice.

Really?  That a lone C-u means an arg of 4 is burnt into our muscle
memory for decades.  Compare with "C-u C-n".  A command that receives
a numerical argument normally treats all of its arguments as numbers.
Breaking that in a single command sounds like a misfeature.



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
       [not found]             ` <mailman.3897.1510936953.27995.help-gnu-emacs@gnu.org>
@ 2017-11-17 16:57               ` Rusi
  2017-11-17 17:26                 ` Drew Adams
  2017-11-17 18:05                 ` Eli Zaretskii
  0 siblings, 2 replies; 69+ messages in thread
From: Rusi @ 2017-11-17 16:57 UTC (permalink / raw)
  To: help-gnu-emacs

On Friday, November 17, 2017 at 10:12:36 PM UTC+5:30, Eli Zaretskii wrote:
> > From: Stefan Monnier
> > Date: Fri, 17 Nov 2017 11:03:37 -0500
> > 
> > > C-u 0 M-t works fine.
> > 
> > BTW, I'd argue that C-u M-t should work as well: currently it is treated
> > like C-u 4 M-t, but I think it's a poor choice.
> 
> Really?  That a lone C-u means an arg of 4 is burnt into our muscle
> memory for decades.  Compare with "C-u C-n".  A command that receives
> a numerical argument normally treats all of its arguments as numbers.
> Breaking that in a single command sounds like a misfeature.

Org mode (at least) is full of functions for which C-u means change some behavior (C-u C-u changes more) and has nothing to do with some magic number 4


^ permalink raw reply	[flat|nested] 69+ messages in thread

* RE: Transposing words over middle words
  2017-11-17 16:57               ` Rusi
@ 2017-11-17 17:26                 ` Drew Adams
  2017-11-17 18:05                 ` Eli Zaretskii
  1 sibling, 0 replies; 69+ messages in thread
From: Drew Adams @ 2017-11-17 17:26 UTC (permalink / raw)
  To: Rusi, help-gnu-emacs

> > > > C-u 0 M-t works fine.
> > >
> > > BTW, I'd argue that C-u M-t should work as well: currently it is
> treated
> > > like C-u 4 M-t, but I think it's a poor choice.
> >
> > Really?  That a lone C-u means an arg of 4 is burnt into our muscle
> > memory for decades.  Compare with "C-u C-n".  A command that receives
> > a numerical argument normally treats all of its arguments as numbers.
> > Breaking that in a single command sounds like a misfeature.
> 
> Org mode (at least) is full of functions for which C-u means change some
> behavior (C-u C-u changes more) and has nothing to do with some magic
> number 4

It's fine for `C-u' to be interpreted numerically (as 4)
by any command.  It's also fine for plain `C-u' to have
a different behavior from `C-u 4' or `M-4' for any given
command.  As long as the doc string makes the prefix arg
possibilities clear.

The fact that `C-u', when interpreted numerically, is
"burnt into our muscle memory" is important.  But it is
only important for commands that interpret the prefix
arg only numerically, and do not interpret plain `C-u'
in some other way.

The ability to provide different behaviors for plain
`C-u', plain `C-u C-u', plain `C-u C-u C-u', and plain
`-' is important - just as important as the ability to 
give different behaviors to a numeric prefix arg for
> 0, = 0, < 0, => 0, <= 0 cases.

It is wonderful that Emacs lets a command let users
distinguish `-' from `-1', just as it can let users
distinguish `-1' from `-2'.

This not an argument that commands should always or
often provide many, many alternative behaviors via
a prefix arg.  It's an argument that they should be
able to (and they are able to) use all the various
raw prefix-arg possibilities however they want.

There are plenty of commands for which a prefix
arg is not at all used numerically - commands for
which a numeric interpretation has no meaning.
Not all commands are like motion commands such as
`C-n'.

Even commands that can interpret a prefix arg
numerically can sometimes benefit from providing
additional interpretations for plain `C-u' etc.



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-17 16:57               ` Rusi
  2017-11-17 17:26                 ` Drew Adams
@ 2017-11-17 18:05                 ` Eli Zaretskii
  1 sibling, 0 replies; 69+ messages in thread
From: Eli Zaretskii @ 2017-11-17 18:05 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Fri, 17 Nov 2017 08:57:18 -0800 (PST)
> From: Rusi <rustompmody@gmail.com>
> 
> > Really?  That a lone C-u means an arg of 4 is burnt into our muscle
> > memory for decades.  Compare with "C-u C-n".  A command that receives
> > a numerical argument normally treats all of its arguments as numbers.
> > Breaking that in a single command sounds like a misfeature.
> 
> Org mode (at least) is full of functions for which C-u means change some behavior (C-u C-u changes more)

So is Emacs.  But AFAIR the rule is: if any argument is treated as a
number, then all of them are.  By contrast, you are talking about
commands where the argument is not treated as a number of repetitions,
but as a trigger for some variation on the default behavior, which is
not what I was talking about.



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-17  8:55       ` Gian Uberto Lauri
  2017-11-17  8:58         ` Gian Uberto Lauri
@ 2017-11-17 20:38         ` Marcin Borkowski
  1 sibling, 0 replies; 69+ messages in thread
From: Marcin Borkowski @ 2017-11-17 20:38 UTC (permalink / raw)
  To: Gian Uberto Lauri; +Cc: help-gnu-emacs, Bob Proulx


On 2017-11-17, at 09:55, Gian Uberto Lauri <saint@eng.it> wrote:

> M-0 M-t is undefined
>
> GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 2.24.30) of 2017-09-29

It works here.

GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.21) of 2017-10-02

Best,

-- 
Marcin Borkowski



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-17 16:19             ` Robert Pluim
@ 2017-11-17 20:41               ` Marcin Borkowski
  0 siblings, 0 replies; 69+ messages in thread
From: Marcin Borkowski @ 2017-11-17 20:41 UTC (permalink / raw)
  To: Robert Pluim; +Cc: help-gnu-emacs, Stefan Monnier


On 2017-11-17, at 17:19, Robert Pluim <rpluim@gmail.com> wrote:

> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
>>> C-u 0 M-t works fine.
>>
>> BTW, I'd argue that C-u M-t should work as well: currently it is treated
>> like C-u 4 M-t, but I think it's a poor choice.
>
> How would you distinguish that from someone actually typing C-u 4 M-t?
> The interactive arg is '4' in both cases, no?

No.

(info "(elisp) Prefix Command Arguments")

Best,

-- 
Marcin Borkowski



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-17 16:21           ` Drew Adams
@ 2017-11-17 20:52             ` Emanuel Berg
  0 siblings, 0 replies; 69+ messages in thread
From: Emanuel Berg @ 2017-11-17 20:52 UTC (permalink / raw)
  To: help-gnu-emacs

Drew Adams wrote:

>>>> By the way, what does `special' do?
>>>> ;; FIXME document SPECIAL. (defun transpose-subr (mover arg &optional special) "Document SPECIAL" - good idea :)
>>>
>>> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=29328
>>
>> Good. Now it says so in the source, I said
>> it here, and you said it on debbugs.
>> That should be enough.
>
> Alas, far from enough.
>
> The bug was was closed summarily, under the
> pretext that it's impossible to describe
> parameter SPECIAL, and that this is only an
> "internal subroutine" so it need not have
> complete doc.

If it is impossible to describe what it does
then what value (purpose) does it have? (I
confess I do not understand this from
the source.)

If `transpose-subr' is internal and for that
reason doesn't need documentation, whatever
logic now that is, why is there a docstring to
begin with? Now it is just confusing to have
a docstring and to look in vain for SPECIAL.

In programming, there isn't really any
"bike-shedding". Even a minor issue can bring
the whole thing down. Better to have the
intention to do everything as close to
perfection as possible. If you instead start
thinking "isn't there something better to do?"
- well, of course there is, but the result
might instead be nothing at all is ever done.

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-17 16:42             ` Eli Zaretskii
@ 2017-11-17 22:53               ` Stefan Monnier
  2017-11-17 23:02                 ` Emanuel Berg
  0 siblings, 1 reply; 69+ messages in thread
From: Stefan Monnier @ 2017-11-17 22:53 UTC (permalink / raw)
  To: help-gnu-emacs

>> > C-u 0 M-t works fine.
>> BTW, I'd argue that C-u M-t should work as well: currently it is treated
>> like C-u 4 M-t, but I think it's a poor choice.
> Really?  That a lone C-u means an arg of 4 is burnt into our muscle
> memory for decades.

Not sure who "our" refers to, but I sure don't belong to that group.

> Compare with "C-u C-n".  A command that receives
> a numerical argument normally treats all of its arguments as numbers.

But M-t already breaks this promise for the 0 case.

> Breaking that in a single command sounds like a misfeature.

That's a valid opinion, but I disagree with it.


        Stefan "who would use this principle in sdeveral other cases, so it
                wouldn't be the «single exception»"




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-17 16:03           ` Stefan Monnier
                               ` (2 preceding siblings ...)
       [not found]             ` <mailman.3897.1510936953.27995.help-gnu-emacs@gnu.org>
@ 2017-11-17 22:55             ` Stefan Monnier
  2017-11-17 23:09               ` Emanuel Berg
  2017-11-21 17:21               ` Tomas Nordin
  3 siblings, 2 replies; 69+ messages in thread
From: Stefan Monnier @ 2017-11-17 22:55 UTC (permalink / raw)
  To: help-gnu-emacs

>> C-u 0 M-t works fine.
> BTW, I'd argue that C-u M-t should work as well: currently it is treated
> like C-u 4 M-t, but I think it's a poor choice.

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.


        Stefan




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-17 22:53               ` Stefan Monnier
@ 2017-11-17 23:02                 ` Emanuel Berg
  0 siblings, 0 replies; 69+ messages in thread
From: Emanuel Berg @ 2017-11-17 23:02 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier wrote:

>> C-u M-t should work as well: currently it is
>> treated like C-u 4 M-t, but I think it's
>> a poor choice. Really? That a lone C-u means
>> an arg of 4 is burnt into our muscle memory
>> for decades.
>
> Not sure who "our" refers to, but I sure
> don't belong to that group.

I'm not even sure "an arg of 4" is something
than *can* enter the muscle memory :)

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-17 22:55             ` Stefan Monnier
@ 2017-11-17 23:09               ` Emanuel Berg
  2017-11-21 17:21               ` Tomas Nordin
  1 sibling, 0 replies; 69+ messages in thread
From: Emanuel Berg @ 2017-11-17 23:09 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier wrote:

>> C-u 0 M-t works fine. BTW, I'd argue
>> that C-u M-t should work as well: currently it
>> is treated like C-u 4 M-t, but I think
>> it's a poor choice.
>
> 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.

Good idea. Personally I think the region is
slow and bulky and transpose is fast and light,
so they don't mesh well IMO, however as it
stands now it would make sense b/c no one sets
the region and then starts transposing words
with no intention of having the region
influence what happens.

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
       [not found]   ` <mailman.3847.1510879170.27995.help-gnu-emacs@gnu.org>
@ 2017-11-17 23:34     ` Joseph C. Fineman
  2017-11-18  0:05       ` Emanuel Berg
       [not found]       ` <mailman.3932.1510963563.27995.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 69+ messages in thread
From: Joseph C. Fineman @ 2017-11-17 23:34 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <moasen@zoho.com> writes:

> Joseph C. Fineman wrote:
>
>>> TL;DR: How can I transpose words jumping
>>> over middle words?
>>
>> I think that, rather than expending
>> cleverness on that particular problem, and
>> then trying to remember the result,I would
>> write a command that solved a more general
>> problem

> Unless there is DWIM interface I'd say the
> general solution can be less easy to remember
> as you need to feed it argument(s) and/or tweak
> it for the particular situation. Which is
> slower than the specific solution, both
> invocation and execution, as well.

In this case, there are no arguments or tweaking involved.
-- 
---  Joe Fineman    joe_f@verizon.net

||:  Ambition is the wish to be the top worm in the can.  :||


^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
       [not found]   ` <mailman.3856.1510903218.27995.help-gnu-emacs@gnu.org>
@ 2017-11-17 23:35     ` Joseph C. Fineman
  0 siblings, 0 replies; 69+ messages in thread
From: Joseph C. Fineman @ 2017-11-17 23:35 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> writes:

>> From: joe_f@verizon.net (Joseph C. Fineman)
>> Date: Thu, 16 Nov 2017 18:05:01 -0500
>> 
>> I think that, rather than expending cleverness on that particular
>> problem, and then trying to remember the result, I would write a command
>> that solved a more general problem & would be easy to remember.  Namely,
>> after I set the mark successively at the beginning and end of a passage,
>> and then at the beginning of another passage, and then going to the end
>> of the latter passage, it would, on being called, exchange the former
>> with the latter passage (using the mark ring).
>
> Isn't that what the zero argument to M-t already does?

No, as far as I can tell from the manual.
-- 
---  Joe Fineman    joe_f@verizon.net

||:  A man is only a woman's way of inseminating another woman.  :||


^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-17 23:34     ` Joseph C. Fineman
@ 2017-11-18  0:05       ` Emanuel Berg
       [not found]       ` <mailman.3932.1510963563.27995.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 69+ messages in thread
From: Emanuel Berg @ 2017-11-18  0:05 UTC (permalink / raw)
  To: help-gnu-emacs

Joseph C. Fineman wrote:

> In this case, there are no arguments or
> tweaking involved.

But how is it then a general solution?

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16  0:04 ` Emanuel Berg
@ 2017-11-18 17:07   ` ken
  2017-11-18 19:34     ` Emanuel Berg
  0 siblings, 1 reply; 69+ messages in thread
From: ken @ 2017-11-18 17:07 UTC (permalink / raw)
  To: help-gnu-emacs

On 11/15/2017 07:04 PM, Emanuel Berg wrote:
>> How can I transpose words jumping over
>> middle words?
> (defun transpose-over-word ()
>    (interactive)
>    (transpose-subr 'forward-word 2)
>    (backward-word 1)
>    (transpose-subr 'forward-word -1)
>    )
> (local-set-key (kbd "M-a") #'transpose-over-word) ; try it

I prefer this method because it's straightforward and easy to 
understand, plus, it leaves the mark where it was.  However, in 
instances in which the middle word is at the end of the line, the result 
is unexpected:

With the point after the '3':

1 2 3 4
5 6 7 8

invoking M-a yields this:

1 2 5
4 3 6 7 8




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-16 22:26     ` Bob Proulx
  2017-11-17  5:00       ` Yuri Khan
  2017-11-17  8:55       ` Gian Uberto Lauri
@ 2017-11-18 17:11       ` Robert Thorpe
  2 siblings, 0 replies; 69+ messages in thread
From: Robert Thorpe @ 2017-11-18 17:11 UTC (permalink / raw)
  To: Bob Proulx; +Cc: help-gnu-emacs

Bob Proulx <bob@proulx.com> writes:

> One must move to the beginning of one word,
> set the mark, move to the beginning of the other word, M-0 M-t or
> C-u 0 ESC t if I can't make the meta work on that keyboard.

As a sidenote....

Let's say you have a keyboard where meta is awkward.  You don't need to
use "C-u 0" you can use just "C-0".  By default "C-u 0", "C-0" and "M-0" all do
the same thing.  Also, you can use "C-[" instead of ESC, which is often
easier on laptop keyboard with small ESC keys.  If I were on a keyboard
with a tricky meta key I would type "C-0 C-[ t".

BR,
Robert Thorpe



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-18 17:07   ` ken
@ 2017-11-18 19:34     ` Emanuel Berg
  2017-11-19  2:06       ` ken
  0 siblings, 1 reply; 69+ messages in thread
From: Emanuel Berg @ 2017-11-18 19:34 UTC (permalink / raw)
  To: help-gnu-emacs

ken wrote:

> I prefer this method because it's
> straightforward and easy to understand, plus,
> it leaves the mark where it was. However, in
> instances in which the middle word is at the
> end of the line, the result is unexpected:
>
> With the point after the '3':
>
> 1 2 3 4
> 5 6 7 8
>
> invoking M-a yields this:
>
> 1 2 5
> 4 3 6 7 8

You are right, here the other function is
better

(defun transpose-over-word-2 ()
  (interactive)
  (backward-char 1)
  (push-mark)
  (forward-word 3)
  (backward-char 1)
  (transpose-words 0)
  (forward-word 1) )

(local-set-key (kbd "M-a") #'transpose-over-word-2) ; try it

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
       [not found]       ` <mailman.3932.1510963563.27995.help-gnu-emacs@gnu.org>
@ 2017-11-18 22:55         ` Joseph C. Fineman
  2017-11-18 23:57           ` Emanuel Berg
  0 siblings, 1 reply; 69+ messages in thread
From: Joseph C. Fineman @ 2017-11-18 22:55 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <moasen@zoho.com> writes:

> Joseph C. Fineman wrote:
>
>> In this case, there are no arguments or
>> tweaking involved.
>
> But how is it then a general solution?

It works with passages of arbitrary length.
-- 
---  Joe Fineman    joe_f@verizon.net

||:  Imprudent sexual activity completes the life cycles of many  :||
||:  pests.                                                       :||


^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-18 22:55         ` Joseph C. Fineman
@ 2017-11-18 23:57           ` Emanuel Berg
  0 siblings, 0 replies; 69+ messages in thread
From: Emanuel Berg @ 2017-11-18 23:57 UTC (permalink / raw)
  To: help-gnu-emacs

Joseph C. Fineman wrote:

>> But how is it then a general solution?
>
> It works with passages of arbitrary length.

OK :)

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-18 19:34     ` Emanuel Berg
@ 2017-11-19  2:06       ` ken
  2017-11-19  2:15         ` Emanuel Berg
  0 siblings, 1 reply; 69+ messages in thread
From: ken @ 2017-11-19  2:06 UTC (permalink / raw)
  To: help-gnu-emacs

On 11/18/2017 02:34 PM, Emanuel Berg wrote:
> ken wrote:
>
>> I prefer this method because it's
>> straightforward and easy to understand, plus,
>> it leaves the mark where it was. However, in
>> instances in which the middle word is at the
>> end of the line, the result is unexpected:
>>
>> With the point after the '3':
>>
>> 1 2 3 4
>> 5 6 7 8
>>
>> invoking M-a yields this:
>>
>> 1 2 5
>> 4 3 6 7 8
> You are right, here the other function is
> better
>
> (defun transpose-over-word-2 ()
>    (interactive)
>    (backward-char 1)
>    (push-mark)
>    (forward-word 3)
>    (backward-char 1)
>    (transpose-words 0)
>    (forward-word 1) )
>
> (local-set-key (kbd "M-a") #'transpose-over-word-2) ; try it
>
That's great.  Thanks.  It's  quite nice that the point remains in 
place.  Is there perhaps a way to return the mark to where it was prior 
to invoking "M-a" so that it, too, remains in place?




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-19  2:06       ` ken
@ 2017-11-19  2:15         ` Emanuel Berg
  2017-11-19  2:34           ` John Mastro
  0 siblings, 1 reply; 69+ messages in thread
From: Emanuel Berg @ 2017-11-19  2:15 UTC (permalink / raw)
  To: help-gnu-emacs

ken wrote:

> That's great.  Thanks.  It's  quite nice that
> the point remains in place.  Is there perhaps
> a way to return the mark to where it was
> prior to invoking "M-a" so that it, too,
> remains in place?

I'm not aware of any "save-mark-excursion" as
in `save-excursion' or `save-restriction', but
what about simply `pop-mark' last thing?

(defun transpose-over-word-2 ()
  (interactive)
  (backward-char 1)
  (push-mark)
  (forward-word 3)
  (backward-char 1)
  (transpose-words 0)
  (forward-word 1)
  (pop-mark) )

Or perhaps it should be done after
`transpose-words', as that is what acts on the
region...

If that doesn't work saving it in a `let' first
and then pushing it back should work...

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-19  2:15         ` Emanuel Berg
@ 2017-11-19  2:34           ` John Mastro
  2017-11-19  3:39             ` Emanuel Berg
  0 siblings, 1 reply; 69+ messages in thread
From: John Mastro @ 2017-11-19  2:34 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

Emanuel Berg <moasen@zoho.com> wrote:
> ken wrote:
>
>> That's great.  Thanks.  It's  quite nice that
>> the point remains in place.  Is there perhaps
>> a way to return the mark to where it was
>> prior to invoking "M-a" so that it, too,
>> remains in place?
>
> I'm not aware of any "save-mark-excursion" as
> in `save-excursion' or `save-restriction', but
> what about simply `pop-mark' last thing?

There is `save-mark-and-excursion', if that helps.

        John



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-19  2:34           ` John Mastro
@ 2017-11-19  3:39             ` Emanuel Berg
  2017-11-19  4:37               ` Drew Adams
  0 siblings, 1 reply; 69+ messages in thread
From: Emanuel Berg @ 2017-11-19  3:39 UTC (permalink / raw)
  To: help-gnu-emacs

John Mastro wrote:

>>> That's great. Thanks. It's quite nice that
>>> the point remains in place. Is there
>>> perhaps a way to return the mark to where
>>> it was prior to invoking "M-a" so that it,
>>> too, remains in place?
>>
>> I'm not aware of any "save-mark-excursion"
>> as in `save-excursion' or
>> `save-restriction', but what about simply
>> `pop-mark' last thing?
>
> There is `save-mark-and-excursion', if
> that helps.

Not here it isn't :)

    GNU Emacs 24.4.1
    (arm-unknown-linux-gnueabihf, GTK+ Version
    3.14.5) of 2015-03-10 on bm-wb-01, modified
    by Debian

Where do you have it?

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* RE: Transposing words over middle words
  2017-11-19  3:39             ` Emanuel Berg
@ 2017-11-19  4:37               ` Drew Adams
  2017-11-19  4:58                 ` Drew Adams
  2017-11-19 14:56                 ` Emanuel Berg
  0 siblings, 2 replies; 69+ messages in thread
From: Drew Adams @ 2017-11-19  4:37 UTC (permalink / raw)
  To: Emanuel Berg, help-gnu-emacs

> > There is `save-mark-and-excursion', if
> > that helps.
> 
> Not here it isn't :)   GNU Emacs 24.4.1
> Where do you have it?

It was introduced in Emacs 25.  It is what used
to be called `save-excursion'. ;-)

Why they didn't instead leave `save-excursion' with
its longstanding behavior and create a new function
(e.g. `save-point' or whatever) to do what the
Emacs 25+ `save-excursion' does, I don't know.  That
would not have been backward incompatible.

The Emacs NEWS says only this:

 ** 'save-excursion' does not save&restore the mark any more.
 Use 'save-mark-and-excursion' if you want the old behavior.

Of course, if you want the old behavior in both
old and new releases, now you have to call one
or the other conditionally, testing
(fboundp `save-mark-and-excursion').



^ permalink raw reply	[flat|nested] 69+ messages in thread

* RE: Transposing words over middle words
  2017-11-19  4:37               ` Drew Adams
@ 2017-11-19  4:58                 ` Drew Adams
  2017-11-19 14:56                 ` Emanuel Berg
  1 sibling, 0 replies; 69+ messages in thread
From: Drew Adams @ 2017-11-19  4:58 UTC (permalink / raw)
  To: help-gnu-emacs

> It was introduced in Emacs 25.  It is what used
> to be called `save-excursion'. ;-)
> 
> Why they didn't instead leave `save-excursion' with
> its longstanding behavior and create a new function
> (e.g. `save-point' or whatever) to do what the
> Emacs 25+ `save-excursion' does, I don't know.  That
> would not have been backward incompatible.
> 
> The Emacs NEWS says only this:
> 
>  ** 'save-excursion' does not save&restore the mark any more.
>  Use 'save-mark-and-excursion' if you want the old behavior.
> 
> Of course, if you want the old behavior in both
> old and new releases, now you have to call one
> or the other conditionally, testing
> (fboundp `save-mark-and-excursion').

This seems to be what was responsible for the change:

commit 599ca626d760215b090012c69c749d391cfd6fbe
Author: Stefan Monnier <address@hidden>
Date:   Wed Mar 25 09:47:12 2015 -0400

    `save-excursion' does not save&restore the mark any more

Searching the emacs-devel mailing-list archives for
`save-mark-and-excursion' I don't find any discussion
about introducing it.  I find only an occurrence that
mentions that commit:

http://lists.gnu.org/archive/html/emacs-devel/2015-12/msg01596.html

Searching the bug list I find only two occurrences,
which are from the year after that 2015 commit.



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-19  4:37               ` Drew Adams
  2017-11-19  4:58                 ` Drew Adams
@ 2017-11-19 14:56                 ` Emanuel Berg
  1 sibling, 0 replies; 69+ messages in thread
From: Emanuel Berg @ 2017-11-19 14:56 UTC (permalink / raw)
  To: help-gnu-emacs

Drew Adams wrote:

>>> There is `save-mark-and-excursion', if
>>> that helps.
>>
>> Not here it isn't :) GNU Emacs 24.4.1 Where
>> do you have it?
>
> It was introduced in Emacs 25. It is what
> used to be called `save-excursion'. ;-)

OK, so I wasn't unaware of such a function.
I was unaware that a function I was aware of
also did that. Only now that has changed :)

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-17 22:55             ` Stefan Monnier
  2017-11-17 23:09               ` Emanuel Berg
@ 2017-11-21 17:21               ` Tomas Nordin
  2017-11-22 18:18                 ` Arnaldo Mandel
  2017-11-22 21:33                 ` Stefan Monnier
  1 sibling, 2 replies; 69+ messages in thread
From: Tomas Nordin @ 2017-11-21 17:21 UTC (permalink / raw)
  To: help-gnu-emacs


> 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)

;;; remove the hack with this:
;; (advice-remove 'transpose-subr #'tn-transpose-dwim-advice)



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-21 17:21               ` Tomas Nordin
@ 2017-11-22 18:18                 ` Arnaldo Mandel
  2017-11-22 19:15                   ` Emanuel Berg
  2017-11-22 21:33                 ` Stefan Monnier
  1 sibling, 1 reply; 69+ messages in thread
From: Arnaldo Mandel @ 2017-11-22 18:18 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

Here is my take on this function.  It is slightly different from what came
before in that the cursor should be in the middle word, and it stays there.

(defun transpose-over-word ()
  "Transposes the two words adjacent to the one containing point."
  (interactive)
  (let ((p (point)))
    (forward-word 1)
    (setq p (- (point) p))
    (backward-word 1)
    (transpose-words  2)
    (backward-word 2)
    (transpose-words 1)
    (backward-char p)))


On Tue, Nov 21, 2017 at 3:21 PM, Tomas Nordin <tomasn@posteo.net> wrote:

>
> > 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)
>
> ;;; remove the hack with this:
> ;; (advice-remove 'transpose-subr #'tn-transpose-dwim-advice)
>
>


^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-22 18:18                 ` Arnaldo Mandel
@ 2017-11-22 19:15                   ` Emanuel Berg
  0 siblings, 0 replies; 69+ messages in thread
From: Emanuel Berg @ 2017-11-22 19:15 UTC (permalink / raw)
  To: help-gnu-emacs

Arnaldo Mandel wrote:

> Here is my take on this function. It is
> slightly different from what came before in
> that the cursor should be in the middle word,
> and it stays there.

It seems to go forward one char?
Otherwise seems good, passes the newline
test :)

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Transposing words over middle words
  2017-11-21 17:21               ` Tomas Nordin
  2017-11-22 18:18                 ` Arnaldo Mandel
@ 2017-11-22 21:33                 ` Stefan Monnier
  1 sibling, 0 replies; 69+ messages in thread
From: Stefan Monnier @ 2017-11-22 21:33 UTC (permalink / raw)
  To: help-gnu-emacs

>> 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")))




^ permalink raw reply related	[flat|nested] 69+ messages in thread

end of thread, other threads:[~2017-11-22 21:33 UTC | newest]

Thread overview: 69+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-15 23:17 Transposing words over middle words Bob Proulx
2017-11-15 23:35 ` Eric Abrahamsen
2017-11-16  6:03   ` Emanuel Berg
2017-11-16  0:04 ` Emanuel Berg
2017-11-18 17:07   ` ken
2017-11-18 19:34     ` Emanuel Berg
2017-11-19  2:06       ` ken
2017-11-19  2:15         ` Emanuel Berg
2017-11-19  2:34           ` John Mastro
2017-11-19  3:39             ` Emanuel Berg
2017-11-19  4:37               ` Drew Adams
2017-11-19  4:58                 ` Drew Adams
2017-11-19 14:56                 ` Emanuel Berg
2017-11-16 19:34 ` Charles A. Roelli
2017-11-16 19:41   ` Emanuel Berg
2017-11-16 20:09   ` Marcin Borkowski
2017-11-16 21:15     ` Emanuel Berg
2017-11-16 22:55       ` Bob Proulx
2017-11-16 23:02         ` Emanuel Berg
2017-11-16 21:18     ` Emanuel Berg
2017-11-16 22:43       ` Drew Adams
2017-11-16 22:59         ` Emanuel Berg
2017-11-17 16:21           ` Drew Adams
2017-11-17 20:52             ` Emanuel Berg
2017-11-16 22:28   ` Bob Proulx
     [not found] ` <mailman.3765.1510789425.27995.help-gnu-emacs@gnu.org>
2017-11-16 22:02   ` Michael Piotrowski
2017-11-16 23:00     ` Bob Proulx
2017-11-16 23:29     ` Eric Abrahamsen
2017-11-16 23:30       ` Eric Abrahamsen
2017-11-17  0:27         ` put it in MELPA (was: Re: Transposing words over middle words) Emanuel Berg
2017-11-17  0:30           ` put it in MELPA Eric Abrahamsen
2017-11-17 15:16           ` put it in MELPA (was: Re: Transposing words over middle words) Tim Visher
     [not found] <mailman.3764.1510787840.27995.help-gnu-emacs@gnu.org>
2017-11-16  7:04 ` Transposing words over middle words Loris Bennett
2017-11-16  8:41   ` Joost Kremers
2017-11-16  8:47     ` Joost Kremers
2017-11-16 16:06   ` Eli Zaretskii
2017-11-16 22:26     ` Bob Proulx
2017-11-17  5:00       ` Yuri Khan
2017-11-17  5:08         ` Emanuel Berg
2017-11-17  8:55       ` Gian Uberto Lauri
2017-11-17  8:58         ` Gian Uberto Lauri
2017-11-17  9:10           ` Eli Zaretskii
2017-11-17  9:35             ` Gian Uberto Lauri
2017-11-17 16:03           ` Stefan Monnier
2017-11-17 16:19             ` Robert Pluim
2017-11-17 20:41               ` Marcin Borkowski
2017-11-17 16:42             ` Eli Zaretskii
2017-11-17 22:53               ` Stefan Monnier
2017-11-17 23:02                 ` Emanuel Berg
     [not found]             ` <mailman.3897.1510936953.27995.help-gnu-emacs@gnu.org>
2017-11-17 16:57               ` Rusi
2017-11-17 17:26                 ` Drew Adams
2017-11-17 18:05                 ` Eli Zaretskii
2017-11-17 22:55             ` Stefan Monnier
2017-11-17 23:09               ` Emanuel Berg
2017-11-21 17:21               ` Tomas Nordin
2017-11-22 18:18                 ` Arnaldo Mandel
2017-11-22 19:15                   ` Emanuel Berg
2017-11-22 21:33                 ` Stefan Monnier
2017-11-17 20:38         ` Marcin Borkowski
2017-11-18 17:11       ` Robert Thorpe
2017-11-16 21:55 ` Michael Piotrowski
2017-11-16 23:05 ` Joseph C. Fineman
2017-11-17  0:39   ` Emanuel Berg
2017-11-17  7:19   ` Eli Zaretskii
     [not found]   ` <mailman.3847.1510879170.27995.help-gnu-emacs@gnu.org>
2017-11-17 23:34     ` Joseph C. Fineman
2017-11-18  0:05       ` Emanuel Berg
     [not found]       ` <mailman.3932.1510963563.27995.help-gnu-emacs@gnu.org>
2017-11-18 22:55         ` Joseph C. Fineman
2017-11-18 23:57           ` Emanuel Berg
     [not found]   ` <mailman.3856.1510903218.27995.help-gnu-emacs@gnu.org>
2017-11-17 23:35     ` Joseph C. Fineman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).