Gnus development mailing list
 help / color / mirror / Atom feed
* message-beginning-of-line behaves a bit strange
@ 2022-01-26 21:17 Uwe Brauer
  2022-01-26 21:27 ` Emanuel Berg
  2022-01-26 21:30 ` Eric Abrahamsen
  0 siblings, 2 replies; 12+ messages in thread
From: Uwe Brauer @ 2022-01-26 21:17 UTC (permalink / raw)
  To: ding


Hi

I want to write a simple function that inserts always a specific word at the beginning of the subject line, either

    1. If I want to compose a message and the subject is empty

    2. Or I reply to message and the subject is not empty.

So if I try 

(message-goto-subject) the cursor jumps 

    1. either (for an empty subject)
       Subject:
               ^
       so I could insert the word

    2. If the subject is not empty then the cursor jumps to
       Subject: stuff
                     ^
       So I have to call message-beginning-of-line and obtain
       Subject: stuff
               ^

The problem is if in the first case I also run message-beginning-of-line I obtain
      
      Subject:
      ^

Which is not good. Is there any possibility to have
message-beginning-of-line always to jump to
      Subject:
              ^

Thanks

Uwe Brauer



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

* Re: message-beginning-of-line behaves a bit strange
  2022-01-26 21:17 message-beginning-of-line behaves a bit strange Uwe Brauer
@ 2022-01-26 21:27 ` Emanuel Berg
  2022-01-27  4:53   ` Emanuel Berg
  2022-01-27  7:47   ` Uwe Brauer
  2022-01-26 21:30 ` Eric Abrahamsen
  1 sibling, 2 replies; 12+ messages in thread
From: Emanuel Berg @ 2022-01-26 21:27 UTC (permalink / raw)
  To: ding

Uwe Brauer wrote:

> Which is not good. Is there any possibility to have
> message-beginning-of-line always to jump to
>       Subject:
>               ^

This

Subject: An offer you can't refuse ...
         ^

is what happens I think? That's not what you want?

I have this, what you ask for happens by default, but if point
didn't change, the user meant something else so it moves to
the beginning of the line instead, disregarding the
`message-mode' and header context.

(defun message-bol ()
  (interactive)
  (let ((beg (point))
        (end (progn (message-beginning-of-line) (point))) )
    (when (= beg end)
      (forward-line 0) )))

-- 
underground experts united
https://dataswamp.org/~incal



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

* Re: message-beginning-of-line behaves a bit strange
  2022-01-26 21:17 message-beginning-of-line behaves a bit strange Uwe Brauer
  2022-01-26 21:27 ` Emanuel Berg
@ 2022-01-26 21:30 ` Eric Abrahamsen
  2022-01-27  7:48   ` Uwe Brauer
  1 sibling, 1 reply; 12+ messages in thread
From: Eric Abrahamsen @ 2022-01-26 21:30 UTC (permalink / raw)
  To: ding

Uwe Brauer <oub@mat.ucm.es> writes:

> Hi
>
> I want to write a simple function that inserts always a specific word at the beginning of the subject line, either
>
>     1. If I want to compose a message and the subject is empty
>
>     2. Or I reply to message and the subject is not empty.
>
> So if I try 
>
> (message-goto-subject) the cursor jumps 
>
>     1. either (for an empty subject)
>        Subject:
>                ^
>        so I could insert the word
>
>     2. If the subject is not empty then the cursor jumps to
>        Subject: stuff
>                      ^
>        So I have to call message-beginning-of-line and obtain
>        Subject: stuff

Try `message-beginning-of-header' instead. Alternately, fooling with the
value of (variable) `message-beginning-of-line' while calling (function)
`message-beginning-of-line'.



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

* Re: message-beginning-of-line behaves a bit strange
  2022-01-26 21:27 ` Emanuel Berg
@ 2022-01-27  4:53   ` Emanuel Berg
  2022-01-27  7:47   ` Uwe Brauer
  1 sibling, 0 replies; 12+ messages in thread
From: Emanuel Berg @ 2022-01-27  4:53 UTC (permalink / raw)
  To: ding

> (defun message-bol ()
>   (interactive)
>   (let ((beg (point))
>         (end (progn (message-beginning-of-line) (point))) )
>     (when (= beg end)
>       (forward-line 0) )))

