/ Published in: Lisp
Expand |
Embed | Plain Text
;;; ;;; Run tidy (http://www.w3.org/People/Raggett/tidy/) on the contents ;;; of the current buffer. If tidy produces error messages, split the ;;; buffer's window to show them. ;;; ;;; Since the original contents of the buffer are deleted and replaced ;;; by tidy's output, preserving point is difficult. The best we can ;;; do is restore point to the same character position that it started ;;; with. ;;; ;;; Kevin Christen ;;; $Date: 2001/02/23 13:48:57 $ ;;; $Revision: 1.2 $ ;;; (defun tidy-buffer () (interactive) (let ((tidy-program "tidy") (tidy-arguments "-q") (stderr-file ; Temp file for tidy's stderr (make-temp-name (concat temporary-file-directory "tidy-stderr"))) (stderr-buffer-name "*Tidy Output*") (original-point (point))) ;; Call tidy. `call-process-region' won't allow stdout and stderr ;; to both be directed to buffers, so put stdout in the current ;; buffer (replacing its contents) and stderr in a temporary file. (call-process-region (point-min) (point-max) tidy-program t (list (current-buffer) stderr-file) nil tidy-arguments) (goto-char original-point) ; Restore point ;; Create a buffer for stderr and read temp file contents into it (get-buffer-create stderr-buffer-name) (save-excursion (set-buffer stderr-buffer-name) (erase-buffer) (insert-file-contents stderr-file) (cond ((= (point-min) (point-max)) (delete-windows-on (current-buffer)) (kill-buffer (current-buffer))))) ;; Delete temp file (delete-file stderr-file) ;; Make the error messages magically appear (if (get-buffer stderr-buffer-name) (set-window-buffer (split-window) stderr-buffer-name))))
You need to login to post a comment.
