3

I use grep-mode for a set of files and wgrep (writable grep buffer) for editing them. The buffer usually looks like:

enter image description here

I want to find a way to change the view like this:

enter image description here

wgrep and compile-goto-error should work as usual.

Upd. It works for wgrep and compile-goto-error now. Additional spaces for regexp are needed:

(setcar (car grep-regexp-alist)
        "^\\(.+?\\)\\(:[ \t]*\\)\\([1-9][0-9]*\\)[ \t]*\\2")

It turns out wgrep-default-line-header-regexp already had required additional spaces.

artscan
  • 445
  • 2
  • 12
  • 2
    This sounds a lot like "Write a package for me." – nispio Jul 04 '16 at 03:15
  • I think it would be made by setting of `grep-regexp-alist` and `wgrep-default-line-header-regexp` and some trick with `align-regexp`. Maybe someone had already done something like that. I've stuck with it a little. – artscan Jul 04 '16 at 03:25
  • I don't understand _why_ you want this, it might help someone come up with a usable answer. Personally, I never even look at the grep output, I just keep using `next-error` and looking at the files themselves. – MAP Jul 05 '16 at 08:03
  • 2
    It is because of `wgrep` (writable grep buffer) is used for in-place editing (like `wdired-mode` for `dired`). – artscan Jul 05 '16 at 08:11

1 Answers1

3

Here is the complete solution:

(setcar (car grep-regexp-alist)
        "^\\(.+?\\)\\(:[ \t]*\\)\\([1-9][0-9]*\\)[ \t]*\\2")

(defun eab/grep-align ()
  (interactive)
  (read-only-mode -1)
  (toggle-truncate-lines 1)
  (save-excursion
    (beginning-of-buffer)
    (compilation-next-error 1)
    (call-interactively 'set-mark-command)
    (end-of-buffer)
    (backward-paragraph)
    (align-regexp (region-beginning) (region-end) "\\(:[0-9]+\\)\\(\\):" 2 1 t))
  (read-only-mode 1))

(defun eab/wgrep-change-to-wgrep-mode ()
  (interactive)
  (eab/grep-align)
  (call-interactively 'wgrep-change-to-wgrep-mode))
artscan
  • 445
  • 2
  • 12