gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

snippet: jump to compilation output errors from shell mode


From: Rob Giardina
Subject: snippet: jump to compilation output errors from shell mode
Date: Tue, 16 Dec 2008 14:43:59 -0800 (PST)
User-agent: G2/1.0

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)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]