From 7ae5757f8fa736e816e9eb43276cb88d7a0b0613 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Thu, 17 Dec 2020 14:56:10 +0100 Subject: Update markdown-mode --- .emacs.d/lisp/markdown-mode.el | 37 ++++++++++++++++++++++++++++--------- 1 file 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) giving the bounds of the current and parent list items." (save-excursion (goto-char start) - (let (bounds level pre-regexp) + (let ((prev-list-line -100) + bounds level pre-regexp) ;; Find a baseline point with zero list indentation (markdown-search-backward-baseline) ;; Search for all list items between baseline and END @@ -1171,7 +1172,9 @@ giving the bounds of the current and parent list items." ((markdown-new-baseline) (setq bounds nil)) ;; Make sure this is not a line from a pre block - ((looking-at-p pre-regexp)) + ((and (looking-at-p pre-regexp) + ;; too indented line is also treated as list if previous line is list + (>= (- (line-number-at-pos) prev-list-line) 2))) ;; If not, then update levels and propertize list item when in range. (t (let* ((indent (current-indentation)) @@ -1182,6 +1185,7 @@ giving the bounds of the current and parent list items." (setq bounds (markdown--append-list-item-bounds marker indent cur-bounds bounds)) (when (and (<= start (point)) (<= (point) end)) + (setq prev-list-line (line-number-at-pos first)) (put-text-property first last 'markdown-list-item bounds))))) (end-of-line))))) @@ -2150,7 +2154,10 @@ Depending on your font, some reasonable choices are: Used for `flyspell-generic-check-word-predicate'." (save-excursion (goto-char (1- (point))) - (if (or (markdown-code-block-at-point-p) + ;; https://github.com/jrblevin/markdown-mode/issues/560 + ;; enable spell check YAML meta data + (if (or (and (markdown-code-block-at-point-p) + (not (markdown-text-property-at-point 'markdown-yaml-metadata-section))) (markdown-inline-code-at-point-p) (markdown-in-comment-p) (markdown--face-p (point) '(markdown-reference-face @@ -8575,11 +8582,19 @@ position." (defvar edit-indirect-guess-mode-function) (defvar edit-indirect-after-commit-functions) -(defun markdown--edit-indirect-after-commit-function (_beg end) - "Ensure trailing newlines at the END of code blocks." +(defun markdown--edit-indirect-after-commit-function (beg end) + "Corrective logic run on code block content from lines BEG to END. +Restores code block indentation from BEG to END, and ensures trailing newlines +at the END of code blocks." + ;; ensure trailing newlines (goto-char end) (unless (eq (char-before) ?\n) - (insert "\n"))) + (insert "\n")) + ;; restore code block indentation + (goto-char (- beg 1)) + (let ((block-indentation (current-indentation))) + (when (> block-indentation 0) + (indent-rigidly beg end block-indentation)))) (defun markdown-edit-code-block () "Edit Markdown code block in an indirect buffer." @@ -8590,13 +8605,17 @@ position." (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* ((lang (markdown-code-block-lang)) + (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)))) - (edit-indirect-region begin end 'display-buffer)) + (funcall mode))) + (indirect-buf (edit-indirect-region begin end 'display-buffer))) + (when (> indentation 0) ;; un-indent in edit-indirect buffer + (with-current-buffer indirect-buf + (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) -- cgit v1.3