Skip to content

Instantly share code, notes, and snippets.

@randrews
Last active May 19, 2021 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randrews/5f1ac95310e6063705e3eecdd9db0094 to your computer and use it in GitHub Desktop.
Save randrews/5f1ac95310e6063705e3eecdd9db0094 to your computer and use it in GitHub Desktop.
(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