Created
May 2, 2012 10:08
-
-
Save aumgn/2575690 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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