Tidy/Emacs combo tip

If anyone uses the unix Emacs editor, this tip is for you.

I've found that when hacking on CGI, SSI programs and even straightforward 
HTML files, I prefer to parse the HTML code thru Tidy from with my editor 
screen as
opposed to "tidying" the whole file from command line. I'm use Emacs for all 
my editing, and here's a great way to incorporate Tidy right into Emacs, so 
you can clean up HTML code on the fly.
This lets you highlight a region of text and run Tidy on it. Tidy's "fixed" 
output will replace your highlighted region right in place. The error/warnings 
output will be directed into a separate mini-buffer below in your main screen. 
If you don't like the result, simply hit your "undo" button and your original 
code comes back. If you like the result, simply save the file and continue 
typing. Voila!

Note that I bind this function to the Ctl-xt key stroke combination, which by 
default has no binding in emacs.

Add this to your .emacs config file:

--------- snip ------------------------------

; Function to run Tidy HTML parser on region 
; NOTE: this requires external Tidy program
(global-set-key "\C-xt" 'tidy-region)
(define-key ctl-x-map "it" 'tidy-region)
(setq shell-command-default-error-buffer "tidy-errors") ; define an error 
(defun tidy-region ()
  "Run Tidy HTML parser on current region."
  (let ((start (mark))
	(end (point))
	(command "tidy"))
	(shell-command-on-region start end command t t  shell-command-default-error-bu

-------- /snip --------------------------------

A side note: I further bind the following function to my F8 key so I can 
quickly scan the error file buffer, kill it and continue typing without 
missing a beat or closing/changing windows. Anything to make life easier, 

----------- snip #2 --------------------------------
; Kill other window and and enlarge current buffer
(global-set-key [f8] 'kill-buffer-other-window) 
(defun kill-buffer-other-window (arg)
  "Kill the buffer in the other window, and make the current buffer full size. 
If no
      other window, kills current buffer."
  (interactive "p")
  (let ((buf (save-window-excursion
	       (other-window arg)
    (delete-windows-on buf)
    (kill-buffer buf))  )

------------- /snip #2 ------------------------------------




Received on Monday, 1 May 2000 13:10:12 UTC