Diff: EmacsTidy

Differences between version 3 and predecessor to the previous major change of EmacsTidy.

Other diffs: Previous Revision, Previous Author

Newer page: version 3 Last edited on August 29, 2002 12:55 pm by PhilHollenback Revert
Older page: version 2 Last edited on May 13, 2002 2:00 pm by PhilHollenback Revert
@@ -8,8 +8,9 @@
  ; 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) 
@@ -20,14 +21,16 @@
  
 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. 
  
 Actually, [this tidy.el|http://discus.anu.edu.au/~kahlil/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 

version 3

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



Our Founder
ToolboxClick to hide/show