-
Notifications
You must be signed in to change notification settings - Fork 164
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
preserve indent-tabs-mode in markdown-edit-code-block #816
Comments
proposed fix: preserve the relevant buffer-local settings, see ===>> and <<=== (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 (not (null (nth 0 bounds))) (goto-char (nth 0 bounds)) (line-beginning-position 2)))
(end (and bounds(not (null (nth 1 bounds))) (goto-char (nth 1 bounds)) (line-beginning-position 1))))
(if (and begin end)
(let* ((indentation (and (goto-char (nth 0 bounds)) (current-indentation)))
(original-indent-tabs-mode indent-tabs-mode) ;;; ====>>
(original-tab-width tab-width) ;;; =====>>
(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)))
;; reset `sh-shell' when indirect buffer
(when (and (not (member system-type '(ms-dos windows-nt)))
(member mode '(shell-script-mode sh-mode))
(member lang (append
(mapcar (lambda (e) (symbol-name (car e)))
sh-ancestor-alist)
'("csh" "rc" "sh"))))
(with-current-buffer indirect-buf
(sh-set-shell lang)))
(when (> indentation 0) ;; un-indent in edit-indirect buffer
(with-current-buffer indirect-buf
(setq indent-tabs-mode original-indent-tabs-mode) ;;; <<====
(setq tab-width original-tab-width) ;;; <<====
(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)))))) alternative: create some |
Could you show us how to reproduce in detail ? How are indentations broken ? Original code, broken indentation code etc. |
here is some badly indented markdown
==> broken indent |
How about using |
I see the point of "which variables to move over"?. And I can use the hook, of course. for the time being would you advise to use this stanza to capture the values from the original buffer? (with-current-buffer (overlay-buffer edit-indirect--overlay) ;;; this feels like hijacking an internal variable
(save-excursion
...)) In the description of the hooks it was unspecific which buffer you're in when each hook is invoked and how to access the "other" buffer. |
Expected Behavior
When I edit a nested code block using
markdown-edit-code-block
and I reindent it in the edit-indirect buffer, it's indentation should be preserved when I commit the edit back to the markdown document.Actual Behavior
The
indent-rigidly
inmarkdown--edit-indirect-after-commit-function
gets a region indented according to the default settings of indent-tabs-mode and tab-width, which may easily mismatch the markdown document's settings (in my case: markdown set to indent with spaces, default however is tabs). poor indent-rigidly can't but mess up at this time.Steps to Reproduce
C-c '
)C-M-q
)see the broken indentation. I have a simple solution proposal, so no cut&paste example.
Backtrace
Software Versions
of 2023-08-16, modified by Debian
The text was updated successfully, but these errors were encountered: