Hi List
Here is a small patch for the jalopy interface that Nascif Abousalh-Neto
wrote.
You can find his package at
http://home.nc.rr.com/nascifandelaine/emacs.html
The patch enables you to do beautifying on the current buffer instead of
the underlying file.
Paste the contents into the jde-jalopy.el file. Call the function
jde-jalopy-buffer for beautifying.
Feel free to improve the code ;-)
Cheers
(defun jde-jalopy-buffer ()
"Sends the current buffer to jalopy for beautifying."
"This is a interactive function that sends the contents "
"of the current buffer to jalopy for compilation."
(interactive)
(save-some-buffers nil nil)
(if jde-jalopy-option-read-args
(setq jde-interactive-jalopy-args
(read-from-minibuffer
"Jalopy args: "
jde-interactive-jalopy-args
nil nil
'(jde-interactive-jalopy-arg-history . 1))))
(let ((path-sep (if (eq system-type 'windows-nt)
"\\" ;;windows file seperator
"/")) ;;unix file seperator
(jalopy-compilation-buffer "*jalopy-compilation*"))
(let ((source-file-name (buffer-name))
(jalopy-script-home (concat jde-jalopy-option-path path-sep "bin"))
(start (point-min))
(end (point-max))
(source-file-point (point))
(legal-buffer (if (buffer-file-name)
"true"
nil))
(jalopy-command
(jde-jalopy-make-arg (jde-jalopy-trim
jde-interactive-jalopy-args))))
(if (get-buffer jalopy-compilation-buffer)
(kill-buffer jalopybuf))
(setq jalopybuf (get-buffer-create jalopy-compilation-buffer))
(copy-to-buffer jalopybuf (point-min) (point-max))
(save-excursion
(set-buffer jalopybuf)
(if legal-buffer
(compilation-mode jalopy-compilation-buffer))
(apply 'call-process-region
start
end
(jde-jalopy-get-java)
t
t
nil
jalopy-command
)
(jde-jalopy-setup-buffer)
(if (not legal-buffer)
(progn
(message "The compiled window might not work correctly, because
the buffer you are trying to beautify is not associated with any
file.")))
)
(goto-char source-file-point)
)
)
)
(defun jde-jalopy-setup-buffer()
"Function that sets up the jalopy buffer."
"If any errors occurred, a seperate compilation window "
"is displayed. Else the current buffers content are replaced "
"by the beautified content."
(let ((jalopy-compilation-ind "Listing on stdin\.\.\.\n\[ERROR\]")
(jalopy-ok-ind "Listing on stdin\.\.\."))
(goto-char (point-min))
(if (search-forward jalopy-compilation-ind nil t) ;;if string was
found, this is a jalopy file with errors
(progn
(forward-line -1)
(beginning-of-line)
(kill-line) ;;kill the containing the jalopy string
(kill-line) ;;kill the containing the jalopy string
(setq jde-display-command)
(setq jalopy-command (reverse jalopy-command))
(while jalopy-command
(setq jde-display-command (concat (car jalopy-command) " "
jde-display-command))
(setq jalopy-command (cdr jalopy-command))
)
(insert-string (concat (jde-jalopy-get-java) " " jde-display-command
"\n\n"))
(replace-string "System.in" source-file-name)
(goto-char (point-min))
(setq buffer-read-only t)
(switch-to-buffer-other-window jalopy-compilation-buffer)
)
(if (search-forward jalopy-ok-ind nil t) ;;if string was found,
this is a jalopy file with NO errors
(progn
(beginning-of-line)
(kill-line) ;;kill the line containing the jalopy string
(kill-line) ;;kill the line containing the jalopy string
(copy-to-buffer source-file-name (point-min) (point-max))
(set-buffer source-file-name)
(kill-buffer jalopy-compilation-buffer)
)
(message "Error occurred") ;;else this is a jalopy file with errors
(switch-to-buffer-other-window jalopy-compilation-buffer)
)
)
)
)