Skip to content

Commit

Permalink
With no string-like delimiters sp--get-stringlike-regexp should never…
Browse files Browse the repository at this point in the history
… match.
  • Loading branch information
Fuco1 committed Jun 24, 2017
1 parent a806e2f commit 6182efa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion smartparens.el
Original file line number Diff line number Diff line change
Expand Up @@ -3186,7 +3186,13 @@ delimiter for any pair allowed in current context."
(sp--strict-regexp-opt (--mapcat (list (car it) (cdr it)) pair-list)))

(cl-defun sp--get-stringlike-regexp (&optional (pair-list (sp--get-allowed-stringlike-list)))
(regexp-opt (--map (car it) pair-list)))
"Return a regexp matching any string-like delimiter.

In case PAIR-LIST is empty return a regexp that never matches
anything."
(if (consp pair-list)
(regexp-opt (--map (car it) pair-list))
"^\\<$"))

(defun sp--get-last-wraped-region (beg end open close)
"Return `sp-get-sexp' style plist about the last wrapped region.
Expand Down
22 changes: 22 additions & 0 deletions test/smartparens-framework-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,25 @@ delimiter."
"`sp--strict-regexp-opt' on nil input should return empty
string to be consistent with `regexp-opt'."
(should (equal "" (sp--strict-regexp-opt nil))))

(ert-deftest sp-test-sp--get-stringlike-regexp-with-delimiter ()
"In case there are string-like delimiters we should return a
regexp that matches them."
(let ((sp-pairs '((t . ((:open "\"" :close "\"" :actions (insert wrap autoskip navigate)))))))
(sp-test-with-temp-elisp-buffer "foo |\"bar\""
(should (sp--looking-at-p (sp--get-stringlike-regexp))))
(sp-test-with-temp-elisp-buffer "\"bar\"| baz"
(should (sp--looking-back-p (sp--get-stringlike-regexp))))))

(ert-deftest sp-test-sp--get-stringlike-regexp-with-no-delimiter ()
"In case there is no string-like delimiter we should return a
regexp that never matches anything."
(let ((sp-pairs '((t . ((:open "(" :close ")" :actions (insert wrap autoskip navigate)))))))
(sp-test-with-temp-elisp-buffer "foo |\"bar\""
(should-not (sp--looking-at-p (sp--get-stringlike-regexp))))
(sp-test-with-temp-elisp-buffer "\"bar\"| baz"
(should-not (sp--looking-back-p (sp--get-stringlike-regexp))))
(sp-test-with-temp-elisp-buffer "foo |(bar)"
(should-not (sp--looking-at-p (sp--get-stringlike-regexp))))
(sp-test-with-temp-elisp-buffer "(bar)| baz"
(should-not (sp--looking-back-p (sp--get-stringlike-regexp))))))

0 comments on commit 6182efa

Please sign in to comment.