This is helpful when working with any sort of compiler output from the
shell (mostly because the compilation mode is great at parsing error
messages). I no longer use compile commands from emacs but instead run
them from the shell and slurp up the output with this function. It
even works on long log messages with well formatted error line
numbers.

It operates on the output of the last command.

-rob

----8<-----

                                        ;JUMP TO COMPILE ERRORS FROM A
SHELL BUFFER
(defun jump-to-compilation-error-in-shell()
  "From a shell buffer, copy the output of the last
command (make, ant, etc.) to a temporary compilation output
buffer and jump to any errors cited in the output using
`compilation-minor-mode'."
  (interactive)
  (assert (eq major-mode 'shell-mode)
          "Can only process compilation errors from a shell buffer")
  (goto-char (point-max))
  (let* ((end (save-excursion (forward-line 0)(point)))
         (start (save-excursion (comint-previous-prompt 1)(forward-
line 1)(point)))
         (out (get-buffer-create "*shell-compilation-output*"))
         (output (buffer-substring-no-properties start end))
         (shell-window (get-buffer-window (current-buffer) (selected-
frame))))
    (with-current-buffer out
      (erase-buffer)
      (insert "Compilation mode skips the first\n2 lines...\n")
      (setq truncate-lines nil)
      (insert output)
      (compilation-minor-mode 1)
      (goto-char (point-min))
      (display-buffer out shell-window)
      (next-error))))
(global-set-key [(control c)(control ?')] 'jump-to-compilation-error-
in-shell)
_______________________________________________
gnu-emacs-sources mailing list
gnu-emacs-sources@gnu.org
http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources

Reply via email to