Reindent code regions before processing them in haml-mode.el

* haml-replace-region and haml-output-region now reindent the code 
regions before sending them to 'haml'.
This commit is contained in:
Federico Builes 2008-12-30 16:59:14 -05:00
parent 1185a59abd
commit ec90f8cf45
1 changed files with 15 additions and 4 deletions

View File

@ -180,15 +180,26 @@ text nested beneath them.")
(kill-line 1)
(haml-reindent-region-by (- haml-indent-offset))))
(defun haml-replace-region (begin end)
(defun haml-replace-region (start end)
"Replaces the current block of Haml code with the HTML equivalent."
(interactive "r")
(shell-command-on-region begin end "haml" "haml-output" t))
(save-excursion
(goto-char end)
(setq end (point-marker))
(goto-char start)
(let ((ci (current-indentation)))
(while (re-search-forward "^ +" end t)
(replace-match (make-string (- (current-indentation) ci) ? ))))
(shell-command-on-region start end "haml" "haml-output" t)))
(defun haml-output-region (begin end)
(defun haml-output-region (start end)
"Displays the HTML output for the current block of Haml code."
(interactive "r")
(shell-command-on-region begin end "haml" "haml-output" nil))
(kill-new (buffer-substring start end))
(with-temp-buffer
(yank)
(haml-indent-region (point-min) (point-max))
(shell-command-on-region (point-min) (point-max) "haml" "haml-output")))
;; Navigation