Skip to content

Commit

Permalink
Merge pull request #480 from jrblevin/syohex/228
Browse files Browse the repository at this point in the history
Don't indent pre block at indent-region
  • Loading branch information
syohex authored May 9, 2020
2 parents e7d8a0e + 69a6f56 commit b014454
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,14 @@
- Fix table align issue when column contains escaped bar([GH-308][])
- Fix nested block fill-paragraph issue([GH-366][])
- Fix table transpose issue with wiki link
- Fix indent-region for pre block([GH-228][])

[gh-171]: https://github.com/jrblevin/markdown-mode/issues/171
[gh-216]: https://github.com/jrblevin/markdown-mode/issues/216
[gh-222]: https://github.com/jrblevin/markdown-mode/issues/222
[gh-224]: https://github.com/jrblevin/markdown-mode/issues/224
[gh-227]: https://github.com/jrblevin/markdown-mode/issues/227
[gh-228]: https://github.com/jrblevin/markdown-mode/issues/228
[gh-229]: https://github.com/jrblevin/markdown-mode/pull/229
[gh-235]: https://github.com/jrblevin/markdown-mode/issues/235
[gh-238]: https://github.com/jrblevin/markdown-mode/issues/238
Expand Down
15 changes: 15 additions & 0 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -4783,6 +4783,20 @@ See `markdown-indent-line' and `markdown-indent-line'."
(interactive "*r")
(markdown-indent-region beg end t))

(defun markdown--indent-region (start end)
(let ((deactivate-mark nil))
(save-excursion
(goto-char end)
(setq end (point-marker))
(goto-char start)
(when (bolp)
(forward-line 1))
(while (< (point) end)
(unless (or (markdown-code-block-at-point-p) (and (bolp) (eolp)))
(indent-according-to-mode))
(forward-line 1))
(move-marker end nil))))


;;; Markup Completion =========================================================

Expand Down Expand Up @@ -9396,6 +9410,7 @@ rows and columns and the column alignment."

;; Indentation
(setq-local indent-line-function markdown-indent-function)
(setq-local indent-region-function #'markdown--indent-region)

;; Flyspell
(setq-local flyspell-generic-check-word-predicate
Expand Down
16 changes: 16 additions & 0 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -1941,6 +1941,22 @@ Should not cause an infinite loop."
(should (eq (point) 62))
(should (looking-back "^ "))))

(ert-deftest test-markdown-indentation/indent-region-function ()
"Test `indent-region'. Code block should not be indented.
Detail: https://github.com/jrblevin/markdown-mode/issues/228"
(markdown-test-string
"Here follows a code sample:

#!/bin/bash
echo foobar

Nice sample, isn't it ?"
(indent-region (point-min) (point-max))
(goto-char (point-min))
(forward-line 2)
(should (looking-at-p " #!/bin/bash"))
(markdown-test-range-has-face (point) (line-end-position) 'markdown-pre-face)))

(ert-deftest test-markdown-indentation/indent-hanging-line ()
"Test `markdown-indent-line' with hanging indentation.
See GH-245."
Expand Down

0 comments on commit b014454

Please sign in to comment.