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

Pair highlight on opening bracket but not on the ending bracket #894

Open AkashGanesan opened 6 years ago

AkashGanesan commented 6 years ago

Expected behavior

When the cursor is on function in the below, it highlights both the brackets defined.

function

..

endfunction

However, when I place my cursor on the endfunction, it doesn't highltight both the words.

Actual behavior

Cursor on endfunction should highlight 'function' as well.

Steps to reproduce the problem

Open a verilog mode file (.sv, .v, .svh); I assume it will also work in any other mode.

(sp-local-pair 'verilog-mode "function" "endfunction") M-x show-smartparens-mode

Backtraces if necessary (M-x toggle-debug-on-error)

Environment & version information

From sp-describe-system:

And no, I'm not using evil.

Fuco1 commented 6 years ago

Can you fill the Environment section? You are probably using evil.

AkashGanesan commented 6 years ago

I've updated the environment section. Weirdly, sp-describe-system doesn't do anything.

And I'm not using evil but I do have it installed. I disabled it after startup (haven't removed it from my config so starts with evil active and I disable it after startup).

Fuco1 commented 6 years ago

The command should ask you for information if it cant detect it and then put the thing into your clipboard so you can paste it here.

I guess I should pop a buffer instead so that people see the result, might be better UX :+1:

Are you putting the cursor at the beginning or end of endfunction. Right now it will only work if the point is after the last n. If you want it to work in the beginning also you can set sp-show-pair-from-inside to t. This will however change it globally, it's not possible to change itonly for a certain pair. I was thinking about adding a pair permission for highlighting but it was never implemented.

I don't think there's any way to make it highlight if the cursor is in the middle of the delimiter.

AkashGanesan commented 6 years ago

Or a line in the command buffer saying the info has be copied to the clipboard. That should be fine as well.

Also, I tried it with the cursor at the end but it is not highlighting. Even after setting sp-show-pair-from-inside, it still doesn't highlight when I try it on the end or the starting of endfunction.

Is there a character limit on how long this can be? I vaguely remember a 10 character limit somewhere but can't find the documentation for it anywhere.

AkashGanesan commented 6 years ago

(defconst sp-max-pair-length 10 "Maximum length of an opening or closing delimiter."

I found this in the Smartparens.el. Is this limit applied since endfunction is longer than 10 chars long?

AkashGanesan commented 6 years ago

UPDATE: So, I did the following

(defconst sp-max-pair-length 15)

With this, it detects it correctly. I also tired to see if this is the issue and changed it to 5 and it doesn't detect it.

So, this variable is the one to change. Al least in case of verilog mode.

Does changing this limit break anything else? Or do I have to change certain other values dependent on this?

Fuco1 commented 6 years ago

Oh, interesting. That would take me quite some time to figure out :D

The constant only serves a performance reason because backward regexp search is really slow in Emacs. Changing it to 15 or 20 shouldn't make much difference though.

I should probably just get rid of it and calculate the length based on the longest pair. The reason being that we create regexpes and sometimes a run-away search might happen so this caps that.