Last active
May 19, 2021 18:41
-
-
Save randrews/5f1ac95310e6063705e3eecdd9db0094 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun ruby-tag (tagname) | |
(or (equal tagname "%") | |
(equal tagname "%=") | |
(equal tagname "%#"))) | |
(defun property-tag (tagname) | |
(or (equal tagname "a") | |
(equal tagname "div") | |
(equal tagname "img") | |
(equal tagname "span"))) | |
(defun insert-tag (tagname) | |
"Insert tag around point" | |
(interactive "sTag name: ") | |
(cond ((equal tagname "end") | |
(insert "<% end %>")) | |
((equal tagname "else") | |
(insert "<% else %>")) | |
((equal tagname "!") | |
(insert "<!-- -->") | |
(goto-char (- (point) 4))) | |
((equal tagname "#") | |
(insert "<%# %>") | |
(goto-char (- (point) 3))) | |
(t | |
(progn | |
(insert "<" tagname | |
(cond | |
((equal tagname "a") " href=\"\"") | |
((or (equal tagname "div") (equal tagname "span")) " class=\"\"") | |
((equal tagname "img") " src=\"\"") | |
((equal tagname "script") " type=\"text/javascript\"") | |
((ruby-tag tagname) " %") | |
(t "")) | |
">") | |
(if (ruby-tag tagname) | |
(goto-char (- (point) 3)) | |
(let ((final-location (point))) | |
(insert "</" tagname ">") | |
(if (property-tag tagname) | |
(goto-char (- final-location 2)) | |
(goto-char final-location)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment