When using Elixir html template (.eex) in web-mode, I sometimes need to type code like <%= for bid <- @bids do %>
. At the moment because the opening left angled bracked is closed immediately with a matching right angled bracket, after I type <-
, I'm left with a closing angled bracket that I don't need and have to delete.
I need help coming up with a way to prevent the left angled bracket from auto closing.
Below is my current web-mode and smartpatens configs:
Web-mode
(use-package web-mode
:ensure t
:mode (("\\.erb\\'" . web-mode)
("\\.mustache\\'" . web-mode)
("\\.html?\\'" . web-mode)
("\\.eex\\'" . web-mode)
("\\.php\\'" . web-mode)
("\\.jsx$" . web-mode))
:init
(setq web-mode-markup-indent-offset 2
web-mode-css-indent-offset 2
web-mode-code-indent-offset 2)
;; make web-mode play nice with smartparens
(setq web-mode-enable-auto-pairing nil)
;(setq web-mode-enable-auto-closing nil)
(setq web-mode-enable-current-element-highlight t)
(setq web-mode-enable-current-column-highlight t)
:config
(sp-with-modes '(web-mode)
(sp-local-pair "<" nil :actions nil)
(sp-local-pair "% " " %"
:unless '(sp-in-string-p)
:post-handlers '(((lambda (&rest _ignored)
(just-one-space)
(save-excursion (insert " ")))
"SPC" "=" "#")))
(sp-local-pair "<% " " %>" :insert "C-b %")
(sp-local-pair "<%= " " %>" :insert "C-b =")
(sp-local-pair "<%# " " %>" :insert "C-b #")
(sp-local-pair "<-" "")))
Smartparens
(use-package smartparens
:ensure t
:hook (prog-mode . smartparens-mode)
:init
;; https://stackoverflow.com/questions/23789962/how-to-disable-emacs-highlighting-whitespace-in-parenthesis
(setq sp-highlight-pair-overlay nil)
:bind
(:map smartparens-mode-map
("C-M-f" . sp-forward-sexp)
("C-M-b" . sp-backward-sexp)
("C-M-a" . sp-backward-down-sexp)
("C-M-e" . sp-up-sexp)
("C-M-w" . sp-copy-sexp)
("C-M-k" . sp-change-enclosing)
("M-k" . sp-kill-sexp)
("C-M-<backspace>" . sp-splice-sexp-killing-backward)
("C-S-<backspace>" . sp-splice-sexp-killing-around)
("C-]" . sp-select-next-thing-exchange))
:config
(require 'smartparens-config)
(sp-local-pair 'emacs-lisp-mode "'" nil :actions nil)
(sp-local-pair 'org-mode "[" nil :actions nil)
(sp-local-pair 'prog-mode "{" nil :post-handlers '((my-create-newline-and-enter-sexp "RET")))
(sp-local-pair 'prog-mode "(" nil :post-handlers '((my-create-newline-and-enter-sexp "RET"))))
Thanks.
(use-package simple-paren :config (simple-paren-define left-pointing-single-arrow ?<-) (simple-paren-define angled-bracket-percent-pair ?<% ?%>) (simple-paren-define angled-bracket-equal-pair ?<%= ?%>))