[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/markdown-mode 3a76555 2/4: Merge pull request #614 from jr
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/markdown-mode 3a76555 2/4: Merge pull request #614 from jrblevin/issue613 |
Date: |
Mon, 3 May 2021 22:57:12 -0400 (EDT) |
branch: elpa/markdown-mode
commit 3a76555cec820ab1f06a2c14afa656d1980285f6
Merge: 94c65e2 6902cbe
Author: Shohei YOSHIDA <syohex@gmail.com>
Commit: GitHub <noreply@github.com>
Merge pull request #614 from jrblevin/issue613
Improve markdown-insert-bold,italic region with spaces
---
CHANGES.md | 2 ++
markdown-mode.el | 24 ++++++++++++++++--------
tests/markdown-test.el | 32 ++++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+), 8 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 2478ff9..a1269e8 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -29,6 +29,7 @@
- Support to display local image with percent encoding file path
- Add ability to resize inline image display
(`markdown-toggle-inline-images`) without Imagemagick installed in the computer
(emulating Org Mode)
- Support including braces around the language specification in GFM code
blocks
+ - Improve `markdown-insert-{bold,italic}` when region starts with
spaces[GH-613][]
* Bug fixes:
- Fix remaining flyspell overlay in code block or comment issue
[GH-311][]
@@ -68,6 +69,7 @@
[gh-587]: https://github.com/jrblevin/markdown-mode/issues/587
[gh-590]: https://github.com/jrblevin/markdown-mode/pull/590
[gh-598]: https://github.com/jrblevin/markdown-mode/pull/598
+ [gh-613]: https://github.com/jrblevin/markdown-mode/issues/613
# Markdown Mode 2.4
diff --git a/markdown-mode.el b/markdown-mode.el
index 114f9a1..cf6a76e 100644
--- a/markdown-mode.el
+++ b/markdown-mode.el
@@ -3585,13 +3585,21 @@ prefixed with an integer from 1 to the length of
(insert (car markdown-hr-strings))))
(markdown-ensure-blank-line-after))
-(defun markdown--insert-common (start-delim end-delim regex start-group
end-group face)
+(defun markdown--insert-common (start-delim end-delim regex start-group
end-group face
+ &optional skip-space)
(if (use-region-p)
;; Active region
- (let ((bounds (markdown-unwrap-things-in-region
- (region-beginning) (region-end)
- regex start-group end-group)))
- (markdown-wrap-or-insert start-delim end-delim nil (car bounds) (cdr
bounds)))
+ (let* ((bounds (markdown-unwrap-things-in-region
+ (region-beginning) (region-end)
+ regex start-group end-group))
+ (beg (car bounds))
+ (end (cdr bounds)))
+ (when (and beg skip-space)
+ (save-excursion
+ (goto-char beg)
+ (skip-chars-forward "[ \t]")
+ (setq beg (point))))
+ (markdown-wrap-or-insert start-delim end-delim nil beg end))
(if (markdown--face-p (point) (list face))
(save-excursion
(while (and (markdown--face-p (point) (list face)) (not (bobp)))
@@ -3613,7 +3621,7 @@ bold word or phrase, remove the bold markup. Otherwise,
simply
insert bold delimiters and place the point in between them."
(interactive)
(let ((delim (if markdown-bold-underscore "__" "**")))
- (markdown--insert-common delim delim markdown-regex-bold 2 4
'markdown-bold-face)))
+ (markdown--insert-common delim delim markdown-regex-bold 2 4
'markdown-bold-face t)))
(defun markdown-insert-italic ()
"Insert markup to make a region or word italic.
@@ -3623,7 +3631,7 @@ italic word or phrase, remove the italic markup.
Otherwise, simply
insert italic delimiters and place the point in between them."
(interactive)
(let ((delim (if markdown-italic-underscore "_" "*")))
- (markdown--insert-common delim delim markdown-regex-italic 1 3
'markdown-italic-face)))
+ (markdown--insert-common delim delim markdown-regex-italic 1 3
'markdown-italic-face t)))
(defun markdown-insert-strike-through ()
"Insert markup to make a region or word strikethrough.
@@ -3633,7 +3641,7 @@ strikethrough word or phrase, remove the strikethrough
markup. Otherwise,
simply insert bold delimiters and place the point in between them."
(interactive)
(markdown--insert-common
- "~~" "~~" markdown-regex-strike-through 2 4 'markdown-strike-through-face))
+ "~~" "~~" markdown-regex-strike-through 2 4 'markdown-strike-through-face
t))
(defun markdown-insert-code ()
"Insert markup to make a region or word an inline code fragment.
diff --git a/tests/markdown-test.el b/tests/markdown-test.el
index 1a46a6e..2f039f8 100644
--- a/tests/markdown-test.el
+++ b/tests/markdown-test.el
@@ -530,6 +530,15 @@ Test point position upon removal and insertion."
(should (string-equal (buffer-string) "**one two** three"))
(should (= (point) 10))))
+(ert-deftest test-markdown-insertion/bold-region-begin-with-space ()
+ "Test region functionality of `markdown-insert-bold'.
+When region starts with spaces"
+ (markdown-test-string " one two three"
+ (push-mark (point) t t)
+ (forward-word 2)
+ (markdown-insert-bold)
+ (should (string-equal (buffer-string) " **one two** three"))))
+
(ert-deftest test-markdown-insertion/italic-region ()
"Test region functionality of `markdown-insert-italic'."
(markdown-test-string "one two three"
@@ -540,6 +549,16 @@ Test point position upon removal and insertion."
(should (string-equal (buffer-string) "*one two* three"))
(should (= (point) 9))))
+(ert-deftest test-markdown-insertion/italic-region-begin-with-space ()
+ "Test region functionality of `markdown-insert-italic'.
+When region starts with spaces"
+ (markdown-test-string " one two three"
+ (transient-mark-mode)
+ (push-mark (point) t t)
+ (forward-word 2)
+ (markdown-insert-italic)
+ (should (string-equal (buffer-string) " *one two* three"))))
+
(ert-deftest test-markdown-insertion/code-region ()
"Test region functionality of `markdown-insert-code'."
(markdown-test-string "one two three"
@@ -6156,6 +6175,19 @@ Details:
https://github.com/jrblevin/markdown-mode/issues/534"
(markdown-test-range-has-face 10 11 'markdown-markup-face)
(markdown-test-range-has-face 12 17 nil)))
+(ert-deftest test-markdown-gfm/insert-strike-through ()
+ "Test `markdown-insert-strike-through'."
+ (markdown-test-string-gfm "one two three"
+ (push-mark (point) t t)
+ (forward-word 2)
+ (markdown-insert-strike-through)
+ (should (string-equal (buffer-string) "~~one two~~ three")))
+ (markdown-test-string-gfm " one two three"
+ (push-mark (point) t t)
+ (forward-word 2)
+ (markdown-insert-strike-through)
+ (should (string-equal (buffer-string) " ~~one two~~ three"))))
+
(ert-deftest test-markdown-gfm/toggle-strike-through ()
"Test toggling functionality of `markdown-insert-strike-through'."
(markdown-test-string-gfm "one ~~two~~ three"