summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimeon Simeonov2020-12-17 14:56:10 +0100
committerSimeon Simeonov2020-12-17 14:56:10 +0100
commit7ae5757f8fa736e816e9eb43276cb88d7a0b0613 (patch)
treef6d2236e7b07f72e0eba1d8b7eccdd46db2e24b4
parente096aeac80c3f75b9d5986726640380f65dbd5b0 (diff)
Update markdown-mode
-rw-r--r--.emacs.d/lisp/markdown-mode.el37
1 files changed, 28 insertions, 9 deletions
diff --git a/.emacs.d/lisp/markdown-mode.el b/.emacs.d/lisp/markdown-mode.el
index a1e37e0..2e47247 100644
--- a/.emacs.d/lisp/markdown-mode.el
+++ b/.emacs.d/lisp/markdown-mode.el
@@ -1154,7 +1154,8 @@ this property is a list with elements of the form (begin . end)
1154giving the bounds of the current and parent list items." 1154giving the bounds of the current and parent list items."
1155 (save-excursion 1155 (save-excursion
1156 (goto-char start) 1156 (goto-char start)
1157 (let (bounds level pre-regexp) 1157 (let ((prev-list-line -100)
1158 bounds level pre-regexp)
1158 ;; Find a baseline point with zero list indentation 1159 ;; Find a baseline point with zero list indentation
1159 (markdown-search-backward-baseline) 1160 (markdown-search-backward-baseline)
1160 ;; Search for all list items between baseline and END 1161 ;; Search for all list items between baseline and END
@@ -1171,7 +1172,9 @@ giving the bounds of the current and parent list items."
1171 ((markdown-new-baseline) 1172 ((markdown-new-baseline)
1172 (setq bounds nil)) 1173 (setq bounds nil))
1173 ;; Make sure this is not a line from a pre block 1174 ;; Make sure this is not a line from a pre block
1174 ((looking-at-p pre-regexp)) 1175 ((and (looking-at-p pre-regexp)
1176 ;; too indented line is also treated as list if previous line is list
1177 (>= (- (line-number-at-pos) prev-list-line) 2)))
1175 ;; If not, then update levels and propertize list item when in range. 1178 ;; If not, then update levels and propertize list item when in range.
1176 (t 1179 (t
1177 (let* ((indent (current-indentation)) 1180 (let* ((indent (current-indentation))
@@ -1182,6 +1185,7 @@ giving the bounds of the current and parent list items."
1182 (setq bounds (markdown--append-list-item-bounds 1185 (setq bounds (markdown--append-list-item-bounds
1183 marker indent cur-bounds bounds)) 1186 marker indent cur-bounds bounds))
1184 (when (and (<= start (point)) (<= (point) end)) 1187 (when (and (<= start (point)) (<= (point) end))
1188 (setq prev-list-line (line-number-at-pos first))
1185 (put-text-property first last 'markdown-list-item bounds))))) 1189 (put-text-property first last 'markdown-list-item bounds)))))
1186 (end-of-line))))) 1190 (end-of-line)))))
1187 1191
@@ -2150,7 +2154,10 @@ Depending on your font, some reasonable choices are:
2150Used for `flyspell-generic-check-word-predicate'." 2154Used for `flyspell-generic-check-word-predicate'."
2151 (save-excursion 2155 (save-excursion
2152 (goto-char (1- (point))) 2156 (goto-char (1- (point)))
2153 (if (or (markdown-code-block-at-point-p) 2157 ;; https://github.com/jrblevin/markdown-mode/issues/560
2158 ;; enable spell check YAML meta data
2159 (if (or (and (markdown-code-block-at-point-p)
2160 (not (markdown-text-property-at-point 'markdown-yaml-metadata-section)))
2154 (markdown-inline-code-at-point-p) 2161 (markdown-inline-code-at-point-p)
2155 (markdown-in-comment-p) 2162 (markdown-in-comment-p)
2156 (markdown--face-p (point) '(markdown-reference-face 2163 (markdown--face-p (point) '(markdown-reference-face
@@ -8575,11 +8582,19 @@ position."
8575(defvar edit-indirect-guess-mode-function) 8582(defvar edit-indirect-guess-mode-function)
8576(defvar edit-indirect-after-commit-functions) 8583(defvar edit-indirect-after-commit-functions)
8577 8584
8578(defun markdown--edit-indirect-after-commit-function (_beg end) 8585(defun markdown--edit-indirect-after-commit-function (beg end)
8579 "Ensure trailing newlines at the END of code blocks." 8586 "Corrective logic run on code block content from lines BEG to END.
8587Restores code block indentation from BEG to END, and ensures trailing newlines
8588at the END of code blocks."
8589 ;; ensure trailing newlines
8580 (goto-char end) 8590 (goto-char end)
8581 (unless (eq (char-before) ?\n) 8591 (unless (eq (char-before) ?\n)
8582 (insert "\n"))) 8592 (insert "\n"))
8593 ;; restore code block indentation
8594 (goto-char (- beg 1))
8595 (let ((block-indentation (current-indentation)))
8596 (when (> block-indentation 0)
8597 (indent-rigidly beg end block-indentation))))
8583 8598
8584(defun markdown-edit-code-block () 8599(defun markdown-edit-code-block ()
8585 "Edit Markdown code block in an indirect buffer." 8600 "Edit Markdown code block in an indirect buffer."
@@ -8590,13 +8605,17 @@ position."
8590 (begin (and bounds (goto-char (nth 0 bounds)) (point-at-bol 2))) 8605 (begin (and bounds (goto-char (nth 0 bounds)) (point-at-bol 2)))
8591 (end (and bounds (goto-char (nth 1 bounds)) (point-at-bol 1)))) 8606 (end (and bounds (goto-char (nth 1 bounds)) (point-at-bol 1))))
8592 (if (and begin end) 8607 (if (and begin end)
8593 (let* ((lang (markdown-code-block-lang)) 8608 (let* ((indentation (and (goto-char (nth 0 bounds)) (current-indentation)))
8609 (lang (markdown-code-block-lang))
8594 (mode (or (and lang (markdown-get-lang-mode lang)) 8610 (mode (or (and lang (markdown-get-lang-mode lang))
8595 markdown-edit-code-block-default-mode)) 8611 markdown-edit-code-block-default-mode))
8596 (edit-indirect-guess-mode-function 8612 (edit-indirect-guess-mode-function
8597 (lambda (_parent-buffer _beg _end) 8613 (lambda (_parent-buffer _beg _end)
8598 (funcall mode)))) 8614 (funcall mode)))
8599 (edit-indirect-region begin end 'display-buffer)) 8615 (indirect-buf (edit-indirect-region begin end 'display-buffer)))
8616 (when (> indentation 0) ;; un-indent in edit-indirect buffer
8617 (with-current-buffer indirect-buf
8618 (indent-rigidly (point-min) (point-max) (- indentation)))))
8600 (user-error "Not inside a GFM or tilde fenced code block"))) 8619 (user-error "Not inside a GFM or tilde fenced code block")))
8601 (when (y-or-n-p "Package edit-indirect needed to edit code blocks. Install it now? ") 8620 (when (y-or-n-p "Package edit-indirect needed to edit code blocks. Install it now? ")
8602 (progn (package-refresh-contents) 8621 (progn (package-refresh-contents)