Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/generic string #1050

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Empty file modified make-release.sh
100755 → 100644
Empty file.
3 changes: 2 additions & 1 deletion smartparens-ruby.el
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ ID, ACTION, CONTEXT."

(when (equal action 'barf-forward)
(sp-get enc
(let ((beg-line (line-number-at-pos :beg-in)))
(let ((beg-line (line-number-at-pos :beg-in))
(end-line (line-number-at-pos :end-in)))
(sp-forward-sexp arg)
(sp-ruby-maybe-one-space)
(when (not (= (line-number-at-pos) beg-line))
Expand Down
22 changes: 11 additions & 11 deletions smartparens.el
Original file line number Diff line number Diff line change
Expand Up @@ -5338,15 +5338,12 @@ This function simply transforms BOUNDS, which is a cons (BEG
. END) into format compatible with `sp-get-sexp'."
(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 (sp--get-prefix (car bounds) op)
:suffix (sp--get-suffix (cdr bounds) cl)))))
(list :beg (car bounds)
:end (cdr bounds)
:op op
:cl cl
: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 @@ -5666,7 +5663,9 @@ expressions are considered."
(sp-get-sexp t))
((sp--valid-initial-delimiter-p (sp--looking-back (sp--get-opening-regexp (sp--get-allowed-pair-list)) nil))
(sp-get-sexp t))
((and (eq (syntax-class (syntax-after (1- (point)))) 7)
((and (memq (syntax-class
(syntax-after (1- (point))))
'(7 15))
(not (sp-char-is-escaped-p (1- (point)))))
(if (eq t (sp-point-in-string))
(save-excursion
Expand Down Expand Up @@ -5717,7 +5716,8 @@ expressions are considered."
(sp-get-sexp nil))
;; TODO: merge the following two conditions and use
;; `sp-get-stringlike-or-textmode-expression'
((and (eq (syntax-class (syntax-after (point))) 7)
((and (memq (syntax-class (syntax-after (point)))
'(7 15))
(not (sp-char-is-escaped-p)))
;; It might happen that the string delimiter we are
;; looking at is nested inside another string
Expand Down
18 changes: 18 additions & 0 deletions test/smartparens-get-paired-expression-ruby-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,21 @@
(ert-deftest sp-test-get-paired-expression-ruby-backward-fail ()
(sp-test--paired-expression-parse-in-ruby "de end|" nil t)
)

(defun sp-test--thing-parse-in-ruby (initial result &optional back)
(let ((sp-pairs '((t . ((:open "def" :close "end" :actions (insert wrap autoskip navigate))
(:open "if" :close "end" :actions (insert wrap autoskip navigate))
(:open "do" :close "end" :actions (insert wrap autoskip navigate))
(:open "begin" :close "end" :actions (insert wrap autoskip navigate))
(:open "(" :close ")" :actions (insert wrap autoskip navigate)))))))
(sp-test-with-temp-buffer initial
(ruby-mode)
(should (equal (sp-get-thing back) result)))))

(ert-deftest sp-test-get-thing-generic-string-ruby ()
(sp-test--thing-parse-in-ruby "C = |%w(asd)#asdas"
'(:beg 5 :end 12 :op "%" :cl ")" :prefix "" :suffix ""))
;; It's not exactly reversible, but this way is backward compatible
(sp-test--thing-parse-in-ruby "C = %w(asd)|#asdas"
'(:beg 7 :end 12 :op "(" :cl ")" :prefix "" :suffix "") t))