-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
markdown-edit-code-block incorrectly indents code in the indirect buffer #375
Comments
I suppose it is difficult to support this feature with current |
If |
Just finished the proposal, it's over at Fanael/edit-indirect#17. |
You shouldn't need rectangular regions (they're a right mess anyway, and supporting them properly is hard) to do that. Instead, find out if the code block, including its start and end lines, is indented, and if it is, save the indentation level in a buffer local variable in the edit-indirect buffer. Then dedenting in the after creation hook and indenting back in the before commit hook should do the trick. |
I agree that that'd probably be a pretty OK solution. I might try and hack that into markdown-mode.el to see if i can implement that. |
Here's the current definition of markdown-mode/markdown-mode.el Lines 8584 to 8604 in cf64031
I ended up settling on this edit to save the indentation depth of the code block to (defun markdown-edit-code-block ()
"Edit Markdown code block in an indirect buffer."
(interactive)
(save-excursion
(if (fboundp 'edit-indirect-region)
(let* ((bounds (markdown-get-enclosing-fenced-block-construct))
(begin (and bounds (goto-char (nth 0 bounds)) (point-at-bol 2)))
(end (and bounds (goto-char (nth 1 bounds)) (point-at-bol 1))))
(if (and begin end)
(let* ((indentation (and (goto-char (nth 0 bounds)) (current-indentation)))
(lang (markdown-code-block-lang))
(mode (or (and lang (markdown-get-lang-mode lang))
markdown-edit-code-block-default-mode))
(edit-indirect-guess-mode-function
(lambda (_parent-buffer _beg _end)
(funcall mode)))
(indirect-buf (edit-indirect-region begin end 'display-buffer)))
(when (> indentation 0)
(with-current-buffer indirect-buf
(setq-local markdown--code-block-indirect-indentation
indentation)
(indent-rigidly (point-min) (point-max) (- indentation)))))
(user-error "Not inside a GFM or tilde fenced code block")))
(when (y-or-n-p "Package edit-indirect needed to edit code blocks. Install it now? ")
(progn (package-refresh-contents)
(package-install 'edit-indirect)
(markdown-edit-code-block)))))) I'll note that this solution won't work for the following cases:
... but then again, code block detection was spotty for me in these cases before. |
@syohex this issue should be closed, as #559 was merged via |
Oh, sorry I forgot. I have closed. |
Expected Behavior
If a GFM block itself is indented, C-c ' should not add indentation to the indirect buffer.
Actual Behavior
C-c ' adds indentation to such block.
Steps to Reproduce
Create a test file such as
move point into the code block
C-c '
Code block will be indented by 4 spaces in the indirect buffer
Software Versions
The text was updated successfully, but these errors were encountered: