From ec90f8cf45001becd1a29ac446be6db8f26fab1a Mon Sep 17 00:00:00 2001 From: Federico Builes Date: Tue, 30 Dec 2008 16:59:14 -0500 Subject: [PATCH] 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'. --- extra/haml-mode.el | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/extra/haml-mode.el b/extra/haml-mode.el index 267a4761..92b3c08d 100644 --- a/extra/haml-mode.el +++ b/extra/haml-mode.el @@ -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