From ecdca2dd6ae7b3587970e7e8402315ada0e47b36 Mon Sep 17 00:00:00 2001 From: Thibaut Verron Date: Fri, 12 Jun 2020 09:38:58 +0200 Subject: [PATCH 01/12] Support for generalized strings --- smartparens.el | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/smartparens.el b/smartparens.el index fea2d3ee..c03400e3 100644 --- a/smartparens.el +++ b/smartparens.el @@ -5349,13 +5349,13 @@ This function simply transforms BOUNDS, which is a cons (BEG (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) + ;; (when (equal op cl) (list :beg (car bounds) :end (cdr bounds) - :op cl + :op op :cl cl :prefix (sp--get-prefix (car bounds) op) - :suffix (sp--get-suffix (cdr bounds) cl))))) + :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. @@ -5675,7 +5675,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 @@ -5720,13 +5722,10 @@ expressions are considered." (and (sp--looking-back " Date: Fri, 12 Jun 2020 10:07:35 +0200 Subject: [PATCH 02/12] generic-string also for going back --- smartparens.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/smartparens.el b/smartparens.el index b0e8a3bb..4b5bcf21 100644 --- a/smartparens.el +++ b/smartparens.el @@ -5676,10 +5676,6 @@ expressions are considered." ;; js2-jsx-mode (looking-at ">")) (sp-get-sgml-tag t))) - ((sp--valid-initial-delimiter-p (sp--looking-back (sp--get-closing-regexp (sp--get-allowed-pair-list)) nil)) - (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 (memq (syntax-class (syntax-after (1- (point)))) '(7 15)) @@ -5694,6 +5690,10 @@ expressions are considered." (sp-get-string t))) ((sp--valid-initial-delimiter-p (sp--looking-back (sp--get-stringlike-regexp) nil)) (sp-get-expression t)) + ((sp--valid-initial-delimiter-p (sp--looking-back (sp--get-closing-regexp (sp--get-allowed-pair-list)) nil)) + (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)) ;; We might be somewhere inside the prefix of the ;; sexp after the point. Since the prefix can be ;; specified as regexp and not syntax class, it might From 7eadd9d2fc2fdf42f2c53a965cea79b6f4f85d31 Mon Sep 17 00:00:00 2001 From: Thibaut Verron Date: Fri, 12 Jun 2020 10:32:05 +0200 Subject: [PATCH 03/12] sp-get-string does not need to do anything special at the boundary of comment --- smartparens.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/smartparens.el b/smartparens.el index 4b5bcf21..0367ac76 100644 --- a/smartparens.el +++ b/smartparens.el @@ -5374,7 +5374,11 @@ expression. The return value is a plist with the same format as the value returned by `sp-get-sexp'." (sp--maybe-init) - (if (sp-point-in-comment) + (if (and (sp-point-in-comment) + (or (and back + (not (eq (point) (car (sp-get-comment-bounds))))) + (and (not back) + (not (eq (point) (cdr (sp-get-comment-bounds))))))) (sp-get-stringlike-expression back) (if (sp-point-in-string) (let ((r (sp-get-quoted-string-bounds))) From 6b9c26056fc39136c10e39e6d548f6a501cad769 Mon Sep 17 00:00:00 2001 From: Thibaut Verron Date: Fri, 12 Jun 2020 10:32:28 +0200 Subject: [PATCH 04/12] New tests for generic strings --- ...artparens-get-paired-expression-ruby-test.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/smartparens-get-paired-expression-ruby-test.el b/test/smartparens-get-paired-expression-ruby-test.el index 698c8671..dda58350 100644 --- a/test/smartparens-get-paired-expression-ruby-test.el +++ b/test/smartparens-get-paired-expression-ruby-test.el @@ -32,3 +32,20 @@ (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 "")) + (sp-test--thing-parse-in-ruby "C = %w(asd)|#asdas" + '(:beg 5 :end 12 :op "%" :cl ")" :prefix "" :suffix "") t)) + From 68b854e1153ab2c05cee62b8ab8d7db543d36e3b Mon Sep 17 00:00:00 2001 From: Thibaut Verron Date: Thu, 8 Oct 2020 11:12:37 +0200 Subject: [PATCH 05/12] . --- make-release.sh | 0 smartparens-ess.el | 17 ++--- smartparens-ruby.el | 3 +- smartparens.el | 72 ++++++------------- test/smartparens-commands-test.el | 60 ++++------------ test/smartparens-crystal-test.el | 38 +++++++--- ...parens-get-paired-expression-elisp-test.el | 14 ++-- test/smartparens-insertion-test.el | 18 ----- 8 files changed, 83 insertions(+), 139 deletions(-) mode change 100755 => 100644 make-release.sh diff --git a/make-release.sh b/make-release.sh old mode 100755 new mode 100644 diff --git a/smartparens-ess.el b/smartparens-ess.el index 3afbdd53..3bac0b5f 100644 --- a/smartparens-ess.el +++ b/smartparens-ess.el @@ -44,14 +44,15 @@ (declare-function ess-roxy-indent-on-newline "ess-roxy") -(dolist (mode '(ess-mode ess-r-mode inferior-ess-mode inferior-ess-r-mode)) - ;; avoid traveling commas when slurping - ;; (|a, b), c ---> (|a, b, c) - (add-to-list 'sp-sexp-suffix (list mode 'regexp "")) - ;; `sp-sexp-prefix' for ESS - (add-to-list 'sp-sexp-prefix - (list mode 'regexp - (rx (zero-or-more (or word (syntax symbol))))))) +;; avoid traveling commas when slurping +;; (|a, b), c ---> (|a, b, c) +(dolist (mode '(ess-mode inferior-ess-mode)) + (add-to-list 'sp-sexp-suffix (list mode 'regexp ""))) + +;; `sp-sexp-prefix' for ESS +(add-to-list 'sp-sexp-prefix + (list 'ess-mode 'regexp + (rx (zero-or-more (or word (syntax symbol)))))) ;; slurping follows Google's R style guide ;; see https://google.github.io/styleguide/Rguide.xml diff --git a/smartparens-ruby.el b/smartparens-ruby.el index 3ba86716..ed504842 100644 --- a/smartparens-ruby.el +++ b/smartparens-ruby.el @@ -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)) diff --git a/smartparens.el b/smartparens.el index 0367ac76..fea2d3ee 100644 --- a/smartparens.el +++ b/smartparens.el @@ -3645,13 +3645,8 @@ Return non-nil if at least one escaping was performed." ;; before inserting the "" pair it is now split into two ;; -> which moves us outside the pair (not (eq context 'string)) - ;; the inserted character must have string syntax, - ;; otherwise no "context" flip happens - (eq (syntax-class - (syntax-after - (save-excursion - (backward-char (length id)) - (point)))) 7)) + ;; the inserted character must have string syntax, otherwise no "context" flip happens + (eq (char-syntax (aref id 0)) ?\")) (let ((open id) (close (sp-get-pair id :close))) (sp--escape-region (list open close) @@ -5354,13 +5349,13 @@ This function simply transforms BOUNDS, which is a cons (BEG (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) + (when (equal op cl) (list :beg (car bounds) :end (cdr bounds) - :op op + :op cl :cl cl :prefix (sp--get-prefix (car bounds) op) - :suffix (sp--get-suffix (cdr bounds) cl))));) + :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. @@ -5374,11 +5369,7 @@ expression. The return value is a plist with the same format as the value returned by `sp-get-sexp'." (sp--maybe-init) - (if (and (sp-point-in-comment) - (or (and back - (not (eq (point) (car (sp-get-comment-bounds))))) - (and (not back) - (not (eq (point) (cdr (sp-get-comment-bounds))))))) + (if (sp-point-in-comment) (sp-get-stringlike-expression back) (if (sp-point-in-string) (let ((r (sp-get-quoted-string-bounds))) @@ -5680,9 +5671,11 @@ expressions are considered." ;; js2-jsx-mode (looking-at ">")) (sp-get-sgml-tag t))) - ((and (memq (syntax-class - (syntax-after (1- (point)))) - '(7 15)) + ((sp--valid-initial-delimiter-p (sp--looking-back (sp--get-closing-regexp (sp--get-allowed-pair-list)) nil)) + (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) (not (sp-char-is-escaped-p (1- (point))))) (if (eq t (sp-point-in-string)) (save-excursion @@ -5694,10 +5687,6 @@ expressions are considered." (sp-get-string t))) ((sp--valid-initial-delimiter-p (sp--looking-back (sp--get-stringlike-regexp) nil)) (sp-get-expression t)) - ((sp--valid-initial-delimiter-p (sp--looking-back (sp--get-closing-regexp (sp--get-allowed-pair-list)) nil)) - (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)) ;; We might be somewhere inside the prefix of the ;; sexp after the point. Since the prefix can be ;; specified as regexp and not syntax class, it might @@ -5731,10 +5720,13 @@ expressions are considered." (and (sp--looking-back " a symbol - ;; sequence - (and (eq (char-before) ??) - (eq (char-syntax (following-char)) ?\\)) - (and (eq (char-syntax (char-before)) ?\\)))) + (memq (char-syntax (following-char)) '(?w ?_))) (forward-char)) (setq n (1- n))) (sp-backward-symbol n))))) @@ -7696,13 +7676,7 @@ Examples: (while (and (not (bobp)) (not (or (sp--valid-initial-delimiter-p (sp--looking-back open)) (sp--valid-initial-delimiter-p (sp--looking-back close)))) - (or (memq (char-syntax (preceding-char)) '(?w ?_)) - ;; Specifically for lisp, we consider - ;; sequences of ?\ a symbol - ;; sequence - (and (eq (char-before (1- (point))) ??) - (eq (char-syntax (preceding-char)) ?\\)) - )) + (memq (char-syntax (preceding-char)) '(?w ?_))) (backward-char)) ;; skip characters which are symbols with prefix flag (while (and (not (eobp)) @@ -8433,8 +8407,8 @@ Examples: (sp-point-in-string)))) (-when-let (ok (if should-split-as-string (save-excursion - (goto-char (car (sp-get-quoted-string-bounds))) - (sp-get-sexp)) + (goto-char (1- (cdr (sp-get-quoted-string-bounds)))) + (sp-get-enclosing-sexp 1)) (sp-get-enclosing-sexp 1))) (sp-get ok (sp--run-hook-with-args :op :pre-handlers 'split-sexp) diff --git a/test/smartparens-commands-test.el b/test/smartparens-commands-test.el index 3de50f7e..563c4a5b 100644 --- a/test/smartparens-commands-test.el +++ b/test/smartparens-commands-test.el @@ -30,28 +30,13 @@ that are used to test the resulting state after running the command. Each string must contain | to specify where point should be." (declare (indent 1)) - (let* ((group-index 0) - (forms - (-mapcat - (lambda (example-group) - (setq group-index (1+ group-index)) - (let ((example-index 0)) - (mapcar - (lambda (test-sequence) - (setq example-index (1+ example-index)) - `(ert-deftest - ,(intern (concat "sp-test-command-" - (symbol-name command) - "-" - (number-to-string group-index) - "-" - (number-to-string example-index) - )) () - (let ,(car example-group) - (sp--test-command ',command ',(list test-sequence))))) - (cdr example-group)))) - examples))) - `(progn ,@forms))) + `(ert-deftest ,(intern (concat "sp-test-command-" + (symbol-name command))) () + ,@(mapcar + (lambda (example-group) + `(let ,(car example-group) + (sp--test-command ',command ',(cdr example-group)))) + examples))) (defun sp--test-command (command examples) "Run the test for COMMAND." @@ -240,15 +225,6 @@ be." ("(foo)\nbar ;; baz (f|oo) baz\n(quux)" "(foo)\nbar ;; baz (f|oo baz)\n(quux)") - ;; #1010 - ("(foo (baz|) ;; bar\n moo\n mee)" - "(foo (baz| ;; bar\n moo)\n mee)" - "(foo (baz| ;; bar\n moo\n mee))") - - ("(foo (gah|) ?\\; bar baz)" - "(foo (gah| ?\\;) bar baz)" - "(foo (gah| ?\\; bar) baz)") - ;; do not slurp outside of comment ("(foo)\nbar ;; (|foo) baz\n(asd)\n\n" "(foo)\nbar ;; (|foo baz)\n(asd)\n\n" @@ -295,7 +271,12 @@ be." "(f|oo)\nbar ;; baz (foo) baz\n(quux)") ("(foo)\nbar ;; baz (f|oo baz)\n(quux)" - "(foo)\nbar ;; baz (f|oo) baz\n(quux)")) + "(foo)\nbar ;; baz (f|oo) baz\n(quux)") + + ;; #634 + ("(let ((a 4)\n ;; (fail)\n |(+ 1)\n ))\n" + "(let ((a 4))\n ;; (fail)\n| (+ 1)\n )\n" + "(let ((a 4)))\n;; (fail)\n|(+ 1)\n\n")) (((mode 'racket) (sp-sexp-prefix '((racket-mode regexp "#?['`,]@?")))) @@ -452,14 +433,6 @@ be." ("\"(foo |bar) baz\"" "\"(foo \"|\"bar) baz\"") ) - (((mode 'python)) - ("\"foo |bar baz\"" "\"foo \"|\"bar baz\"") - ("'foo |bar baz'" "'foo '|'bar baz'") - ("'foo bar|'" "'foo bar'|''") - - ("\"\"\"foo|bar\"\"\"" "\"\"\"foo\"\"\"|\"\"\"bar\"\"\"") - ) - (((sp-split-sexp-always-split-as-string nil)) ("\"foo |bar baz\"" "\"foo\" |\"bar baz\"") ("\"foo bar|\"" "\"foo bar\"|\"\"") @@ -1023,10 +996,3 @@ This is the behavior of `paredit-convolute-sexp'." (sp-buffer-equals "(foo) (progn |(bar))")))) - -(ert-deftest sp-test-sp-forward-barf-sexp-634 () - (sp-test-with-temp-elisp-buffer "(let ((a 4)\n ;; (fail)\n |(+ 1)\n ))\n" - (call-interactively 'sp-forward-barf-sexp) - (sp-buffer-equals "(let ((a 4))\n ;; (fail)\n (+ 1)\n )\n") - (call-interactively 'sp-forward-barf-sexp) - (sp-buffer-equals "(let ((a 4)))\n;; (fail)\n|(+ 1)\n\n"))) diff --git a/test/smartparens-crystal-test.el b/test/smartparens-crystal-test.el index 8690c539..3cc48418 100644 --- a/test/smartparens-crystal-test.el +++ b/test/smartparens-crystal-test.el @@ -34,7 +34,7 @@ end")))) (should (sp-crystal-eq-ignore-indent (buffer-string) expected))))) -(sp-ert-deftest sp-test-crystal-slurp-forward +(ert-deftest sp-test-crystal-slurp-forward () (sp-crystal-test-slurp-assert 1 " if teXst end @@ -196,6 +196,16 @@ end (sp-crystal-test-slurp-assert 1 " beginX end +?x +" :=> " +begin + ?x +end +") + + (sp-crystal-test-slurp-assert 1 " +beginX +end !x " :=> " begin @@ -225,7 +235,7 @@ end ) -(sp-ert-deftest sp-test-crystal-slurp-backward +(ert-deftest sp-test-crystal-slurp-backward () (sp-crystal-test-slurp-assert -1 " foo.bar begin X @@ -284,6 +294,16 @@ end begin !foo end +") + + (sp-crystal-test-slurp-assert -1 " +?f +begin X +end +" :=> " +begin + ?f +end ") (sp-crystal-test-slurp-assert -1 " @@ -377,7 +397,7 @@ end ) -(sp-ert-deftest sp-test-crystal-slurp-on-single-line +(ert-deftest sp-test-crystal-slurp-on-single-line () (sp-crystal-test-slurp-assert 1 " test {X} test " :=> " @@ -404,7 +424,7 @@ test { test; test } ) -(sp-ert-deftest sp-test-crystal-slurp-with-inline-blocks +(ert-deftest sp-test-crystal-slurp-with-inline-blocks () (sp-crystal-test-slurp-assert 1 " if teXst end @@ -454,7 +474,7 @@ end (should (sp-crystal-eq-ignore-indent (buffer-string) expected))))) -(sp-ert-deftest sp-test-crystal-barf-forward +(ert-deftest sp-test-crystal-barf-forward () (sp-crystal-test-barf-assert 1 " if teXst foo @@ -564,7 +584,7 @@ end ") ) -(sp-ert-deftest sp-test-crystal-barf-backward +(ert-deftest sp-test-crystal-barf-backward () (sp-crystal-test-barf-assert -1 " begin fooX @@ -654,7 +674,7 @@ end ") ) -(sp-ert-deftest sp-test-crystal-barf-on-single-line +(ert-deftest sp-test-crystal-barf-on-single-line () (sp-crystal-test-barf-assert 1 " test { Xtest } " :=> " @@ -680,7 +700,7 @@ test test; test { } ") ) -(sp-ert-deftest sp-test-crystal-barf-with-inline-blocks +(ert-deftest sp-test-crystal-barf-with-inline-blocks () ;; (sp-crystal-test-barf-assert 2 " ;; if teXst ;; foo if true @@ -720,7 +740,7 @@ foo = if true (should (sp-crystal-eq-ignore-indent (buffer-string) expected))))) -(sp-ert-deftest sp-test-crystal-splice +(ert-deftest sp-test-crystal-splice () (sp-crystal-test-splice-assert 1 " if teXst end diff --git a/test/smartparens-get-paired-expression-elisp-test.el b/test/smartparens-get-paired-expression-elisp-test.el index 64332070..1232701c 100644 --- a/test/smartparens-get-paired-expression-elisp-test.el +++ b/test/smartparens-get-paired-expression-elisp-test.el @@ -2,7 +2,7 @@ (sp-test-with-temp-elisp-buffer initial (should (equal (sp-get-paired-expression back) result)))) -(sp-ert-deftest sp-test-get-paired-expression-elisp +(ert-deftest sp-test-get-paired-expression-elisp () "Test basic paired expressions in `emacs-lisp-mode'." (sp-test--paired-expression-parse-in-elisp "|(foo bar)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix "")) (sp-test--paired-expression-parse-in-elisp "(foo bar|)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix "")) @@ -36,7 +36,7 @@ (sp-test--paired-expression-parse-in-elisp "|(foo bar \\?)" '(:beg 1 :end 13 :op "(" :cl ")" :prefix "" :suffix "")) ) -(sp-ert-deftest sp-test-get-paired-expression-elisp-backward +(ert-deftest sp-test-get-paired-expression-elisp-backward () "Test basic paired expressions in `emacs-lisp-mode' in backwards." (sp-test--paired-expression-parse-in-elisp "(|foo bar)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix "") t) (sp-test--paired-expression-parse-in-elisp "(foo bar|)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix "") t) @@ -70,7 +70,7 @@ (sp-test--paired-expression-parse-in-elisp "(foo bar \\?)|" '(:beg 1 :end 13 :op "(" :cl ")" :prefix "" :suffix "") t) ) -(sp-ert-deftest sp-test-get-paired-expression-elisp-fail +(ert-deftest sp-test-get-paired-expression-elisp-fail () "Test that we fail on incomplete pairs." (sp-test--paired-expression-parse-in-elisp "|(foo bar" nil) (sp-test--paired-expression-parse-in-elisp "(foo |bar" nil) @@ -91,7 +91,7 @@ (sp-test--paired-expression-parse-in-elisp "|,@foo)" nil) ) -(sp-ert-deftest sp-test-get-paired-expression-elisp-backward-fail +(ert-deftest sp-test-get-paired-expression-elisp-backward-fail () "Test that we fail on incomplete pairs parsing backwards." (sp-test--paired-expression-parse-in-elisp "foo| bar)" nil t) (sp-test--paired-expression-parse-in-elisp "foo bar)|" nil t) @@ -114,7 +114,7 @@ ) ;; Regression tests -(sp-ert-deftest sp-test-get-paired-expression-505 +(ert-deftest sp-test-get-paired-expression-505 () "Test https://github.com/Fuco1/smartparens/issues/505" (sp-test--paired-expression-parse-in-elisp "(foo (|bar \"baz(\"))" '(:beg 6 :end 18 :op "(" :cl ")" :prefix "" :suffix "")) (sp-test--paired-expression-parse-in-elisp "(foo (|bar \"baz(\" ))" '(:beg 6 :end 19 :op "(" :cl ")" :prefix "" :suffix "")) @@ -133,14 +133,14 @@ (sp-test--paired-expression-parse-in-elisp "(foo (|bar ;baz(\n ))" '(:beg 6 :end 24 :op "(" :cl ")" :prefix "" :suffix "")) ) -(sp-ert-deftest sp-test-get-paired-expression-556 +(ert-deftest sp-test-get-paired-expression-556 () "Test https://github.com/Fuco1/smartparens/issues/556" (sp-test--paired-expression-parse-in-elisp "(f| ; ()\n 'x)" '(:beg 1 :end 14 :op "(" :cl ")" :prefix "" :suffix "")) (sp-test--paired-expression-parse-in-elisp "(f ; ()\n |'x)" '(:beg 1 :end 14 :op "(" :cl ")" :prefix "" :suffix "")) (sp-test--paired-expression-parse-in-elisp "(f ; ()\n '|x)" '(:beg 1 :end 14 :op "(" :cl ")" :prefix "" :suffix "")) ) -(sp-ert-deftest sp-test-get-paired-expression-653 +(ert-deftest sp-test-get-paired-expression-653 () "If the point is in a multi-line comment, we should be able to parse a multi-line sexp. diff --git a/test/smartparens-insertion-test.el b/test/smartparens-insertion-test.el index d7a299e5..ad933e9a 100644 --- a/test/smartparens-insertion-test.el +++ b/test/smartparens-insertion-test.el @@ -208,24 +208,6 @@ escape them on the top level." (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 -exactly one character in between. This causes SP to get the -context wrong and escape the newly inserted pair. - -Detailed analysis is available here: -https://github.com/Fuco1/smartparens/issues/783#issuecomment-417841576" - (let ((sp-pairs - '((t - (:open "'" :close "'" - :actions (insert wrap autoskip navigate) - :post-handlers (sp-escape-quotes-after-insert)))))) - (sp-test-with-temp-buffer "char x = |" - (c-mode) - (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 From 1c7f76248ec1749511f153f6f7569963a72d4a87 Mon Sep 17 00:00:00 2001 From: Thibaut Verron Date: Thu, 8 Oct 2020 12:48:48 +0200 Subject: [PATCH 06/12] Merge one file --- test/smartparens-crystal-test.el | 38 ++++++++------------------------ 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/test/smartparens-crystal-test.el b/test/smartparens-crystal-test.el index 3cc48418..8690c539 100644 --- a/test/smartparens-crystal-test.el +++ b/test/smartparens-crystal-test.el @@ -34,7 +34,7 @@ end")))) (should (sp-crystal-eq-ignore-indent (buffer-string) expected))))) -(ert-deftest sp-test-crystal-slurp-forward () +(sp-ert-deftest sp-test-crystal-slurp-forward (sp-crystal-test-slurp-assert 1 " if teXst end @@ -196,16 +196,6 @@ end (sp-crystal-test-slurp-assert 1 " beginX end -?x -" :=> " -begin - ?x -end -") - - (sp-crystal-test-slurp-assert 1 " -beginX -end !x " :=> " begin @@ -235,7 +225,7 @@ end ) -(ert-deftest sp-test-crystal-slurp-backward () +(sp-ert-deftest sp-test-crystal-slurp-backward (sp-crystal-test-slurp-assert -1 " foo.bar begin X @@ -294,16 +284,6 @@ end begin !foo end -") - - (sp-crystal-test-slurp-assert -1 " -?f -begin X -end -" :=> " -begin - ?f -end ") (sp-crystal-test-slurp-assert -1 " @@ -397,7 +377,7 @@ end ) -(ert-deftest sp-test-crystal-slurp-on-single-line () +(sp-ert-deftest sp-test-crystal-slurp-on-single-line (sp-crystal-test-slurp-assert 1 " test {X} test " :=> " @@ -424,7 +404,7 @@ test { test; test } ) -(ert-deftest sp-test-crystal-slurp-with-inline-blocks () +(sp-ert-deftest sp-test-crystal-slurp-with-inline-blocks (sp-crystal-test-slurp-assert 1 " if teXst end @@ -474,7 +454,7 @@ end (should (sp-crystal-eq-ignore-indent (buffer-string) expected))))) -(ert-deftest sp-test-crystal-barf-forward () +(sp-ert-deftest sp-test-crystal-barf-forward (sp-crystal-test-barf-assert 1 " if teXst foo @@ -584,7 +564,7 @@ end ") ) -(ert-deftest sp-test-crystal-barf-backward () +(sp-ert-deftest sp-test-crystal-barf-backward (sp-crystal-test-barf-assert -1 " begin fooX @@ -674,7 +654,7 @@ end ") ) -(ert-deftest sp-test-crystal-barf-on-single-line () +(sp-ert-deftest sp-test-crystal-barf-on-single-line (sp-crystal-test-barf-assert 1 " test { Xtest } " :=> " @@ -700,7 +680,7 @@ test test; test { } ") ) -(ert-deftest sp-test-crystal-barf-with-inline-blocks () +(sp-ert-deftest sp-test-crystal-barf-with-inline-blocks ;; (sp-crystal-test-barf-assert 2 " ;; if teXst ;; foo if true @@ -740,7 +720,7 @@ foo = if true (should (sp-crystal-eq-ignore-indent (buffer-string) expected))))) -(ert-deftest sp-test-crystal-splice () +(sp-ert-deftest sp-test-crystal-splice (sp-crystal-test-splice-assert 1 " if teXst end From d78f746bc31374637f66222026574eedf4f83a81 Mon Sep 17 00:00:00 2001 From: Thibaut Verron Date: Thu, 8 Oct 2020 13:25:49 +0200 Subject: [PATCH 07/12] Messed up merge --- smartparens-ess.el | 17 +++--- test/smartparens-commands-test.el | 60 +++++++++++++++---- ...parens-get-paired-expression-elisp-test.el | 14 ++--- 3 files changed, 62 insertions(+), 29 deletions(-) diff --git a/smartparens-ess.el b/smartparens-ess.el index 39ec2b3b..15b923ea 100644 --- a/smartparens-ess.el +++ b/smartparens-ess.el @@ -44,15 +44,14 @@ (declare-function ess-roxy-indent-on-newline "ess-roxy") -;; avoid traveling commas when slurping -;; (|a, b), c ---> (|a, b, c) -(dolist (mode '(ess-mode inferior-ess-mode)) - (add-to-list 'sp-sexp-suffix (list mode 'regexp ""))) - -;; `sp-sexp-prefix' for ESS -(add-to-list 'sp-sexp-prefix - (list 'ess-mode 'regexp - (rx (zero-or-more (or word (syntax symbol)))))) +(dolist (mode '(ess-mode ess-r-mode inferior-ess-mode inferior-ess-r-mode)) + ;; avoid traveling commas when slurping + ;; (|a, b), c ---> (|a, b, c) + (add-to-list 'sp-sexp-suffix (list mode 'regexp "")) + ;; `sp-sexp-prefix' for ESS + (add-to-list 'sp-sexp-prefix + (list mode 'regexp + (rx (zero-or-more (or word (syntax symbol))))))) (defadvice sp-backward-kill-symbol (around sp-ess-backward-kill-symbol activate) "#821 For the purpose of killing words and symbols, we remove diff --git a/test/smartparens-commands-test.el b/test/smartparens-commands-test.el index 563c4a5b..3de50f7e 100644 --- a/test/smartparens-commands-test.el +++ b/test/smartparens-commands-test.el @@ -30,13 +30,28 @@ that are used to test the resulting state after running the command. Each string must contain | to specify where point should be." (declare (indent 1)) - `(ert-deftest ,(intern (concat "sp-test-command-" - (symbol-name command))) () - ,@(mapcar - (lambda (example-group) - `(let ,(car example-group) - (sp--test-command ',command ',(cdr example-group)))) - examples))) + (let* ((group-index 0) + (forms + (-mapcat + (lambda (example-group) + (setq group-index (1+ group-index)) + (let ((example-index 0)) + (mapcar + (lambda (test-sequence) + (setq example-index (1+ example-index)) + `(ert-deftest + ,(intern (concat "sp-test-command-" + (symbol-name command) + "-" + (number-to-string group-index) + "-" + (number-to-string example-index) + )) () + (let ,(car example-group) + (sp--test-command ',command ',(list test-sequence))))) + (cdr example-group)))) + examples))) + `(progn ,@forms))) (defun sp--test-command (command examples) "Run the test for COMMAND." @@ -225,6 +240,15 @@ be." ("(foo)\nbar ;; baz (f|oo) baz\n(quux)" "(foo)\nbar ;; baz (f|oo baz)\n(quux)") + ;; #1010 + ("(foo (baz|) ;; bar\n moo\n mee)" + "(foo (baz| ;; bar\n moo)\n mee)" + "(foo (baz| ;; bar\n moo\n mee))") + + ("(foo (gah|) ?\\; bar baz)" + "(foo (gah| ?\\;) bar baz)" + "(foo (gah| ?\\; bar) baz)") + ;; do not slurp outside of comment ("(foo)\nbar ;; (|foo) baz\n(asd)\n\n" "(foo)\nbar ;; (|foo baz)\n(asd)\n\n" @@ -271,12 +295,7 @@ be." "(f|oo)\nbar ;; baz (foo) baz\n(quux)") ("(foo)\nbar ;; baz (f|oo baz)\n(quux)" - "(foo)\nbar ;; baz (f|oo) baz\n(quux)") - - ;; #634 - ("(let ((a 4)\n ;; (fail)\n |(+ 1)\n ))\n" - "(let ((a 4))\n ;; (fail)\n| (+ 1)\n )\n" - "(let ((a 4)))\n;; (fail)\n|(+ 1)\n\n")) + "(foo)\nbar ;; baz (f|oo) baz\n(quux)")) (((mode 'racket) (sp-sexp-prefix '((racket-mode regexp "#?['`,]@?")))) @@ -433,6 +452,14 @@ be." ("\"(foo |bar) baz\"" "\"(foo \"|\"bar) baz\"") ) + (((mode 'python)) + ("\"foo |bar baz\"" "\"foo \"|\"bar baz\"") + ("'foo |bar baz'" "'foo '|'bar baz'") + ("'foo bar|'" "'foo bar'|''") + + ("\"\"\"foo|bar\"\"\"" "\"\"\"foo\"\"\"|\"\"\"bar\"\"\"") + ) + (((sp-split-sexp-always-split-as-string nil)) ("\"foo |bar baz\"" "\"foo\" |\"bar baz\"") ("\"foo bar|\"" "\"foo bar\"|\"\"") @@ -996,3 +1023,10 @@ This is the behavior of `paredit-convolute-sexp'." (sp-buffer-equals "(foo) (progn |(bar))")))) + +(ert-deftest sp-test-sp-forward-barf-sexp-634 () + (sp-test-with-temp-elisp-buffer "(let ((a 4)\n ;; (fail)\n |(+ 1)\n ))\n" + (call-interactively 'sp-forward-barf-sexp) + (sp-buffer-equals "(let ((a 4))\n ;; (fail)\n (+ 1)\n )\n") + (call-interactively 'sp-forward-barf-sexp) + (sp-buffer-equals "(let ((a 4)))\n;; (fail)\n|(+ 1)\n\n"))) diff --git a/test/smartparens-get-paired-expression-elisp-test.el b/test/smartparens-get-paired-expression-elisp-test.el index 1232701c..64332070 100644 --- a/test/smartparens-get-paired-expression-elisp-test.el +++ b/test/smartparens-get-paired-expression-elisp-test.el @@ -2,7 +2,7 @@ (sp-test-with-temp-elisp-buffer initial (should (equal (sp-get-paired-expression back) result)))) -(ert-deftest sp-test-get-paired-expression-elisp () +(sp-ert-deftest sp-test-get-paired-expression-elisp "Test basic paired expressions in `emacs-lisp-mode'." (sp-test--paired-expression-parse-in-elisp "|(foo bar)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix "")) (sp-test--paired-expression-parse-in-elisp "(foo bar|)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix "")) @@ -36,7 +36,7 @@ (sp-test--paired-expression-parse-in-elisp "|(foo bar \\?)" '(:beg 1 :end 13 :op "(" :cl ")" :prefix "" :suffix "")) ) -(ert-deftest sp-test-get-paired-expression-elisp-backward () +(sp-ert-deftest sp-test-get-paired-expression-elisp-backward "Test basic paired expressions in `emacs-lisp-mode' in backwards." (sp-test--paired-expression-parse-in-elisp "(|foo bar)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix "") t) (sp-test--paired-expression-parse-in-elisp "(foo bar|)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix "") t) @@ -70,7 +70,7 @@ (sp-test--paired-expression-parse-in-elisp "(foo bar \\?)|" '(:beg 1 :end 13 :op "(" :cl ")" :prefix "" :suffix "") t) ) -(ert-deftest sp-test-get-paired-expression-elisp-fail () +(sp-ert-deftest sp-test-get-paired-expression-elisp-fail "Test that we fail on incomplete pairs." (sp-test--paired-expression-parse-in-elisp "|(foo bar" nil) (sp-test--paired-expression-parse-in-elisp "(foo |bar" nil) @@ -91,7 +91,7 @@ (sp-test--paired-expression-parse-in-elisp "|,@foo)" nil) ) -(ert-deftest sp-test-get-paired-expression-elisp-backward-fail () +(sp-ert-deftest sp-test-get-paired-expression-elisp-backward-fail "Test that we fail on incomplete pairs parsing backwards." (sp-test--paired-expression-parse-in-elisp "foo| bar)" nil t) (sp-test--paired-expression-parse-in-elisp "foo bar)|" nil t) @@ -114,7 +114,7 @@ ) ;; Regression tests -(ert-deftest sp-test-get-paired-expression-505 () +(sp-ert-deftest sp-test-get-paired-expression-505 "Test https://github.com/Fuco1/smartparens/issues/505" (sp-test--paired-expression-parse-in-elisp "(foo (|bar \"baz(\"))" '(:beg 6 :end 18 :op "(" :cl ")" :prefix "" :suffix "")) (sp-test--paired-expression-parse-in-elisp "(foo (|bar \"baz(\" ))" '(:beg 6 :end 19 :op "(" :cl ")" :prefix "" :suffix "")) @@ -133,14 +133,14 @@ (sp-test--paired-expression-parse-in-elisp "(foo (|bar ;baz(\n ))" '(:beg 6 :end 24 :op "(" :cl ")" :prefix "" :suffix "")) ) -(ert-deftest sp-test-get-paired-expression-556 () +(sp-ert-deftest sp-test-get-paired-expression-556 "Test https://github.com/Fuco1/smartparens/issues/556" (sp-test--paired-expression-parse-in-elisp "(f| ; ()\n 'x)" '(:beg 1 :end 14 :op "(" :cl ")" :prefix "" :suffix "")) (sp-test--paired-expression-parse-in-elisp "(f ; ()\n |'x)" '(:beg 1 :end 14 :op "(" :cl ")" :prefix "" :suffix "")) (sp-test--paired-expression-parse-in-elisp "(f ; ()\n '|x)" '(:beg 1 :end 14 :op "(" :cl ")" :prefix "" :suffix "")) ) -(ert-deftest sp-test-get-paired-expression-653 () +(sp-ert-deftest sp-test-get-paired-expression-653 "If the point is in a multi-line comment, we should be able to parse a multi-line sexp. From 56ba712dc4339358ccc2a1a067c3b3ed9e2782fa Mon Sep 17 00:00:00 2001 From: Thibaut Verron Date: Thu, 8 Oct 2020 13:31:51 +0200 Subject: [PATCH 08/12] Better merge --- smartparens.el | 52 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/smartparens.el b/smartparens.el index fb568922..5047c122 100644 --- a/smartparens.el +++ b/smartparens.el @@ -3629,8 +3629,13 @@ Return non-nil if at least one escaping was performed." ;; before inserting the "" pair it is now split into two ;; -> which moves us outside the pair (not (eq context 'string)) - ;; the inserted character must have string syntax, otherwise no "context" flip happens - (eq (char-syntax (aref id 0)) ?\")) + ;; the inserted character must have string syntax, + ;; otherwise no "context" flip happens + (eq (syntax-class + (syntax-after + (save-excursion + (backward-char (length id)) + (point)))) 7)) (let ((open id) (close (sp-get-pair id :close))) (sp--escape-region (list open close) @@ -5335,13 +5340,13 @@ This function simply transforms BOUNDS, which is a cons (BEG (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) + ;; (when (equal op cl) (list :beg (car bounds) :end (cdr bounds) - :op cl + :op op :cl cl :prefix (sp--get-prefix (car bounds) op) - :suffix (sp--get-suffix (cdr bounds) cl))))) + :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. @@ -5661,7 +5666,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 @@ -5712,7 +5719,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 @@ -7398,7 +7406,8 @@ Examples: (prefix arg in comment) (list :arg arg :enc enc))) (sp-get (sp-get-enclosing-sexp) (sp-do-move-cl (point)) - (sp--indent-region :beg :end) + (sp--keep-indentation + (sp--indent-region :beg :end)) (sp--run-hook-with-args :op :post-handlers 'barf-forward (list :arg arg :enc enc)))))) (sp-backward-barf-sexp (sp--negate-argument old-arg))))) @@ -7465,8 +7474,9 @@ Examples: ;; pair that was not allowed before. However, such a call is ;; never made in SP, so it's OK for now (allowed-pairs (sp--get-allowed-regexp)) - (allowed-open (sp--get-opening-regexp (sp--get-allowed-pair-list))) - (allowed-close (sp--get-closing-regexp (sp--get-allowed-pair-list))) + ,(if forward + '(allowed-close (sp--get-closing-regexp (sp--get-allowed-pair-list))) + '(allowed-open (sp--get-opening-regexp (sp--get-allowed-pair-list)))) (allowed-strings (sp--get-stringlike-regexp)) (prefix nil)) (while (and (not (or ,eob-test @@ -7614,7 +7624,13 @@ Examples: (or (not allowed) (not (or (sp--valid-initial-delimiter-p (sp--looking-at open)) (sp--valid-initial-delimiter-p (sp--looking-at close))))) - (memq (char-syntax (following-char)) '(?w ?_))) + (or (memq (char-syntax (following-char)) '(?w ?_)) + ;; Specifically for lisp, we consider + ;; sequences of ?\ a symbol + ;; sequence + (and (eq (char-before) ??) + (eq (char-syntax (following-char)) ?\\)) + (and (eq (char-syntax (char-before)) ?\\)))) (forward-char)) (setq n (1- n))) (sp-backward-symbol n))))) @@ -7663,7 +7679,17 @@ Examples: (while (and (not (bobp)) (not (or (sp--valid-initial-delimiter-p (sp--looking-back open)) (sp--valid-initial-delimiter-p (sp--looking-back close)))) +<<<<<<< variant A + (or (memq (char-syntax (preceding-char)) '(?w ?_)) + ;; Specifically for lisp, we consider + ;; sequences of ?\ a symbol + ;; sequence + (and (eq (char-before (1- (point))) ??) + (eq (char-syntax (preceding-char)) ?\\)) + )) +>>>>>>> variant B (memq (char-syntax (preceding-char)) '(?w ?_))) +======= end (backward-char)) ;; skip characters which are symbols with prefix flag (while (and (not (eobp)) @@ -8394,8 +8420,8 @@ Examples: (sp-point-in-string)))) (-when-let (ok (if should-split-as-string (save-excursion - (goto-char (1- (cdr (sp-get-quoted-string-bounds)))) - (sp-get-enclosing-sexp 1)) + (goto-char (car (sp-get-quoted-string-bounds))) + (sp-get-sexp)) (sp-get-enclosing-sexp 1))) (sp-get ok (sp--run-hook-with-args :op :pre-handlers 'split-sexp) From 1444754345d5c8e446459a1c80269c9b91a39e6f Mon Sep 17 00:00:00 2001 From: Thibaut Verron Date: Thu, 8 Oct 2020 13:33:49 +0200 Subject: [PATCH 09/12] Better merge --- smartparens.el | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/smartparens.el b/smartparens.el index 5047c122..5eecf38a 100644 --- a/smartparens.el +++ b/smartparens.el @@ -5340,13 +5340,25 @@ This function simply transforms BOUNDS, which is a cons (BEG (cl (char-to-string (char-before (cdr bounds))))) ;; if the closing and opening isn't the same token, we should ;; return nil +<<<<<<< variant A + (when (equal op cl) +>>>>>>> variant B ;; (when (equal op cl) +======= end (list :beg (car bounds) :end (cdr bounds) +<<<<<<< variant A + :op cl +>>>>>>> variant B :op op +======= end :cl cl :prefix (sp--get-prefix (car bounds) op) +<<<<<<< variant A + :suffix (sp--get-suffix (cdr bounds) cl))))) +>>>>>>> variant B :suffix (sp--get-suffix (cdr bounds) cl))));) +======= end (defun sp-get-string (&optional back) "Find the nearest string after point, or before if BACK is non-nil. @@ -5666,9 +5678,13 @@ 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)) +<<<<<<< variant A + ((and (eq (syntax-class (syntax-after (1- (point)))) 7) +>>>>>>> variant B ((and (memq (syntax-class (syntax-after (1- (point)))) '(7 15)) +======= end (not (sp-char-is-escaped-p (1- (point))))) (if (eq t (sp-point-in-string)) (save-excursion @@ -5719,8 +5735,12 @@ expressions are considered." (sp-get-sexp nil)) ;; TODO: merge the following two conditions and use ;; `sp-get-stringlike-or-textmode-expression' +<<<<<<< variant A + ((and (eq (syntax-class (syntax-after (point))) 7) +>>>>>>> variant B ((and (memq (syntax-class (syntax-after (point))) '(7 15)) +======= end (not (sp-char-is-escaped-p))) ;; It might happen that the string delimiter we are ;; looking at is nested inside another string @@ -7679,7 +7699,6 @@ Examples: (while (and (not (bobp)) (not (or (sp--valid-initial-delimiter-p (sp--looking-back open)) (sp--valid-initial-delimiter-p (sp--looking-back close)))) -<<<<<<< variant A (or (memq (char-syntax (preceding-char)) '(?w ?_)) ;; Specifically for lisp, we consider ;; sequences of ?\ a symbol @@ -7687,9 +7706,6 @@ Examples: (and (eq (char-before (1- (point))) ??) (eq (char-syntax (preceding-char)) ?\\)) )) ->>>>>>> variant B - (memq (char-syntax (preceding-char)) '(?w ?_))) -======= end (backward-char)) ;; skip characters which are symbols with prefix flag (while (and (not (eobp)) From 04d37a61bb252422940c59d89ebfafcefbf18432 Mon Sep 17 00:00:00 2001 From: Thibaut Verron Date: Thu, 8 Oct 2020 13:38:44 +0200 Subject: [PATCH 10/12] Better merge --- smartparens.el | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/smartparens.el b/smartparens.el index 5eecf38a..ee4bbead 100644 --- a/smartparens.el +++ b/smartparens.el @@ -5338,27 +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 -<<<<<<< variant A - (when (equal op cl) ->>>>>>> variant B - ;; (when (equal op cl) -======= end - (list :beg (car bounds) - :end (cdr bounds) -<<<<<<< variant A - :op cl ->>>>>>> variant B - :op op -======= end - :cl cl - :prefix (sp--get-prefix (car bounds) op) -<<<<<<< variant A - :suffix (sp--get-suffix (cdr bounds) cl))))) ->>>>>>> variant B - :suffix (sp--get-suffix (cdr bounds) cl))));) -======= end + (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. @@ -5678,13 +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)) -<<<<<<< variant A - ((and (eq (syntax-class (syntax-after (1- (point)))) 7) ->>>>>>> variant B ((and (memq (syntax-class (syntax-after (1- (point)))) '(7 15)) -======= end (not (sp-char-is-escaped-p (1- (point))))) (if (eq t (sp-point-in-string)) (save-excursion @@ -5735,12 +5716,8 @@ expressions are considered." (sp-get-sexp nil)) ;; TODO: merge the following two conditions and use ;; `sp-get-stringlike-or-textmode-expression' -<<<<<<< variant A - ((and (eq (syntax-class (syntax-after (point))) 7) ->>>>>>> variant B ((and (memq (syntax-class (syntax-after (point))) '(7 15)) -======= end (not (sp-char-is-escaped-p))) ;; It might happen that the string delimiter we are ;; looking at is nested inside another string From ce5348fe0121516314cc9db600a81f03f1f6bc6b Mon Sep 17 00:00:00 2001 From: Thibaut Verron Date: Thu, 8 Oct 2020 16:17:31 +0200 Subject: [PATCH 11/12] "Fix" the new test --- test/smartparens-get-paired-expression-ruby-test.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/smartparens-get-paired-expression-ruby-test.el b/test/smartparens-get-paired-expression-ruby-test.el index dda58350..22f7d341 100644 --- a/test/smartparens-get-paired-expression-ruby-test.el +++ b/test/smartparens-get-paired-expression-ruby-test.el @@ -46,6 +46,7 @@ (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 5 :end 12 :op "%" :cl ")" :prefix "" :suffix "") t)) + '(:beg 7 :end 12 :op "%" :cl ")" :prefix "" :suffix "") t)) From f7e0a8f2600df3d139ae472935eba212b4181c6d Mon Sep 17 00:00:00 2001 From: Thibaut Verron Date: Thu, 8 Oct 2020 16:42:25 +0200 Subject: [PATCH 12/12] "Fix" the new test --- test/smartparens-get-paired-expression-ruby-test.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/smartparens-get-paired-expression-ruby-test.el b/test/smartparens-get-paired-expression-ruby-test.el index 22f7d341..c14649ad 100644 --- a/test/smartparens-get-paired-expression-ruby-test.el +++ b/test/smartparens-get-paired-expression-ruby-test.el @@ -48,5 +48,5 @@ '(: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)) + '(:beg 7 :end 12 :op "(" :cl ")" :prefix "" :suffix "") t))