I found out that smartparens
has a similar command that has slightly different behaviour and works better with Erlang or languages that use separators like C. The command is sp-slurp-hybrid-sexp
.
With it I get the result I wanted:
Name = [∎"Joe"].
Unfortunately neither command work perfectly to slurp items and handle separator in all cases. Slurping from [1,2,3], 4, 5
may end up with [1,2,3 4], 5
or [1,2,3 4],,5
. I assume that more work is required to properly support Erlang and some extra learning of the implementation logic is required.
Update - To properly fix the issue : use a function that fix the block:
My final solution to this problem was to write a function that checks the validity of the comma separated block and fix it if it's invalid. Then add that function as a post handler for Erlang operation.
The function I wrote for this is pel-syntax-fix-block-content
, available in this answer.
The I wrote the following and my init calls pel-smartparens-setup-erlang
when smartparens cod in an erlang-mode buffer:
(defun pel-sp-erlang-handler (_id action _context)
"Check validity of block and fix it if it was broken by smartparens.
This is a smartparens post-handler and receives 3 arguments:
ID, ACTION and CONTEXT."
(when (memq action '(slurp-forward
barf-forward
split-sexp))
(pel-syntax-fix-block-content (- (point) 2))
(forward-char 2)))
(defun pel-smartparens-setup-erlang ()
"Configure smartparens for Erlang.
This must be called within the scope of a erlang-mode buffer."
(sp-local-pair 'erlang-mode "(" ")"
:actions '(insert wrap autoskip navigate)
:post-handlers '(pel-sp-erlang-handler))
(sp-local-pair 'erlang-mode "[" "]"
:actions '(insert wrap autoskip navigate)
:post-handlers '(pel-sp-erlang-handler))
(sp-local-pair 'erlang-mode "{" "}"
:actions '(insert wrap autoskip navigate)
:post-handlers '(pel-sp-erlang-handler))
(sp-local-pair 'erlang-mode "<<" ">>"
:actions '(insert wrap autoskip navigate)
:post-handlers '(pel-sp-erlang-handler)))