Posts Tagged ‘emacs’

Grails 2.0 and emacs shell-mode

Posted in Uncategorized on September 16th, 2011 by ataylor284 – Comments Off on Grails 2.0 and emacs shell-mode

I’ve been testing out Grails 2.0.0.M2 a bit and I really like the reduced clutter in the output.

Emacs shell-mode doesn’t handle the new output style well, though. The control characters grails uses to keep the output on one line are not interpreted properly and get echoed to the buffer. Although ansi-term works, shell-mode provides much better integration with emacs.

Here’s a snippet of elisp to fix it:

(defun grails-comint-magic (string)
  "Handle grails output gracefully."
  (let ((position (process-mark (get-buffer-process (current-buffer)))))
      (goto-char comint-last-output-start)
      (while (re-search-forward "\033\\[1A\033\\[[0-9]+D\033\\[0K" position t)
        (replace-match "" t t)
         (progn (forward-line 1) (point)))))))
(add-hook 'comint-output-filter-functions 'grails-comint-magic)

It simply recognizes the sequence of control characters grails generates and simulates the intent directly with emacs commands.

Throw this in your .emacs and enjoy.