Skip to content

Commit 1d792c5

Browse files
committed
Refactor markdown-edit-code-block and reduce point movement
1 parent faf0799 commit 1d792c5

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

markdown-mode.el

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9378,13 +9378,14 @@ at the END of code blocks."
93789378
(if (fboundp 'edit-indirect-region)
93799379
(if-let* ((bounds (markdown-get-enclosing-fenced-block-construct))
93809380
(fence-begin (nth 0 bounds))
9381-
(fence-end (nth 1 bounds))
9382-
(original-point (point))
9383-
(original-column (current-column))
9384-
(begin (progn (goto-char fence-begin) (line-beginning-position 2)))
9385-
(end (progn (goto-char fence-end) (line-beginning-position 1)))
9386-
(original-line (- (line-number-at-pos original-point) (line-number-at-pos begin))))
9387-
(let* ((indentation (progn (goto-char fence-begin) (current-indentation)))
9381+
(fence-end (nth 1 bounds)))
9382+
(let* ((original-line (line-number-at-pos))
9383+
(original-column (current-column))
9384+
(begin (progn (goto-char fence-begin) (line-beginning-position 2)))
9385+
(line (max 0 (- original-line (line-number-at-pos) 1)))
9386+
(indentation (current-indentation))
9387+
(column (max 0 (- original-column indentation)))
9388+
(end (progn (goto-char fence-end) (line-beginning-position 1)))
93889389
(lang (markdown-code-block-lang))
93899390
(mode (or (and lang (markdown-get-lang-mode lang))
93909391
markdown-edit-code-block-default-mode))
@@ -9404,8 +9405,8 @@ at the END of code blocks."
94049405
(when (> indentation 0) ;; un-indent in edit-indirect buffer
94059406
(indent-rigidly (point-min) (point-max) (- indentation)))
94069407
(goto-char (point-min))
9407-
(forward-line (max 0 original-line))
9408-
(move-to-column (max 0 (- original-column indentation)))))
9408+
(forward-line line)
9409+
(move-to-column column)))
94099410
(user-error "Not inside a GFM or tilde fenced code block"))
94109411
(when (y-or-n-p "Package edit-indirect needed to edit code blocks. Install it now? ")
94119412
(package-refresh-contents)

0 commit comments

Comments
 (0)