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

Fix #707 (partly) #1057

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion smartparens-elixir.el
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
(--each '(elixir-mode)
(add-to-list 'sp-sexp-suffix (list it 'regexp "")))

(defun sp-elixir-do-keyword-p (id _action _context)
"Return non-nil if the \"do:\" keyword is part of definition.

ID is the opening delimiter.

Skips the definition if it contains \"do:\" because such syntax
has no \"end\" delimiter."
(let ((line (thing-at-point 'line t)))
(string-match-p "\\bdo:" line)))

(defun sp-elixir-def-p (id)
"Return non-nil if the \"do\" keyword is part of definition.

Expand Down Expand Up @@ -60,7 +70,8 @@ def-do-end and similar pairs."
(defun sp-elixir-skip-def-p (ms _mb _me)
"Test if \"do\" is part of definition.
MS, MB, ME."
(sp-elixir-def-p ms))
(or (sp-elixir-def-p ms)
(sp-elixir-do-keyword-p ms _mb _me)))

(defun sp-elixir-do-block-post-handler (_id action _context)
"Insert \"do\" keyword and indent the new block.
Expand Down Expand Up @@ -102,32 +113,38 @@ ID, ACTION, CONTEXT."
(sp-local-pair "def" "end"
:when '(("SPC" "RET" "<evil-ret>"))
:post-handlers '(sp-elixir-do-block-post-handler)
:skip-match 'sp-elixir-do-keyword-p
:unless '(sp-in-comment-p sp-in-string-p))
(sp-local-pair "defp" "end"
:when '(("SPC" "RET" "<evil-ret>"))
:post-handlers '(sp-elixir-do-block-post-handler)
:skip-match 'sp-elixir-do-keyword-p
:unless '(sp-in-comment-p sp-in-string-p))
(sp-local-pair "defmodule" "end"
:when '(("SPC" "RET" "<evil-ret>"))
:post-handlers '(sp-elixir-do-block-post-handler)
:skip-match 'sp-elixir-do-keyword-p
:unless '(sp-in-comment-p sp-in-string-p))
(sp-local-pair "fn" "end"
:when '(("SPC" "RET" "<evil-ret>"))
:post-handlers '("| "))
(sp-local-pair "if" "end"
:when '(("SPC" "RET" "<evil-ret>"))
:post-handlers '(sp-elixir-do-block-post-handler)
:skip-match 'sp-elixir-do-keyword-p
:unless '(sp-in-comment-p sp-in-string-p))
(sp-local-pair "unless" "end"
:when '(("SPC" "RET" "<evil-ret>"))
:post-handlers '(sp-elixir-do-block-post-handler)
:skip-match 'sp-elixir-do-keyword-p
:unless '(sp-in-comment-p sp-in-string-p))
(sp-local-pair "case" "end"
:when '(("SPC" "RET" "<evil-ret>"))
:post-handlers '(sp-elixir-do-block-post-handler)
:unless '(sp-in-comment-p sp-in-string-p))
(sp-local-pair "receive" "end"
:when '(("RET" "<evil-ret>"))
:skip-match 'sp-elixir-do-keyword-p
:post-handlers '(sp-elixir-empty-do-block-post-handler))
)

Expand Down