Re: Reply inline in notmuch-show buffer, "mu4e-conversation style"

Subject: Re: Reply inline in notmuch-show buffer, "mu4e-conversation style"

Date: Tue, 19 Mar 2019 15:03:21 +0100

To: notmuch@notmuchmail.org

Cc:

From: Pierre Neidhardt


What I did in mu4e-conversation was actually rather simple, albeit a bit
hackish:

- Copy the test from the composition buffer
- Save the window excursion
- Fire up a new message buffer as notmuch-show-reply would produce.
- Cleanup the citation.
- Insert the copied text from the composition buffer.
- Send.

Sadly, mu4e wraps too much around message-mode and this forced me to use
some ugly hacks.  I haven't looked at notmuch's code yet, but it seems
that it does not wrap quite as much, so it might be cleaner and as
simple as a writing a 10-line-longish function.

The "hardest" part is to add a composition area.

Here is the code excerpt from mu4e-conversation:

--8<---------------cut here---------------start------------->8---
(defun mu4e-conversation-send (&optional msg)
  "Send message at the end of the view buffer.
If MSG is specified, then send this message instead.

Most `mu4e-compose-…' variables are lexically bound during the
call of this function."
  (interactive)
  (unless (mu4e-conversation--buffer-p)
    (mu4e-warn "(send) Not a conversation buffer"))
  (let (draft-buf
        (buf (current-buffer))
        (mu4e-compose-signature mu4e-compose-signature)
        ;; [More local variables...]
        (mu4e-compose-crypto-reply-encrypted-policy mu4e-compose-crypto-reply-encrypted-policy))
    (run-hooks 'mu4e-conversation-before-send-hook)
    (save-window-excursion
      (mu4e-conversation--open-draft msg)
      (condition-case nil
          ;; Force-kill DRAFT-BUF on succcess since it's an implementation
          ;; detail in mu4e-conversation and the composition area is in BUF.
          (let ((message-kill-buffer-on-exit t))
            (message-send-and-exit))
        ;; Stay in draft buffer and widen in case we failed during header check.
        (error (setq draft-buf (current-buffer))
               (widen))))
    (cond
     (draft-buf
      (switch-to-buffer draft-buf))
     (mu4e-conversation-kill-buffer-on-exit
      (switch-to-buffer buf)
      (mu4e-conversation-quit 'no-confirm))
     (t
      ;; Delete message that was just sent.
      (goto-char (point-max))
      (mu4e-conversation-previous-message)
      (forward-line)
      (delete-region (line-beginning-position 1) (point-max))
      ;; Ensure it's writable.
      (insert
       (propertize "\n"
                   'face 'mu4e-conversation-header
                   'rear-nonsticky t))
      (set-buffer-modified-p nil)
      ;; -after-send-hook can be used to update the conversation buffer so that
      ;; it includes the message that was just sent.
      (run-hooks 'mu4e-conversation-after-send-hook)))))
--8<---------------cut here---------------end--------------->8---

The hackish part is in mu4e-conversation--open-draft, which I'm not
including here because it's long and boring.  Hopefully notmuch.el won't
require us to do this.

-- 
Pierre Neidhardt
https://ambrevar.xyz/
signature.asc (application/pgp-signature)
_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch

Thread: