Fuco1 / smartparens

Minor mode for Emacs that deals with parens pairs and tries to be smart about it.
GNU General Public License v3.0
1.83k stars 194 forks source link

Disabling sp-navigate-comments-as-sexps has no effect. #837

Open wusticality opened 6 years ago

wusticality commented 6 years ago

EDIT: I may be misunderstanding this setting, if so please let me know! :)

Expected behavior

Unless I'm misunderstanding something, setting sp-navigate-comments-as-sexps to nil should disable smartparens commands like structural navigation from working inside comments.

Actual behavior

The various smartparens commands appear to work even when sp-navigate-comments-as-sexps is set to nil. For example, I can structurally navigate a sexp in a comment in a lisp buffer even when sp-navigate-comments-as-sexps is set to nil.

Steps to reproduce the problem

Set sp-navigate-comments-as-sexps to nil, enable smartparens in a lisp buffer, put a sexp into a comment, and then try using smartparens structural navigation commands within said sexp.

Environment & version information

Fuco1 commented 6 years ago

What this does is that if you turn it on it will treat the entire comment as a sexp for the purposes of jumping up out of it. So if you call sp-up-sexp it will move you out of the comment. Also it overrides the value of sp-navigate-close-if-unbalanced and makes it to be always false when inside comments.

What that does is that if you have a code like

(asdasd 

with autoclosing it will try to balance this and add a closing paren. If you put it in a comment it won't because it might actually be intentional that the code is broken inside a comment (for example, it is a literal example of something).

Is there any reason why you would not want to navigate by structure inside a comment?

Fuco1 commented 6 years ago

If the docstring is not clear enough I'm happy to accept some additional text or changes. If you can describe it better please let me know and we can adjust the text so it better fits the reality!

wusticality commented 6 years ago

Ah I see what you're saying.

Quick question - I noticed that when sp-navigate-comments-as-sexps is true (which is the default I think) that sp-up-sexp jumps forward up out of the comment, but sp-backward-up-sexp does not jump to the beginning of the comment, but to the end of the previous non-comment sexp. Is there a reason for this? When I first saw the docstring for this variable I assumed that all navigation commands would work as if the comment were a sexp, but that doesn't seem to be the case.

Fuco1 commented 6 years ago

I can't think of any reason. Maybe it was convenient somehow for me to do the combination of gotoend + gotobegin and select the comment then delete it, I might have liked the behaviour and kept it so. I really don't remember :D

What you describe is probably more consistent, I think no harm done if we change it to be so.