Skip to content

Conversation

cjennings
Copy link

This PR addresses issue 210:

ROOT CAUSE

On line 1556, in org-msg-edit-mode reads:

(add-hook 'message-sent-hook 'undo t t)

When sending messages that extend past the visible space, org-msg prepares the content and may narrow the buffer. When the message-sent-hook fires in a narrowed buffer, it calls undo which errors when attempting to undo changes recorded outside the visible restriction. "primitive-undo: Changes to be undone are outside visible portion of buffer". While the email is sent successfully, the compose buffer is left in a mixed text+html state, which causes confusion and forces the users to close buffers manually.

FIX DESCRIPTION

  • Replace the raw undo hook with a helper which widens before performing the undo. Add that helper to message-send-hook based on the value of message-kill-buffer-on-exit. This way:
  • If message-kill-buffer-on-exit is t, there’s no need to restore the buffer as it will be killed right after the hooks. No undo → no error → no need to widen.
  • If the buffer won’t be killed, we DO need to restore it, therefore we widen first and then perform the undo.

ALTERNATIVES REJECTED

  • Removing undo entirely. This fixes the error, but was rejected as it changes org-msg's behavior for users who keep the buffer open post-send.
  • Saving/restoring the original buffer text explicitly. Rejected because this felt more invasive and might risk clobbering other transient state.
  • Always add the hook to widen before performing the undo. Rejected to avoid executing more code than necessary.

…portion of buffer

jeremy-compostella#210

ROOT CAUSE

On line 1556, in org-msg-edit-mode reads:
```
  (add-hook 'message-sent-hook 'undo t t)
```
https://github.com/jeremy-compostella/org-msg/blob/59e2042e5f23e25f31c6aef0db1e70c6f54f117d/org-msg.el#L1556

When sending messages that extend past the visible space, org-msg prepares the content and may narrow the buffer. When the message-sent-hook fires in a narrowed buffer, calling undo errors when attempting to undo changes recorded outside the visible restriction.

PROPOSED FIX

- Replace the raw undo hook with a helper which widens before performing the undo. Add that helper to message-send-hook based on the value of message-kill-buffer-on-exit.
This way:
- If message-kill-buffer-on-exit is t, there’s no need to restore the buffer as it will be killed right after the hooks. No undo → no error → no need to widen.
- If the buffer won’t be killed, we DO need to restore it, therefore we widen first and then perform the undo.

ALTERNATIVES REJECTED

- Removing undo entirely. This fixes the error, but was rejected as it changes org-msg's behavior for users who keep the buffer open post-send.
- Saving/restoring the original buffer text explicitly. Rejected because this felt more invasive and might risk clobbering other transient state.
- Always add the hook to widen before performing the undo. Rejected to avoid executing more code than necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant