Skip to content

Instantly share code, notes, and snippets.

@aumgn
Created May 2, 2012 10:08
Show Gist options
  • Select an option

  • Save aumgn/2575690 to your computer and use it in GitHub Desktop.

Select an option

Save aumgn/2575690 to your computer and use it in GitHub Desktop.
(defun pretty-print1 ()
(interactive)
(beginning-of-buffer) ;; Retourne au debut du buffer
(setq level 0)
(while (search-forward-regexp "<[^\!]" nil t)
(let ((is-ending-tag (is-ending-tag)))
(if is-ending-tag
(setq level (- level 1)))
(indent-before-tag level)
(if (not is-ending-tag)
(setq level (+ level 1))))))
(defun indent-before-tag (indent)
(backward-char 2)
(if (not (is-at-beginning-of-line))
(insert-char ?\n 1))
(insert-char ?\t indent)
(forward-char 2))
(defun is-at-beginning-of-line ()
(setq result t)
(let ((start-point (point)))
(while (not (bolp))
(backward-char 1)
(if (not (or
(equal (following-char) ?\t)
(equal (following-char) ? )))
(setq result nil)))
(goto-char start-point)
result))
(defun is-ending-tag ()
(equal (preceding-char) ?/))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment