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

Wrong cursor position after reply — missing call to `goto-body` #167

Open david-alvarez-rosa opened 1 year ago

david-alvarez-rosa commented 1 year ago

When using mu4e and just after hitting R for replying to an email the cursor position is just after the "text follows this line" message:

--text follows this line--
[cursor] #+OPTIONS: html-postamble:nil num:nil ^:{} toc:nil author:nil email:nil tex:dvipng d:nil
#+STARTUP: 
:PROPERTIES:
:reply-to: ("/var/folders/vv/v20qymzd6xs88lycdmdw63ww0000gr/T/mm-LxlqRs.html")
:attachment: nil
:alternatives: (text html)
:END:

Hitting C-c C-b for org-msg-goto-body works as expected:

--text follows this line--
#+OPTIONS: html-postamble:nil num:nil ^:{} toc:nil author:nil email:nil tex:dvipng d:nil
#+STARTUP: 
:PROPERTIES:
:reply-to: ("/var/folders/vv/v20qymzd6xs88lycdmdw63ww0000gr/T/mm-LxlqRs.html")
:attachment: nil
:alternatives: (text html)
:END:
[cursor]

I'm suspecting a missing call to org-msg-goto-body, but from the code I see that it's where it should. Any ideas how this can be fixed?

Thank you in advance!

wangwb98 commented 1 month ago

I had same question, and after check mu4e code, I realized it's related to mu4e~compose-handler's implementation. That function will first call mu4e-compose-mode to change the major mode, thus its mode hook (mu4e-compose-mode-hook) will invoke org-msg-post-setup, which will use org-msg-goto-body. But, after all those things done, mu4e~compose-handler still has something to do, which includes jumping to "to" or mail body. This jump override the effect of org-msg-goto-body.

My temporary solution is like below, to go to body again, by adding advice to mu4e-display-buffer. You may have a try to see if it solved your problem as well.

(defun my-goto-body-before-display (buffer-or-name &optional select)
  "Replace message-goto-body with org-msg-goto-body"
  (if (derived-mode-p 'org-msg-edit-mode)
      (if (org-msg-message-fetch-field "to")
          (org-msg-goto-body)
        (message-goto-to))))
(advice-add 'mu4e-display-buffer :before #'my-goto-body-before-display)