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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ 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; 32+ 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] 32+ messages in thread

end of thread, other threads:[~2017-11-19 14:56 UTC | newest]

Thread overview: 32+ 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

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