2

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.

  • 2
    This sounds a lot like "Write a package for me." – nispio Jul 4 '16 at 3: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 4 '16 at 3: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 5 '16 at 8:03
  • 2
    It is because of wgrep (writable grep buffer) is used for in-place editing (like wdired-mode for dired). – artscan Jul 5 '16 at 8:11
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))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.