This page has been locked and cannot be edited.
!Combine HTML Tidy with Emacs I write quite a bit of HTML in emacs, and I often have to clean up html that others have written. The best tool for this is [HTML tidy|http://www.w3.org/People/Raggett/tidy/]. Ken Bowen pointed me towards a bit of code which I reworked in to this emacs function, __tidy-buffer__(): <verbatim> ; Function to run Tidy HTML parser on buffer ; NOTE: this requires external Tidy program (defun tidy-buffer () "Run Tidy HTML parser on current buffer." (interactive) (if (get-buffer "tidy-errs") (kill-buffer "tidy-errs")) (shell-command-on-region (point-min) (point-max) "tidy -f /tmp/tidy-errs -q -i -wrap 72 -c" t) (find-file-other-window "/tmp/tidy-errs") (other-window 1) (delete-file "/tmp/tidy-errs") (message "buffer tidy'ed") ) (global-set-key (kbd "C-x t") 'tidy-buffer) </verbatim> This function basically runs the current buffer through tidy (obviously you have to have that installed first), and then pops up a new buffer with the errors from that process. I bind it to C-xt. This function could be improved my making it work like ''make'' does, that is selecting a particular error in the error buffer could move you to that location in your html file. This will only work in XEmacs right now, someone should write the small fix to the call the shell-command-on-region to make it work in GNU Emacs as well. Just stick this in to your .emacs to try it out. Actually, [this tidy.el|http://www.emacswiki.org/emacs/tidy.el] looks much more complete than mine. It is like 20 times longer, though. __update 8/29/02__: Thanks to Ted Weatherly for supplying the fix for the 'buffer has changed on disk' problem this function used to have. --phil ----- <?plugin AddComment mode=show?> ----- CategoryGeekStuff CategoryEmacs CategoryBlog
comments powered by Disqus.
What links here
Recent Changes Cached
No changes found