Pilgrim

Pilgrim

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.

PS: I posted this here Emacs Stackexchange in case you think you’ve seen it asked before.

Showing Posts 1 to 7

NobbZ

NobbZ

According to the documentation you have to use (sp-local-pair "<" nil :actions :rem).

Pilgrim

Pilgrim OP

Thanks for trying to help but I get the error message File mode specification error: (wrong-type-argument consp nil) when I use the form suggested in your reply.

NobbZ

NobbZ

In the docs, all examples of sp-local-pair take the major mode as argument.

Though I’m not sure if thats obselete due to your use of sp-with-modes.

Pilgrim

Pilgrim OP

Yeah in this case web-mode is the major mode but it’s not working for some reason. Any way thanks for trying.

OvermindDL1

OvermindDL1

I’ve also noticed this in emacs, it is quite irritating, though expected, I’ve mostly got used to just typing <delete to get a single <. ^.^;

dimitarvp

dimitarvp

How do you format keybinds like you do here in the forum? Never knew.

NobbZ

NobbZ

<kbd> HTML tag, C is created via <kbd>C</kbd>.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews