Diff: EmacsTidy

Differences between current version and previous revision of EmacsTidy.

Other diffs: Previous Major Revision, Previous Author

Newer page: version 7 Last edited on March 1, 2012 3:50 pm by PhilHollenback
Older page: version 6 Last edited on April 7, 2009 10:44 pm by PhilHollenback Revert
@@ -37,34 +37,13 @@
-<?plugin RawHtml  
-var idcomments_acct = '011e5665a1128cdbe79c8077f0f04353';  
-var idcomments_post_id;  
-var idcomments_post_url;  
-<span id="IDCommentsPostTitle" style="display:none"></span>  
-<script type='text/javascript' src='http://www.intensedebate.com/js/genericCommentWrapperV2.js'></script>  
- ?> 
+<?plugin AddComment mode =show ?> 
-<?plugin AddComment mode=show?>  
-<?plugin RawHtml  
-<script type="text/javascript"><!--  
-google_ad_client = "pub-5011581245921339";  
-google_ad_width = 728;  
-google_ad_height = 90;  
-google_ad_format = "728x90_as";  
-google_ad_channel ="";  
-google_ad_type = "text";  
-<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">  

current version

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.

Ken Bowen pointed me towards a bit of code which I reworked in to this emacs function, tidy-buffer():

 ; Function to run Tidy HTML parser on buffer
 ; NOTE: this requires external Tidy program
 (defun tidy-buffer ()
  "Run Tidy HTML parser on current buffer."
  (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)

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 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.


Comment on EmacsTidy:

Exactly what I was looking for! I like that its short and simple too!




Our Founder
ToolboxClick to hide/show