"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> The other day I was grepping for something and there were commented
> lines in the hits and it occurred to me how easy it would be to
> distinguish these lines visually if the matches were syntax
> highlighted. At least for those files which are already opened with
> emacs.
Nice idea! A slightly different and probably simpler approach is to
copy matched lines directly from their buffers, if available:
(defun grep-fontify ()
(interactive)
(font-lock-mode -1)
(let ((inhibit-read-only t))
(save-excursion
(goto-char (point-min))
(while (not (eobp))
;; naive approach, should use the regexp that compile uses
(if (looking-at "\\(.*?\\):\\(.*?\\):\\(.*\n?\\)")
(let* ((file (match-string-no-properties 1))
(line-number (string-to-number (match-string-no-properties
2)))
(line (match-string-no-properties 3))
(buffer (get-file-buffer file)))
(if buffer
(let (fetched-line)
(with-current-buffer buffer
(save-excursion
(goto-line line-number)
(let ((l (thing-at-point 'line)))
(if (string= l line)
(setq fetched-line l)))))
(when fetched-line
(re-search-forward ".*?:.*?:")
(kill-line)
(if (string= (thing-at-point 'char) "\n")
(delete-char 1))
(save-excursion (insert fetched-line)))))))
(forward-line)))))
To be invoked in the buffer created and returned by "grep".
All the best,
Markus Triska
_______________________________________________
gnu-emacs-sources mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources