diff --git a/smartparens.el b/smartparens.el index 67c71e2e..db769c65 100644 --- a/smartparens.el +++ b/smartparens.el @@ -5232,8 +5232,9 @@ is used to retrieve the prefix instead of the global setting." (let* ((pref (sp-get-pair op :prefix)) (prefix (if pref - (when (sp--looking-back pref sp-max-prefix-length) - (match-string-no-properties 0)) + (if (sp--looking-back pref sp-max-prefix-length) + (match-string-no-properties 0) + "") (-if-let (mmode-prefix (cdr (assoc major-mode sp-sexp-prefix))) (cond ((and (eq (car mmode-prefix) 'regexp) @@ -5274,8 +5275,9 @@ is used to retrieve the suffix instead of the global setting." (let* ((suff (sp-get-pair op :suffix)) (suffix (if suff - (when (sp--looking-at suff) - (match-string-no-properties 0)) + (if (sp--looking-at suff) + (match-string-no-properties 0) + "") (-if-let (mmode-suffix (cdr (assoc major-mode sp-sexp-suffix))) (cond ((and (eq (car mmode-suffix) 'regexp) diff --git a/test/smartparens-get-prefix-test.el b/test/smartparens-get-prefix-test.el index 67de0171..49137e40 100644 --- a/test/smartparens-get-prefix-test.el +++ b/test/smartparens-get-prefix-test.el @@ -60,3 +60,13 @@ (sp--update-local-pairs) (sp-skip-backward-to-symbol) (sp-buffer-equals "asd (aaa|(abc))")))))) + +(ert-deftest sp-test-get-prefix-always-return-string () + "Previously in case of a pair-specific prefix we could return +nil if there was no match." + (let ((sp-sexp-prefix '((emacs-lisp-mode regexp "\\(?:aaa\\)")))) + (sp-test-with-temp-elisp-buffer "asd (aaa|(abc))" + (let ((sp-pairs '((t (:open "(" :close ")" :actions (insert wrap autoskip navigate))) + (emacs-lisp-mode (:open "(" :close ")" :actions (insert wrap autoskip navigate) :prefix "x"))))) + (sp--update-local-pairs) + (should (equal (sp--get-prefix (point) "(") "")))))) diff --git a/test/smartparens-get-suffix-test.el b/test/smartparens-get-suffix-test.el index 491d9b78..b30c5ba8 100644 --- a/test/smartparens-get-suffix-test.el +++ b/test/smartparens-get-suffix-test.el @@ -25,3 +25,13 @@ (sp-test-with-temp-buffer "«asdasd»|«asdasd»" (text-mode) (should (equal (sp--get-suffix (point) "«") ""))))) + +(ert-deftest sp-test-get-suffix-always-return-string () + "Previously in case of a pair-specific suffix we could return +nil if there was no match." + (let ((sp-sexp-suffix '((emacs-lisp-mode regexp "\\(?:aaa\\)")))) + (sp-test-with-temp-elisp-buffer "((abc)|aaa) asd" + (let ((sp-pairs '((t (:open "(" :close ")" :actions (insert wrap autoskip navigate))) + (emacs-lisp-mode (:open "(" :close ")" :actions (insert wrap autoskip navigate) :suffix "x"))))) + (sp--update-local-pairs) + (should (equal (sp--get-suffix (point) "(") ""))))))