... which is a version of

(defun back-to-dwim ()
  (interactive)
  (scroll-right)
  (let ((beg (point)))
    (back-to-indentation)
    (when (= beg (point))
      (beginning-of-line) )))

-- 
underground experts united
https://dataswamp.org/~incal



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

* Re: message-beginning-of-line behaves a bit strange
  2022-01-26 21:27 ` Emanuel Berg
  2022-01-27  4:53   ` Emanuel Berg
@ 2022-01-27  7:47   ` Uwe Brauer
  2022-01-27 11:29     ` Emanuel Berg
  1 sibling, 1 reply; 12+ messages in thread
From: Uwe Brauer @ 2022-01-27  7:47 UTC (permalink / raw)
  To: ding

[-- Attachment #1: Type: text/plain, Size: 967 bytes --]


> Uwe Brauer wrote:

> This

> Subject: An offer you can't refuse ...
>          ^

> is what happens I think? That's not what you want?

> I have this, what you ask for happens by default, but if point
> didn't change, the user meant something else so it moves to
> the beginning of the line instead, disregarding the
> `message-mode' and header context.

> (defun message-bol ()
>   (interactive)
>   (let ((beg (point))
>         (end (progn (message-beginning-of-line) (point))) )
>     (when (= beg end)
>       (forward-line 0) )))

Thanks, so I did 

(defun my-add-subject-test2 ()
  (interactive)
  (message-goto-subject)
  (message-bol)
  (insert "[Test]2 "))


(defun message-bol ()
  (interactive)
  (let ((beg (point))
        (end (progn (message-beginning-of-line) (point))) )
    (when (= beg end)
      (forward-line 0) )))


But this did not work for an empty subject line, while Eric's suggestion does. 😉

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]

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

* Re: message-beginning-of-line behaves a bit strange
  2022-01-26 21:30 ` Eric Abrahamsen
@ 2022-01-27  7:48   ` Uwe Brauer
  2022-01-27  8:31     ` Robert Pluim
  2022-01-27 11:38     ` Emanuel Berg
  0 siblings, 2 replies; 12+ messages in thread
From: Uwe Brauer @ 2022-01-27  7:48 UTC (permalink / raw)
  To: ding

[-- Attachment #1: Type: text/plain, Size: 504 bytes --]


> Uwe Brauer <oub@mat.ucm.es> writes:

> Try `message-beginning-of-header' instead. Alternately, fooling with the
> value of (variable) `message-beginning-of-line' while calling (function)
> `message-beginning-of-line'.

Great, I did

(defun my-add-subject-test ()
  (interactive)
  (message-goto-subject)
;  (message-beginning-of-line)
  (message-beginning-of-header 'subject)
  (insert "[Test] "))

And this work nicely for both, empty and non empty subject lines!

Thanks 😁



[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]

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

* Re: message-beginning-of-line behaves a bit strange
  2022-01-27  7:48   ` Uwe Brauer
@ 2022-01-27  8:31     ` Robert Pluim
  2022-01-27 11:38     ` Emanuel Berg
  1 sibling, 0 replies; 12+ messages in thread
From: Robert Pluim @ 2022-01-27  8:31 UTC (permalink / raw)
  To: ding

>>>>> On Thu, 27 Jan 2022 08:48:26 +0100, Uwe Brauer <oub@mat.ucm.es> said:

    >> Uwe Brauer <oub@mat.ucm.es> writes:

    >> Try `message-beginning-of-header' instead. Alternately, fooling with the
    >> value of (variable) `message-beginning-of-line' while calling (function)
    >> `message-beginning-of-line'.

    Uwe> Great, I did

    Uwe> (defun my-add-subject-test ()
    Uwe>   (interactive)
    Uwe>   (message-goto-subject)
    Uwe> ;  (message-beginning-of-line)
    Uwe>   (message-beginning-of-header 'subject)
    Uwe>   (insert "[Test] "))

Strictly speaking that should be

(message-beginning-of-header t)

but as long as the argument is non-nil I think youʼre OK.

Robert
-- 


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

* Re: message-beginning-of-line behaves a bit strange
  2022-01-27  7:47   ` Uwe Brauer
@ 2022-01-27 11:29     ` Emanuel Berg
  2022-01-28  7:58       ` Uwe Brauer
  0 siblings, 1 reply; 12+ messages in thread
From: Emanuel Berg @ 2022-01-27 11:29 UTC (permalink / raw)
  To: ding

Uwe Brauer wrote:

> Thanks, so I did 
>
> (defun my-add-subject-test2 ()
>   (interactive)
>   (message-goto-subject)
>   (message-bol)
>   (insert "[Test]2 "))
>
> (defun message-bol ()
>   (interactive)
>   (let ((beg (point))
>         (end (progn (message-beginning-of-line) (point))) )
>     (when (= beg end)
>       (forward-line 0) )))
>
> But this did not work for an empty subject line, while
> Eric's suggestion does.

No one suggested it should be used like that either ...

-- 
underground experts united
https://dataswamp.org/~incal



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

* Re: message-beginning-of-line behaves a bit strange
  2022-01-27  7:48   ` Uwe Brauer
  2022-01-27  8:31     ` Robert Pluim
@ 2022-01-27 11:38     ` Emanuel Berg
  2022-01-27 16:31       ` Eric Abrahamsen
  2022-01-28  8:00       ` Uwe Brauer
  1 sibling, 2 replies; 12+ messages in thread
From: Emanuel Berg @ 2022-01-27 11:38 UTC (permalink / raw)
  To: ding

Uwe Brauer wrote:

>> Uwe Brauer <oub@mat.ucm.es> writes:
>
>> Try `message-beginning-of-header' instead. Alternately,
>> fooling with the value of (variable)
>> `message-beginning-of-line' while calling (function)
>> `message-beginning-of-line'.
>
> Great, I did
>
> (defun my-add-subject-test ()
>   (interactive)
>   (message-goto-subject)
> ;  (message-beginning-of-line)
>   (message-beginning-of-header 'subject)
>   (insert "[Test] "))
>
> And this work nicely for both, empty and non empty
> subject lines!

?! Subject twice?

What kind of code is that? I mean

  (message-goto-subject)
  (message-beginning-of-header 'subject)

Much better:

`message-goto-subject' could have an optional formal parameter
BEG so when the argument is non-nil it does
(message-beginning-of-header 'subject) last.

But at the very least (message-beginning-of-header 'subject)
should imply (message-goto-subject) first.

Or one could make HANDLE-FOLDED optional and when nil, go to
the current line's header beginning.

Subject should appear one time!

-- 
underground experts united
https://dataswamp.org/~incal



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

* Re: message-beginning-of-line behaves a bit strange
  2022-01-27 11:38     ` Emanuel Berg
@ 2022-01-27 16:31       ` Eric Abrahamsen
  2022-01-28  8:00       ` Uwe Brauer
  1 sibling, 0 replies; 12+ messages in thread
From: Eric Abrahamsen @ 2022-01-27 16:31 UTC (permalink / raw)
  To: ding

Emanuel Berg <moasenwood@zoho.eu> writes:

> Uwe Brauer wrote:
>
>>> Uwe Brauer <oub@mat.ucm.es> writes:
>>
>>> Try `message-beginning-of-header' instead. Alternately,
>>> fooling with the value of (variable)
>>> `message-beginning-of-line' while calling (function)
>>> `message-beginning-of-line'.
>>
>> Great, I did
>>
>> (defun my-add-subject-test ()
>>   (interactive)
>>   (message-goto-subject)
>> ;  (message-beginning-of-line)
>>   (message-beginning-of-header 'subject)
>>   (insert "[Test] "))
>>
>> And this work nicely for both, empty and non empty
>> subject lines!
>
> ?! Subject twice?
>
> What kind of code is that? I mean
>
>   (message-goto-subject)
>   (message-beginning-of-header 'subject)
>
> Much better:
>
> `message-goto-subject' could have an optional formal parameter
> BEG so when the argument is non-nil it does
> (message-beginning-of-header 'subject) last.
>
> But at the very least (message-beginning-of-header 'subject)
> should imply (message-goto-subject) first.
>
> Or one could make HANDLE-FOLDED optional and when nil, go to
> the current line's header beginning.
>
> Subject should appear one time!

As Robert points out, the 'subject argument is actually meaningless,
the argument's actual name is HANDLE-FOLDED.
`message-beginning-of-header' acts on whatever header point is on, it
doesn't differentiate between headers.



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

* Re: message-beginning-of-line behaves a bit strange
  2022-01-27 11:29     ` Emanuel Berg
@ 2022-01-28  7:58       ` Uwe Brauer
  0 siblings, 0 replies; 12+ messages in thread
From: Uwe Brauer @ 2022-01-28  7:58 UTC (permalink / raw)
  To: ding

[-- Attachment #1: Type: text/plain, Size: 667 bytes --]

>>> "EB" == Emanuel Berg <moasenwood@zoho.eu> writes:

> Uwe Brauer wrote:
>> Thanks, so I did 
>> 
>> (defun my-add-subject-test2 ()
>> (interactive)
>> (message-goto-subject)
>> (message-bol)
>> (insert "[Test]2 "))
>> 
>> (defun message-bol ()
>> (interactive)
>> (let ((beg (point))
>> (end (progn (message-beginning-of-line) (point))) )
>> (when (= beg end)
>> (forward-line 0) )))
>> 
>> But this did not work for an empty subject line, while
>> Eric's suggestion does.

> No one suggested it should be used like that either ...

Then I did and still don't understand your earlier message about the purpose of this new function. Anyhow.

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]

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

* Re: message-beginning-of-line behaves a bit strange
  2022-01-27 11:38     ` Emanuel Berg
  2022-01-27 16:31       ` Eric Abrahamsen
@ 2022-01-28  8:00       ` Uwe Brauer
  1 sibling, 0 replies; 12+ messages in thread
From: Uwe Brauer @ 2022-01-28  8:00 UTC (permalink / raw)
  To: ding

[-- Attachment #1: Type: text/plain, Size: 1365 bytes --]

>>> "EB" == Emanuel Berg <moasenwood@zoho.eu> writes:

> Uwe Brauer wrote:
>>> Uwe Brauer <oub@mat.ucm.es> writes:
>> 
>>> Try `message-beginning-of-header' instead. Alternately,
>>> fooling with the value of (variable)
>>> `message-beginning-of-line' while calling (function)
>>> `message-beginning-of-line'.
>> 
>> Great, I did
>> 
>> (defun my-add-subject-test ()
>> (interactive)
>> (message-goto-subject)
>> ;  (message-beginning-of-line)
>> (message-beginning-of-header 'subject)
>> (insert "[Test] "))
>> 
>> And this work nicely for both, empty and non empty
>> subject lines!

> ?! Subject twice?

> What kind of code is that? I mean

>   (message-goto-subject)
>   (message-beginning-of-header 'subject)

> Much better:

> `message-goto-subject' could have an optional formal parameter
> BEG so when the argument is non-nil it does
> (message-beginning-of-header 'subject) last.


That is a proposal?


> But at the very least (message-beginning-of-header 'subject)
> should imply (message-goto-subject) first.

> Or one could make HANDLE-FOLDED optional and when nil, go to
> the current line's header beginning.

> Subject should appear one time!

So the correct code is 

(defun my-add-subject-test ()
(interactive)
(message-goto-subject)
(message-beginning-of-header t)
(insert "[Test] "))

Ok!

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]

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

end of thread, other threads:[~2022-01-28  8:05 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-26 21:17 message-beginning-of-line behaves a bit strange Uwe Brauer
2022-01-26 21:27 ` Emanuel Berg
2022-01-27  4:53   ` Emanuel Berg
2022-01-27  7:47   ` Uwe Brauer
2022-01-27 11:29     ` Emanuel Berg
2022-01-28  7:58       ` Uwe Brauer
2022-01-26 21:30 ` Eric Abrahamsen
2022-01-27  7:48   ` Uwe Brauer
2022-01-27  8:31     ` Robert Pluim
2022-01-27 11:38     ` Emanuel Berg
2022-01-27 16:31       ` Eric Abrahamsen
2022-01-28  8:00       ` Uwe Brauer

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 NNTP newsgroup(s).