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

Narrow in sp-region-ok-p after doing syntax checks #805

Merged
merged 1 commit into from
Nov 1, 2017

Conversation

alexmurray
Copy link
Contributor

This ensures sp-point-in-string returns correctly when invoked from
evil-smartparens etc - see expez/evil-smartparens#42

This ensures `sp-point-in-string` returns correctly when invoked from
`evil-smartparens` etc - see expez/evil-smartparens#42
@alexmurray
Copy link
Contributor Author

I ran the unit tests locally and got the same result (5 failing tests) with and without this change:

$ cask exec ert-runner
ad-handle-definition: ‘find-tag-noselect’ got redefined
Finding all versions of R on your system...
Sorry, no version of R could be found on your system.

Mark set

Mark set
Mark set
...........................................Test sp-test-command-sp-mark-sexp-invalid backtrace:

  (if errorp1226 nil (ert-fail (append (funcall form-description-fn-12
  (let ((errorp1226 nil) (form-description-fn-1227 (function (lambda n
  (let (form-description-1225) (let ((errorp1226 nil) (form-descriptio
  (let ((value-1224 (cl-gensym "ert-form-evaluation-aborted-"))) (let 
  (lambda nil (let ((value-1224 (cl-gensym "ert-form-evaluation-aborte
  ert--run-test-internal([cl-struct-ert--test-execution-info [cl-struc
  ert-run-test([cl-struct-ert-test sp-test-command-sp-mark-sexp-invali
  ert-run-or-rerun-test([cl-struct-ert--stats (and t) [[cl-struct-ert-
  ert-run-tests((and t) (lambda (event-type &rest event-args) (cond ((
  ert-runner/run-tests-batch((and t))
  (let ((stats (ert-runner/run-tests-batch selector))) (kill-emacs (if
  ert-runner/run-tests-batch-and-exit((and t))
  (if ert-runner-verbose (ert-runner/run-tests-batch-and-exit ert-runn
  (let ((test-files (ert-runner--test-files tests)) (test-helper (f-ex
  ert-runner/run()
  apply(ert-runner/run nil)
  commander--handle-command(nil)
  commander-parse(nil)
  (if commander-parsing-done nil (commander-parse (or commander-args (
  eval-buffer(#<buffer  *load*> nil "/home/amurray/smartparens/.cask/2
  load-with-code-conversion("/home/amurray/smartparens/.cask/25.3/elpa
  load("/home/amurray/smartparens/.cask/25.3/elpa/ert-runner-20170816.
  command-line-1(("-scriptload" "/home/amurray/smartparens/.cask/25.3/
  command-line()
  normal-top-level()

Test sp-test-command-sp-mark-sexp-invalid condition:

    (ert-test-failed
     ((should-error
       (sp-test-with-temp-elisp-buffer "(progn (foo) |(bar)) (baz)"
	 (call-interactively ...)
	 (call-interactively ...))
       :type 'user-error)
      :form
      (let
	  ((wconfig ...))
	(unwind-protect
	    (progn ...)
	  (set-window-configuration wconfig)))
      :value nil :fail-reason "did not signal an error"))


Mark set
Mark set
FTest sp-test-command-sp-mark-sexp-multiple-invocations backtrace:

  (if (unwind-protect (setq value-22 (apply fn-20 args-21)) (setq form
  (let (form-description-24) (if (unwind-protect (setq value-22 (apply
  (let ((value-22 (quote ert-form-evaluation-aborted-23))) (let (form-
  (let ((fn-20 (function =)) (args-21 (list (1+ (string-match-p "M" (r
  (progn (let ((fn-20 (function =)) (args-21 (list (1+ (string-match-p
  (if (string-match-p "M" result) (progn (let ((fn-20 (function =)) (a
  sp-buffer-equals("|(foo) (bar)M (baz)")
  (progn (set-input-method nil) (emacs-lisp-mode) (smartparens-mode 1)
  (unwind-protect (progn (set-input-method nil) (emacs-lisp-mode) (sma
  (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn
  (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-b
  (let ((case-fold-search nil)) (let ((temp-buffer (generate-new-buffe
  (progn (let ((case-fold-search nil)) (let ((temp-buffer (generate-ne
  (unwind-protect (progn (let ((case-fold-search nil)) (let ((temp-buf
  (let ((wconfig (current-window-configuration))) (unwind-protect (pro
  (lambda nil (let ((wconfig (current-window-configuration))) (unwind-
  ert--run-test-internal([cl-struct-ert--test-execution-info [cl-struc
  ert-run-test([cl-struct-ert-test sp-test-command-sp-mark-sexp-multip
  ert-run-or-rerun-test([cl-struct-ert--stats (and t) [[cl-struct-ert-
  ert-run-tests((and t) (lambda (event-type &rest event-args) (cond ((
  ert-runner/run-tests-batch((and t))
  (let ((stats (ert-runner/run-tests-batch selector))) (kill-emacs (if
  ert-runner/run-tests-batch-and-exit((and t))
  (if ert-runner-verbose (ert-runner/run-tests-batch-and-exit ert-runn
  (let ((test-files (ert-runner--test-files tests)) (test-helper (f-ex
  ert-runner/run()
  apply(ert-runner/run nil)
  commander--handle-command(nil)
  commander-parse(nil)
  (if commander-parsing-done nil (commander-parse (or commander-args (
  eval-buffer(#<buffer  *load*> nil "/home/amurray/smartparens/.cask/2
  load-with-code-conversion("/home/amurray/smartparens/.cask/25.3/elpa
  load("/home/amurray/smartparens/.cask/25.3/elpa/ert-runner-20170816.
  command-line-1(("-scriptload" "/home/amurray/smartparens/.cask/25.3/
  command-line()
  normal-top-level()

Test sp-test-command-sp-mark-sexp-multiple-invocations condition:

    (ert-test-failed
     ((should
       (=
	(1+ ...)
	(mark)))
      :form
      (= 12 6)
      :value nil))


Can’t guess python-indent-offset, using defaults: 4
Can’t guess python-indent-offset, using defaults: 4
Can’t guess python-indent-offset, using defaults: 4

Rewrap with: 
^[>
Indenting region...
Indenting region...done

Indenting region...
Indenting region...done
F.........................................................................................................................................................................................................................................................Test sp-test-ruby-barf-forward backtrace:

  (if (unwind-protect (setq value-337 (apply fn-335 args-336)) (setq f
  (let (form-description-339) (if (unwind-protect (setq value-337 (app
  (let ((value-337 (quote ert-form-evaluation-aborted-338))) (let (for
  (let ((fn-335 (function sp-ruby-eq-ignore-indent)) (args-336 (list (
  (progn (ruby-mode) (smartparens-mode 1) (save-excursion (insert in))
  (unwind-protect (progn (ruby-mode) (smartparens-mode 1) (save-excurs
  (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn
  (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-b
  (progn (fset (quote load) (function shut-up-load)) (fset (quote writ
  (unwind-protect (progn (fset (quote load) (function shut-up-load)) (
  (let* ((vnew (function (lambda (char) (shut-up-insert-to-buffer char
  (unwind-protect (let* ((vnew (function (lambda (char) (shut-up-inser
  (if shut-up-ignore (progn (let ((temp-buffer (generate-new-buffer " 
  (let (--cl-shut-up-current-output--) (setq --cl-shut-up-current-outp
  (let ((shut-up-sink (generate-new-buffer " *shutup*")) (inhibit-mess
  sp-ruby-test-barf-assert(1 "\nbeginX\n  Module::Class\nend\n" :=> "\
  (lambda nil (sp-ruby-test-barf-assert 1 "\nif teXst\n  foo\nend\n" :
  ert--run-test-internal([cl-struct-ert--test-execution-info [cl-struc
  ert-run-test([cl-struct-ert-test sp-test-ruby-barf-forward nil (lamb
  ert-run-or-rerun-test([cl-struct-ert--stats (and t) [[cl-struct-ert-
  ert-run-tests((and t) (lambda (event-type &rest event-args) (cond ((
  ert-runner/run-tests-batch((and t))
  (let ((stats (ert-runner/run-tests-batch selector))) (kill-emacs (if
  ert-runner/run-tests-batch-and-exit((and t))
  (if ert-runner-verbose (ert-runner/run-tests-batch-and-exit ert-runn
  (let ((test-files (ert-runner--test-files tests)) (test-helper (f-ex
  ert-runner/run()
  apply(ert-runner/run nil)
  commander--handle-command(nil)
  commander-parse(nil)
  (if commander-parsing-done nil (commander-parse (or commander-args (
  eval-buffer(#<buffer  *load*> nil "/home/amurray/smartparens/.cask/2
  load-with-code-conversion("/home/amurray/smartparens/.cask/25.3/elpa
  load("/home/amurray/smartparens/.cask/25.3/elpa/ert-runner-20170816.
  command-line-1(("-scriptload" "/home/amurray/smartparens/.cask/25.3/
  command-line()
  normal-top-level()

Test sp-test-ruby-barf-forward condition:

    (ert-test-failed
     ((should
       (sp-ruby-eq-ignore-indent
	(buffer-string)
	expected))
      :form
      (sp-ruby-eq-ignore-indent "
begin
  Module
  end::Class
" "
begin
end
Module::Class
")
      :value nil))

F......Test sp-test-ruby-slurp-backward backtrace:

  (while (> n 0) (goto-char (let ((struct enc)) (- (plist-get struct :
  (if (sp--raw-argument-p arg) (progn (goto-char (let ((struct enc)) (
  (save-excursion (if (sp--raw-argument-p arg) (progn (goto-char (let 
  (progn (save-excursion (if (sp--raw-argument-p arg) (progn (goto-cha
  (if enc (progn (save-excursion (if (sp--raw-argument-p arg) (progn (
  (let ((n (abs (prefix-numeric-value arg))) (enc (sp-get-enclosing-se
  (if (> (prefix-numeric-value arg) 0) (let ((n (abs (prefix-numeric-v
  sp-backward-slurp-sexp(4)
  (if (> (prefix-numeric-value arg) 0) (let ((n (abs (prefix-numeric-v
  sp-forward-slurp-sexp(-4)
  (progn (ruby-mode) (smartparens-mode 1) (save-excursion (insert in))
  (unwind-protect (progn (ruby-mode) (smartparens-mode 1) (save-excurs
  (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn
  (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-b
  (progn (fset (quote load) (function shut-up-load)) (fset (quote writ
  (unwind-protect (progn (fset (quote load) (function shut-up-load)) (
  (let* ((vnew (function (lambda (char) (shut-up-insert-to-buffer char
  (unwind-protect (let* ((vnew (function (lambda (char) (shut-up-inser
  (if shut-up-ignore (progn (let ((temp-buffer (generate-new-buffer " 
  (let (--cl-shut-up-current-output--) (setq --cl-shut-up-current-outp
  (let ((shut-up-sink (generate-new-buffer " *shutup*")) (inhibit-mess
  sp-ruby-test-slurp-assert(-4 "\ntest ? a : b\nbeginX\nend\n" :=> "\n
  (lambda nil (sp-ruby-test-slurp-assert -1 "\nfoo.bar\nbegin X\nend\n
  ert--run-test-internal([cl-struct-ert--test-execution-info [cl-struc
  ert-run-test([cl-struct-ert-test sp-test-ruby-slurp-backward nil (la
  ert-run-or-rerun-test([cl-struct-ert--stats (and t) [[cl-struct-ert-
  ert-run-tests((and t) (lambda (event-type &rest event-args) (cond ((
  ert-runner/run-tests-batch((and t))
  (let ((stats (ert-runner/run-tests-batch selector))) (kill-emacs (if
  ert-runner/run-tests-batch-and-exit((and t))
  (if ert-runner-verbose (ert-runner/run-tests-batch-and-exit ert-runn
  (let ((test-files (ert-runner--test-files tests)) (test-helper (f-ex
  ert-runner/run()
  apply(ert-runner/run nil)
  commander--handle-command(nil)
  commander-parse(nil)
  (if commander-parsing-done nil (commander-parse (or commander-args (
  eval-buffer(#<buffer  *load*> nil "/home/amurray/smartparens/.cask/2
  load-with-code-conversion("/home/amurray/smartparens/.cask/25.3/elpa
  load("/home/amurray/smartparens/.cask/25.3/elpa/ert-runner-20170816.
  command-line-1(("-scriptload" "/home/amurray/smartparens/.cask/25.3/
  command-line()
  normal-top-level()

Test sp-test-ruby-slurp-backward condition:

    (wrong-type-argument number-or-marker-p nil)

FTest sp-test-ruby-slurp-forward backtrace:

  (while (> n 0) (goto-char (let ((struct enc)) (+ (plist-get struct :
  (if (sp--raw-argument-p arg) (progn (goto-char (let ((struct enc)) (
  (save-excursion (if (sp--raw-argument-p arg) (progn (goto-char (let 
  (progn (save-excursion (if (sp--raw-argument-p arg) (progn (goto-cha
  (if enc (progn (save-excursion (if (sp--raw-argument-p arg) (progn (
  (let ((n (abs (prefix-numeric-value arg))) (enc (sp-get-enclosing-se
  (if (> (prefix-numeric-value arg) 0) (let ((n (abs (prefix-numeric-v
  sp-forward-slurp-sexp(4)
  (progn (ruby-mode) (smartparens-mode 1) (save-excursion (insert in))
  (unwind-protect (progn (ruby-mode) (smartparens-mode 1) (save-excurs
  (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn
  (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-b
  (progn (fset (quote load) (function shut-up-load)) (fset (quote writ
  (unwind-protect (progn (fset (quote load) (function shut-up-load)) (
  (let* ((vnew (function (lambda (char) (shut-up-insert-to-buffer char
  (unwind-protect (let* ((vnew (function (lambda (char) (shut-up-inser
  (if shut-up-ignore (progn (let ((temp-buffer (generate-new-buffer " 
  (let (--cl-shut-up-current-output--) (setq --cl-shut-up-current-outp
  (let ((shut-up-sink (generate-new-buffer " *shutup*")) (inhibit-mess
  sp-ruby-test-slurp-assert(4 "\nbeginX\nend\ntest ? a : b\n" :=> "\nb
  (lambda nil (sp-ruby-test-slurp-assert 1 "\nif teXst\nend\nfoo\n" :=
  ert--run-test-internal([cl-struct-ert--test-execution-info [cl-struc
  ert-run-test([cl-struct-ert-test sp-test-ruby-slurp-forward nil (lam
  ert-run-or-rerun-test([cl-struct-ert--stats (and t) [[cl-struct-ert-
  ert-run-tests((and t) (lambda (event-type &rest event-args) (cond ((
  ert-runner/run-tests-batch((and t))
  (let ((stats (ert-runner/run-tests-batch selector))) (kill-emacs (if
  ert-runner/run-tests-batch-and-exit((and t))
  (if ert-runner-verbose (ert-runner/run-tests-batch-and-exit ert-runn
  (let ((test-files (ert-runner--test-files tests)) (test-helper (f-ex
  ert-runner/run()
  apply(ert-runner/run nil)
  commander--handle-command(nil)
  commander-parse(nil)
  (if commander-parsing-done nil (commander-parse (or commander-args (
  eval-buffer(#<buffer  *load*> nil "/home/amurray/smartparens/.cask/2
  load-with-code-conversion("/home/amurray/smartparens/.cask/25.3/elpa
  load("/home/amurray/smartparens/.cask/25.3/elpa/ert-runner-20170816.
  command-line-1(("-scriptload" "/home/amurray/smartparens/.cask/25.3/
  command-line()
  normal-top-level()

Test sp-test-ruby-slurp-forward condition:

    (wrong-type-argument number-or-marker-p nil)


Mark set
Mark set

Indenting region...
Indenting region...done

Matches: (foo bar)

Matches: (foo bar)

Matches: (foo bar)

Matches: (foo bar)
F......................................................................................

Ran 389 tests in 31.355 seconds
5 unexpected results:
   FAILED  sp-test-command-sp-mark-sexp-invalid
   FAILED  sp-test-command-sp-mark-sexp-multiple-invocations
   FAILED  sp-test-ruby-barf-forward
   FAILED  sp-test-ruby-slurp-backward
   FAILED  sp-test-ruby-slurp-forward

@Fuco1
Copy link
Owner

Fuco1 commented Nov 1, 2017

Yea, this makes sense to me. The string-context check is there as a "fast-fail", basically because if your region spans a bit inside and a bit outside of a string then you can never have balanced expression whatsoever.

The failing tests appeared in some newer Emacs version and I still haven't had the chance to look at them, but these are the five "allowed" fails for now.

Thanks for all the investigation you put into this!

@Fuco1 Fuco1 merged commit 9682ba9 into Fuco1:master Nov 1, 2017
@alexmurray alexmurray deleted the narrow-after-syntax-ppss-check branch November 1, 2017 10:32
@alexmurray
Copy link
Contributor Author

Thanks for merging the fix - and for this awesome package 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants