Skip to content

Commit fc4fff8

Browse files
authored
Merge pull request #916 from knu/refactor/markdown-edit-code-block
Refactor markdown-edit-code-block
2 parents c6ac744 + 1d792c5 commit fc4fff8

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

markdown-mode.el

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9331,7 +9331,7 @@ position."
93319331
(defvar-local markdown--edit-indirect-committed-position nil)
93329332

93339333
(defun markdown--edit-indirect-save-committed-position ()
9334-
"Set where editing is committed to a local variable in the parent buffer."
9334+
"Save where editing is committed in a local variable in the parent buffer."
93359335
(if-let* ((parent-buffer (overlay-buffer edit-indirect--overlay))
93369336
((with-current-buffer parent-buffer
93379337
(derived-mode-p 'markdown-mode)))
@@ -9343,7 +9343,7 @@ position."
93439343
(advice-add #'edit-indirect--commit :after #'markdown--edit-indirect-save-committed-position))
93449344

93459345
(defun markdown--edit-indirect-move-to-committed-position ()
9346-
"Move the point in the code block corresponding to the saved committed position'."
9346+
"Move the point in the code block corresponding to the saved committed position."
93479347
(when-let* ((pos markdown--edit-indirect-committed-position)
93489348
(bounds (markdown-get-enclosing-fenced-block-construct))
93499349
(fence-begin (nth 0 bounds)))
@@ -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)