Re: Here's how to insert your signature before cited email

162 views
Skip to first unread message

Dirk-Jan C. Binnema

unread,
Sep 4, 2016, 4:10:53 PM9/4/16
to mu-di...@googlegroups.com

> Note that you have to use `compose-type' in the compose pre-hook and
> `mu4e~compose-type' in the compose-mode hook
>
> Yes, I know that many people claim that we shouldn't put signatures before
> quoted text. However, some of us prefer not to follow that guideline.

I recommend against using mu4e~ prefixed functions / variables, those
are for internal use only, and can change at any point.

Cheers,
Dirk.

--
Dirk-Jan C. Binnema Helsinki, Finland
e:dj...@djcbsoftware.nl w:www.djcbsoftware.nl
pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C

Hippo Man

unread,
Sep 4, 2016, 4:13:43 PM9/4/16
to mu-discuss
Oh, thank you.

What is the recommended method for distinguishing between "new", "reply", and "forward" buffers?

Dirk-Jan C. Binnema

unread,
Sep 4, 2016, 4:26:30 PM9/4/16
to mu-di...@googlegroups.com

> Oh, thank you.
>
> What is the recommended method for distinguishing between "new", "reply",
> and "forward" buffers?

If you really want to use that distinction in your compose-hook rather
than the pre-hook, you could store the info in a variable in the
latter.

I guess in this case your preferred position of the signature would be
the same for forward/reply, and for new it doesn't really matter -- so
perhaps there's no need to distinguish.

Kind regards,

Hippo Man

unread,
Sep 4, 2016, 4:36:54 PM9/4/16
to mu-discuss
Yes, I know I can distinguish between "new" and the other modes by looking at `mu4e-compose-parent-message' ... it's nil for "new" and it has a value for the other cases.

With regard to the signature, I don't really need to distinguish between "reply" and "forward", as you pointed out.

However, there might be other processing that I will perform which needs to know whether we're doing a "reply" or a "forward".

What variable should I use to determine this? `compose-mode' is known during the pre-hook ... but that's just a local elisp variable which is probably even less likely to be stable than any mu4e~* variables.

Also, `mu4e-compose-parent-message' is set during "edit" mode, as well, and I definitely do not want any signature processing in that mode. In the pre-hook, how can I distinguish between "edit" and the "forward"/"reply" cases?

Hippo Man

unread,
Sep 4, 2016, 4:38:58 PM9/4/16
to mu-discuss
I mean "compose-type", not "compose-mode".

Dirk-Jan C. Binnema

unread,
Sep 5, 2016, 1:49:53 AM9/5/16
to mu-di...@googlegroups.com
You can create your own temporary variable for that, ie. in the pre-hook
you'd do something like.

(setq my-toplevel-sig
(when (member compose-type ... )
"My signature"))

and in the compose hook you can use my-toplevel-sig, if it's set.

Cheers,

Hippo Man

unread,
Sep 5, 2016, 8:02:57 AM9/5/16
to mu-discuss
Yes, I understand that I can create my own variable. I'm just concerned that I can't count on `compose-type' as the source of the information for this variable, since `compose-type' is just the name of an argument to an internal mu4e function, and it is probably even less likely to be present in future versions of mu4e than any mu4e~* variables. It's not even a defcustom or defvar.

It's defined here in mu43-compose.el ...

