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
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
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'.
> (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
[-- 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 --]
[-- 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 --]
>>>>> 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
--
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
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
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.
[-- 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 --]
[-- 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 --]