jeremy-compostella / org-msg

OrgMsg is a GNU/Emacs global minor mode mixing up Org mode and Message mode to compose and reply to emails in a Outlook HTML friendly style.
GNU General Public License v3.0
276 stars 56 forks source link

Unwanted *ORG ASCII Export* buffer #169

Open kourosh2 opened 1 year ago

kourosh2 commented 1 year ago

Hi,

Every time that I compose a message withorg-msg enabled, a new buffer called *Org ASCII Export* of my email is generated. I am feeling that I am doing something wrong. Can anyone point what I am doing wrong?

Emacs 28.2 Org-mode version 9.6.6 Org-msg config:

(use-package org-msg
  :after (mu4e org)
  :config
  (org-msg-mode)
  :custom
  (org-msg-options "html-postamble:nil H:5 num:nil ^:{} toc:nil author:nil email:nil tex:dvipng \\n:t")
  (org-msg-startup "inlineimages")
  (org-msg-greeting-fmt "\nHi%s,\n\n")
  (org-msg-default-alternatives '((new . (text html))
                  (reply-to-html . (text html))
                  (reply-to-text . (text))))
  (org-msg-greeting-name-limit 3)
  )

Thanks, Kourosh

prbuen commented 1 year ago

I have the same; this is an org-mode behaviour, see the docstring for org-export-show-temporary-export-buffer. To keep that buffer buried, you can add this to your .emacs: (setq org-export-show-temporary-export-buffer nil) The buffer is still there, but it remains buried. When I reply/forward to a message that I view, it also remains visible after sending, whereas most mua would close that message. To remove these buffers, I add the following to .emacs (if you use another mua than mu4e you may not have that second issue):

(setq org-export-show-temporary-export-buffer nil)
(add-hook 'message-sent-hook '(lambda()
    (interactive)
    (switch-to-buffer "*mu4e-article*")
    (mu4e-view-quit)    
    (kill-buffer "*Org ASCII Export*")))
krisbalintona commented 1 year ago

@prbuen Thanks for pointing out org-export-show-temporary-export-buffer. I figured it was built-in org behavior but I couldn't pinpoint an option for it.

This is the clever snippet I use for it to only affect org-msg export buffers:

(defun org-msg-no-temp-buffer (orig-fun &rest args)
    "Advice to set `org-export-show-temporary-export-buffer' to `nil'."
    (let ((org-export-show-temporary-export-buffer nil))
      (apply orig-fun args)))
  (advice-add 'org-msg-preview :around #'org-msg-no-temp-buffer)
  (advice-add 'org-msg-ctrl-c-ctrl-c :around #'org-msg-no-temp-buffer)

The snippet you mentioned can be added after the apply call, too.

EDIT: The above snippet actually didn't work as well as I though it would (I got hasty typing the message before testing). The issue was with the window configuration not being desirable after sending an email. With some tinkering, I found that the neatest solution is this:

(add-hook 'message-sent-hook
            #'(lambda ()
                 (when (bound-and-true-p org-msg-mode)
                   (switch-to-buffer "*Org ASCII Export*")
                   (kill-buffer-and-window))))

This returns the window configuration to how it was prior to email composition, regardless of where the user began email composition. Perhaps this doesn't work fully with different display-buffer-alist configurations, but for my Emacs config this works perfectly.

kourosh2 commented 1 year ago

Thanks @prbuen and @krisbalintona. I combined your solutions and it is working nicely.

podiki commented 8 months ago

@kourosh2 would you mind sharing what worked for you? Currently trying to sort this out myself, I think that I use frames-only-mode is adding another variable here.

kourosh2 commented 8 months ago

@kourosh2 would you mind sharing what worked for you? Currently trying to sort this out myself, I think that I use frames-only-mode is adding another variable here.

Sure, see below:

(use-package org-msg
  :preface
  (defun org-msg-no-temp-buffer (orig-fun &rest args)
    "Advice to set `org-export-show-temporary-export-buffer' to `nil'."
    (let ((org-export-show-temporary-export-buffer nil))
      (apply orig-fun args)))

  :config
  (advice-add 'org-msg-preview :around #'org-msg-no-temp-buffer)
  (advice-add 'org-msg-ctrl-c-ctrl-c :around #'org-msg-no-temp-buffer)
  (add-hook 'message-sent-hook
            (lambda ()
              (interactive)
              (switch-to-buffer "*mu4e-article*")
              (mu4e-view-quit)
              (kill-buffer "*Org ASCII Export*"))))