(defun* mu4e~compose-handler (compose-type &optional original-msg includes) ...

That's the function which invokes `mu4e-compose-pre-hook'.

But can I count on `compose-type' always being the name of that variable in future mu4e versions, perhaps?

Dirk-Jan C. Binnema

unread,
Sep 6, 2016, 2:18:07 AM9/6/16
to mu-di...@googlegroups.com

On Monday Sep 05 2016, Hippo Man wrote:

> Yes, I understand that I can create my own variable. I'm just concerned
> that I can't count on `compose-type' as the source of the information for
> this variable, since `compose-type' is just the name of an argument to an
> internal mu4e function, and it is probably even less likely to be present
> in future versions of mu4e than any mu4e~* variables. It's not even a
> defcustom or defvar.

That would indeed not be a very robust solution; I've made
mu4e-compose-type a public variable instead, so you can use it in your
hooks.

Kind regards,

Hippo Man

unread,
Sep 6, 2016, 4:36:53 AM9/6/16
to mu-discuss
Thank you!

I notice, however, that `mu4e-compose-type' is not set until after `mu4e-compose-pre-hook' is run, and that there is no longer any `mu4e-compose-mode-hook', at all. Is there a new hook or method for modifying draft messages after they are created?


Message has been deleted

Hippo Man

unread,
Sep 6, 2016, 11:27:18 AM9/6/16
to mu-discuss
OOPS! I now remember that `mu4e-compose-mode-hook' gets automatically run because of `mu4e-compose-mode', and that's why I don't see it defined anywhere in the mu4e code. Sorry for the false alarm.

But as for `mu4e-compose-type', is there any way it could be set before the invocation of `mu4e-compose-pre-hook'? There are cases where it's useful to know the compose type within the pre-hook. Otherwise, I have to stick with checking `compose-type' in the pre-hook.

Thank you.

Dirk-Jan C. Binnema

unread,
Sep 6, 2016, 11:31:01 AM9/6/16
to mu-di...@googlegroups.com

On Tuesday Sep 06 2016, hipp...@gmail.com wrote:

> OOPS! Never mind. I forgot that `mu4e-compose-mode-hook' comes "for free"
> when defining mu4e-compose-mode, and this is the reason for why I am not
> seeing a definition for it in the mu4e code.
>
> But also, would it be possible to set `mu4e-compose-type' *before* invoking
> `mu4e-compose-pre-hook'? This allows us to perform setup specific to the
> composition type within the pre-hook, as well.

Sure - that makes sense. I've pushed a change.

Hippo Man

unread,
Sep 6, 2016, 11:33:59 AM9/6/16
to mu-discuss
Thank you very much! I'll test this later today, when I get home from work.

Hippo Man

unread,
Sep 6, 2016, 5:46:31 PM9/6/16
to mu-discuss
I just now tested this, and it works fine.

Thank you again!

Benjamin Slade

unread,
Sep 9, 2016, 11:10:55 PM9/9/16
to mu-discuss


On Tuesday, 6 September 2016 15:46:31 UTC-6, Hippo Man wrote:
I just now tested this, and it works fine.

Thank you again!

What is the method of setting this up? If you wouldn't mind sharing. 

Hippo Man

unread,
Sep 11, 2016, 9:13:01 AM9/11/16
to mu-discuss
 In order to put the signature above the quoted text, I now am able to do that by putting the following code into my `mu4e-compose-mode-hook' ...

  (unless (member mu4e-compose-type '(edit resend))
    (save-excursion
      (save-restriction
        (widen)
        (cond
         ((eq mu4e-compose-type '
new)
         
(message-goto-body)
         
(kill-region (point) (point-max)))
         
((message-goto-signature)
         
(forward-line -2)
         
(kill-region (point) (point-max))
         
)
         
)
       
(message-goto-body)
       
(insert "\n")
       
(narrow-to-region (point-min) (point))
       
(let ((message-signature t)
             
(mu4e-compose-signature t)
             
(mu4e-compose-signature-auto-include t))
         
(message-insert-signature))
       
(when (member mu4e-compose-type '(forward reply))
          (goto-char (point-max))
          (insert "\n"))
        )
      )
    )


This assumes that I have already initialized `message-signature', `mu4e-compose-signature', and `mu4e-compose-signature-auto-include' to nil.



Message has been deleted
Message has been deleted

Hippo Man

unread,
Sep 11, 2016, 9:26:24 AM9/11/16
to mu-discuss
Also, at the end of `mu4e-mode-compose-hook', I also have the following in order to position the cursor to the first empty header that needs to be filled in, if there is one ...

  (save-restriction
   
(message-narrow-to-headers)
   
(unless (re-search-forward "^.+?:\\s-*$" nil t)
     
(message-goto-body)))



Hong Xu

unread,
Nov 4, 2016, 8:50:25 PM11/4/16
to mu-discuss


On Sunday, September 11, 2016 at 6:13:01 AM UTC-7, Hippo Man wrote:
 In order to put the signature above the quoted text, I now am able to do that by putting the following code into my `mu4e-compose-mode-hook' ...

...


This assumes that I have already initialized `message-signature', `mu4e-compose-signature', and `mu4e-compose-signature-auto-include' to nil.



Are you sure this still works? mu4e-compose-type is always nil for me.
Message has been deleted

Hippo Man

unread,
Nov 24, 2016, 12:10:29 AM11/24/16
to mu-discuss


On Friday, November 4, 2016 at 8:50:25 PM UTC-4, Hong Xu wrote:

Are you sure this still works? mu4e-compose-type is always nil for me.
 
It still works for me. That variable indeed gets set to non-nil values. I'm using the 0.9.17 code base.
 

AP11

unread,
Dec 4, 2016, 12:58:07 PM12/4/16
to mu-discuss
Hi Hippo Man: I have tried putting the code you provided in my emacs file, but I don't get the desired results. Could you add the full snippet of your code? I'm assuming you put this in your init.el file?

Thanks!
Reply all
Reply to author
Forward
0 new messages