Fanael / edit-indirect

Edit regions in separate buffers
99 stars 23 forks source link

edit-indirect-commit inserts newlines in Markdown files #27

Closed tjtrabue closed 6 months ago

tjtrabue commented 7 months ago

Greetings,

I love this plugin! It works so well with markdown-mode, allowing me to edit code blocks as if I was programming in org-mode. It's wonderful! I just noticed some strange behavior today. If I edit a Markdown file, and I place my cursor anywhere other than the beginning of a code block, and then proceed to edit the code block with markdown-edit-code-block (which uses edit-indirect to pop up the temporary code buffer) and close the buffer with edit-indirect-commit, a newline gets inserted where at the position of my cursor. It may have to do with the fact that I use evil-mode.

To recap the steps I used to produce this bug:

  1. Install markdown-mode, edit-indirect, evil-mode
  2. Edit a markdown file, and make sure that markdown-mode is active, evil-mode is active, and that edit-indirect has been loaded
  3. Create a fenced code block with "..." in any programming language
  4. Write some text in the code block, place cursor anywhere in the code block except at the beginning of a line, and press C-c ' to edit the code block in an indirect buffer
  5. Press C-c ' again to run edit-indirect-commit
  6. Notice that a newline gets added at point.

Do you have any ideas as to why this may be happening? I would appreciate any help you could give me.

Thank you so much! -tjtrabue

dschrempf commented 7 months ago

+1

Fanael commented 6 months ago

:facepalm:

The end point of the region passed to edit-indirect-after-commit-functions is incorrect, so markdown--edit-indirect-after-commit-function thinks the code block ends in the middle of a line and so it adds the trailing line feed.

I have no idea how I've never noticed this bug, nor how I've made this silly mistake in the first place, especially since there's an end marker right there, in the very same function edit-indirect--commit, just a handful of lines above the hook invocation, and the invocation of edit-indirect-before-commit-functions is correct!