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

Electric > for blank tags (a.k.a fragments) #112

Open
goranmoomin opened this issue Jul 28, 2019 · 2 comments
Open

Electric > for blank tags (a.k.a fragments) #112

goranmoomin opened this issue Jul 28, 2019 · 2 comments

Comments

@goranmoomin
Copy link

When using rjsx-mode, I really love the electricity feature of the > key.
I have found that, when inserting blank tags (a.k.a fragments), the electric > doesn't work, which makes inserting fragments very tedious.
rjsx-fragments
I would like if the electric > works for blank tags too.

@sooqua
Copy link

sooqua commented Sep 11, 2019

  (defun +javascript-rjsx-electric-gt-a (n)
    (when (and (looking-back "<>")
               (looking-at-p "/>"))
      (save-excursion (insert "<"))))
  (advice-add #'rjsx-electric-gt :after #'+javascript-rjsx-electric-gt-a)

@MageJohn
Copy link

MageJohn commented Feb 4, 2021

I think this advice is probably faster (not that yours is slow, I just spotted some optimisations):

(defun +rjsx-electric-gt-fragment-a (n)
  (if (or (/= n 1) (not (and (eq (char-before) ?<) (eq (char-after) ?/)))) 't
    (insert ?> ?<)
    (backward-char)))
(advice-add #'rjsx-electric-gt :before-while #'+rjsx-electric-gt-fragment-a)

It uses all low level functions defined in C, and it will also completely skip rjsx-electric-gt if it can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants