Skip to content

Commit

Permalink
[Fix #811] Strings can have prefixes too
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuco1 committed Nov 11, 2017
1 parent b5cf2df commit 4978ab2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
12 changes: 6 additions & 6 deletions smartparens.el
Original file line number Diff line number Diff line change
Expand Up @@ -5162,17 +5162,17 @@ returned by `sp-get-sexp'."

This function simply transforms BOUNDS, which is a cons (BEG
. END) into format compatible with `sp-get-sexp'."
(let* (;; if the closing and opening isn't the same token, we should
;; return nil
(op (char-to-string (char-after (car bounds))))
(let* ((op (char-to-string (char-after (car bounds))))
(cl (char-to-string (char-before (cdr bounds)))))
;; if the closing and opening isn't the same token, we should
;; return nil
(when (equal op cl)
(list :beg (car bounds)
:end (cdr bounds)
:op cl
:cl cl
:prefix ""
:suffix ""))))
:prefix (sp--get-prefix (car bounds) op)
:suffix (sp--get-suffix (cdr bounds) cl)))))

(defun sp-get-string (&optional back)
"Find the nearest string after point, or before if BACK is non-nil.
Expand Down Expand Up @@ -5561,7 +5561,7 @@ expressions are considered."
(sym-string (and sym (sp-get sym (buffer-substring-no-properties :beg :end))))
(point-before-prefix (point)))
(when sym-string
(if (sp--valid-initial-delimiter-p (sp--search-forward-regexp (sp--get-opening-regexp (sp--get-allowed-pair-list)) nil t))
(if (sp--valid-initial-delimiter-p (sp--search-forward-regexp (sp--get-opening-regexp (sp--get-pair-list-context 'navigate)) nil t))
(let* ((ms (match-string 0))
(pref (progn
;; need to move before the
Expand Down
31 changes: 31 additions & 0 deletions test/smartparens-get-thing-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,37 @@ picked up, causing `sp-get-thing' to take the 2nd previous one."
(should
(equal (sp-get-thing)
'(:beg 11 :end 12 :op "" :cl "" :prefix "" :suffix ""))))))

;; #811
(ert-deftest sp-test-get-thing-string-with-prefix-syntax-before-prefix ()
(sp-test-with-temp-elisp-buffer "symbol |,\"string\""
(sp-get (sp-get-thing)
(should (equal :prefix ","))
(should (equal :op "\"")))))

;; #811
(ert-deftest sp-test-get-thing-string-with-prefix-syntax-after-prefix ()
(sp-test-with-temp-elisp-buffer "symbol ,|\"string\""
(sp-get (sp-get-thing)
(should (equal :prefix ","))
(should (equal :op "\"")))))

;; #811
(ert-deftest sp-test-get-thing-string-with-prefix-regexp-before-prefix ()
(let ((sp-sexp-prefix '((emacs-lisp-mode regexp "P"))))
(sp-test-with-temp-elisp-buffer "symbol |P\"foo\""
(sp-get (sp-get-thing)
(should (equal :prefix "P"))
(should (equal :op "\""))))))

;; #811
(ert-deftest sp-test-get-thing-string-with-prefix-regexp-after-prefix ()
(let ((sp-sexp-prefix '((emacs-lisp-mode regexp "P"))))
(sp-test-with-temp-elisp-buffer "symbol P|\"foo\""
(sp-get (sp-get-thing)
(should (equal :prefix "P"))
(should (equal :op "\""))))))

;; #812
(ert-deftest sp-test-get-thing-symbol-with-prefix-syntax-before-prefix ()
(let ((sp-sexp-prefix nil))
Expand Down

0 comments on commit 4978ab2

Please sign in to comment.