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

Allow inserting closing delimiters for non-autoskip pairs #712

Merged
merged 1 commit into from
Jun 5, 2017

Conversation

johnmastro
Copy link
Contributor

Don't inhibit inserting closing delimiters for pairs that don't use the autoskip action.

Commit a677859 added code to prevent closing delimiters from being inserted in strict mode. Typing a closing delimiter will either skip over the delimiter that was automatically inserted, or emit a message that an unbalanced delimiter was blocked from insertion. I think it makes sense to exempt from this pairs that don't use the autoskip action (and/or the insert action? more on that below), since in that case the only reason to type the closing delimiter is if you want to insert it.

I ran into this because, in C-like modes, I set up {} for the navigate and wrap actions, but not insert or autoskip.

It may also make sense to exempt pairs without the insert action, for basically the same reason - if you've configured Smartparens not to insert the closing delimiter for you, you probably intend to type it yourself. However, I never use insert without autoskip or vice versa, so I'm not sure. Of the two, I went with autoskip because it is more directly connected to typing a closing delimiter.

@johnmastro
Copy link
Contributor Author

For a test, would something like this be appropriate?

(ert-deftest sp-test-sp-dont-inhibit-closing-pair-unless-autoskip ()
  (sp-test-with-temp-buffer "" nil
    (let ((sp-pairs sp-pairs))
      (smartparens-strict-mode)
      (sp-local-pair major-mode "{" "}" :actions '(insert autoskip navigate wrap))
      (execute-kbd-macro "}")
      (should (eq (char-before) nil))
      (sp-local-pair major-mode "{" "}" :actions '(:rem autoskip))
      (execute-kbd-macro "}")
      (should (eq (char-before) ?\})))))

johnmastro added a commit to johnmastro/.emacs.d that referenced this pull request Mar 2, 2017
Pull request to address the issue (as I see it) in Smartparens:
Fuco1/smartparens#712
@Fuco1 Fuco1 self-requested a review June 4, 2017 17:07
Copy link
Owner

@Fuco1 Fuco1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can go with autoskip for now. Later I have some thoughts of making the system a bit more fine-grained so we can have a permission for autoskip and for the insertion inhibition as separate things (as well as the regular insert action)

smartparens.el Outdated
last (sp--get-allowed-pair-list))
(-when-let (pair (sp--char-is-part-of-closing
last (sp--get-allowed-pair-list)))
(memq 'autoskip (plist-get (sp-get-pair (car pair)) :actions)))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can pass the keyword as an argument to sp-get-pair which I think is slightly better if we later decide to change the internal representation.

@Fuco1
Copy link
Owner

Fuco1 commented Jun 4, 2017

The test is fine if it works :)

@Fuco1 Fuco1 self-assigned this Jun 4, 2017
@johnmastro johnmastro force-pushed the maybe-skip-closing branch from 3f9edcb to 1738ef5 Compare June 4, 2017 20:49
Don't inhibit inserting closing delimiters for pairs that don't use the
autoskip action.
@johnmastro johnmastro force-pushed the maybe-skip-closing branch from 1738ef5 to 249ac32 Compare June 5, 2017 17:21
@johnmastro
Copy link
Contributor Author

Thanks for taking a look and for the feedback. I force-pushed an updated commit using the optional argument for sp-get-pair I had missed plus adding the test.

@Fuco1
Copy link
Owner

Fuco1 commented Jun 5, 2017

Great! Sorry it took me so long.

In the future don't hesitate to @ ping me if I take too long. My github workflow suck and I get tasks lost so often :/

@Fuco1 Fuco1 merged commit 6427125 into Fuco1:master Jun 5, 2017
@johnmastro
Copy link
Contributor Author

No need to apologize but I will ping in the future - didn't want to be a bother if you just hadn't had a chance to get to it :) Thanks for reviewing/merging!

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