After using M-x find-grep I have a list of files with position information in a compile buffer. Now I want to visit the files to check, which can be done with <RET>, calling compile-goto-error to switch/open file into buffer at given position. Emphasize on visit, I want to quickly leave the visited buffer by typing q.
I looked into the source of compile-goto-error and added the view-mode line with progn around the (setq compilation-current-error (point)) clueless as I am like this:
(defun my-compile-goto-error (&optional event)
"Visit the source for the error message at point.
Use this command in a compilation log buffer."
(interactive (list last-input-event))
(if event (posn-set-point (event-end event)))
(or (compilation-buffer-p (current-buffer))
(error "Not in a compilation buffer"))
(compilation--ensure-parse (point))
(if (get-text-property (point) 'compilation-directory)
(dired-other-window
(car (get-text-property (point) 'compilation-directory)))
(progn
(setq compilation-current-error (point))
(unless view-mode (view-mode t)))
(next-error-internal)))
However, this works only every second time, with or without the line (unless view-mode (view-mode t))
How can I force compile-goto-error to open source-file in view-mode?