Skip to content

Commit

Permalink
fix(rst): do not insert double _ after a link
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuco1 committed Oct 7, 2020
1 parent b814b69 commit c59bfef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 29 deletions.
6 changes: 5 additions & 1 deletion smartparens-rst.el
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@
(require 'smartparens-text)
(require 'smartparens-markdown)

(defun sp-rst-point-after-backtick (_id action _context)
(when (eq action 'insert)
(sp--looking-back-p "`_")))

(sp-with-modes 'rst-mode
(sp-local-pair "*" "*"
:unless '(sp--gfm-point-after-word-p sp-point-at-bol-p)
:post-handlers '(("[d1]" "SPC"))
:skip-match 'sp--gfm-skip-asterisk)
(sp-local-pair "**" "**")
(sp-local-pair "_" "_" :unless '(sp-point-after-word-p))
(sp-local-pair "_" "_" :unless '(sp-point-after-word-p sp-rst-point-after-backtick))
(sp-local-pair "``" "``"))

(provide 'smartparens-rst)
Expand Down
28 changes: 0 additions & 28 deletions test/smartparens-insertion-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,6 @@ which case we should probably rewrap."
(:open "[" :close "]" :actions (insert wrap autoskip navigate))))))
(sp-test-insertion "\"foo | bar\"" "\"" "\"foo \\\"|\\\" bar\"")))

(ert-deftest sp-test-insert-quote-dont-escape-quote-in-rst-mode nil
"In text modes where ' and \" are not string syntax, do not
escape them on the top level."
(let ((sp-pairs
'((t
(:open "\"" :close "\""
:actions (insert wrap autoskip navigate)
:post-handlers (sp-escape-quotes-after-insert))
(:open "[" :close "]" :actions (insert wrap autoskip navigate))))))
(sp-test-with-temp-buffer "foo | bar"
(rst-mode)
(execute-kbd-macro "\"")
(sp-buffer-equals "foo \"|\" bar"))))

(ert-deftest sp-test-insert-quote-dont-escape-quote-in-c-mode nil
"In C mode there is a complication where the mode sets single
quote (') syntax as punctuation in all cases other than having
Expand All @@ -226,20 +212,6 @@ https://github.com/Fuco1/smartparens/issues/783#issuecomment-417841576"
(execute-kbd-macro "'")
(sp-buffer-equals "char x = '|'"))))

(ert-deftest sp-test-insert-quote-dont-escape-in-contraction nil
"Do not escape ' after a word when it is used as a contraction"
(let ((sp-pairs
'((t
(:open "'" :close "'"
:actions (insert wrap autoskip navigate escape)
:unless (sp-in-string-quotes-p sp-point-after-word-p)
:post-handlers (sp-escape-wrapped-region sp-escape-quotes-after-insert))
(:open "[" :close "]" :actions (insert wrap autoskip navigate))))))
(sp-test-with-temp-buffer "foo| bar"
(rst-mode)
(execute-kbd-macro "'s")
(sp-buffer-equals "foo's| bar"))))

;; #665
(ert-deftest sp-test-insert-quote-dont-escape-if-not-in-string-before-insertion nil
"In `scala-mode' and modes where the syntax classes are hacked
Expand Down

0 comments on commit c59bfef

Please sign in to comment.