Diff: EmacsTidy

Differences between version 6 and revision by previous author of EmacsTidy.

Other diffs: Previous Major Revision, Previous Revision

Newer page: version 6 Last edited on April 7, 2009 10:44 pm by PhilHollenback Revert
Older page: version 1 Last edited on August 1, 2001 9:28 pm by 10.1.3.2 Revert
@@ -3,31 +3,68 @@
 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. 
-  
-Also there is a bug where you are sometimes asked 'buffer /tmp/tidy-errs changed on disk, reload?' when you run this multiple times. Haven't fixed that yet.  
  
 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. 
  
-Oh , I just found [this more complete solution |http://dublincore .org/2000 /09/13-tools .html ], which might work better but is way more complicated
+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 RawHtml  
+<script>  
+var idcomments_acct = '011e5665a1128cdbe79c8077f0f04353';  
+var idcomments_post_id;  
+var idcomments_post_url;  
+</script>  
+<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 RawHtml  
+<center>  
+<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>  
+<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">  
+</script>  
+</center>  
+?>  

version 6

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."
  (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)

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.

--phil



Comment on EmacsTidy:

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





Our Founder
ToolboxClick to hide/show