From 0cf78735d937c8e445d67459bad894b50770c1f1 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Sat, 23 Sep 2017 14:14:24 +0200 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20insert=20trailing=20whitespace?= =?UTF-8?q?=20when=20inserting=20a=20blockquote?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #227 --- markdown-mode.el | 8 ++++++-- tests/markdown-test.el | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/markdown-mode.el b/markdown-mode.el index 822e3337..cfc67d57 100644 --- a/markdown-mode.el +++ b/markdown-mode.el @@ -975,6 +975,7 @@ (require 'url-parse) (require 'button) (require 'color) +(require 'rx) (defvar jit-lock-start) (defvar jit-lock-end) @@ -4735,7 +4736,9 @@ region. The characters PREFIX will appear at the beginning of each line." (save-excursion (let* ((end-marker (make-marker)) - (beg-marker (make-marker))) + (beg-marker (make-marker)) + (prefix-without-trailing-whitespace + (replace-regexp-in-string (rx (+ blank) eos) "" prefix))) ;; Ensure blank line after and remove extra whitespace (goto-char end) (skip-syntax-backward "-") @@ -4752,7 +4755,8 @@ of each line." (goto-char beg-marker) (while (and (< (line-beginning-position) end-marker) (not (eobp))) - (insert prefix) + ;; Don’t insert trailing whitespace. + (insert (if (eolp) prefix-without-trailing-whitespace prefix)) (forward-line))))) (defun markdown-blockquote-region (beg end) diff --git a/tests/markdown-test.el b/tests/markdown-test.el index 2081dda9..0462d95e 100644 --- a/tests/markdown-test.el +++ b/tests/markdown-test.el @@ -922,6 +922,11 @@ Test point position upon removal and insertion." (should (looking-at "^ > $")) (should (markdown-next-line-blank-p)))) +(ert-deftest test-markdown-insertion/blockquote-region-with-newline () + (markdown-test-string "a\n\nb\n" + (markdown-blockquote-region 1 (point-max)) + (should (equal (buffer-string) "> a\n>\n> b\n\n")))) + (ert-deftest test-markdown-insertion/empty-italic () "Test `markdown-insert-italic' with no word at point and no region." (markdown-test-string ""