pdfgrep icon indicating copy to clipboard operation
pdfgrep copied to clipboard

Make "next-error" and "previous-error" work when visiting files that contain results of "pdfgrep"

Open rodrigomorales1 opened this issue 3 years ago • 1 comments

The context

Sometimes I execute pdfgrep in multiple PDF files which contain more than 1000 pages. For this reason, I want to save the results in order to visit the search results another day.

Creating the file (let's say, A) that contain the results of pdfgrep is fairly easily since the buffer that shows the results found by pdfgrep inserts a modeline into the buffer which causes Emacs to set grep as the major-mode when revisiting the file A. The code block shown below shows the results of executing M-x pdfgrep in an arbitrary file

-*- mode: grep; default-directory: "~/Experiments/" -*-
Grep started at Thu Nov 12 20:59:07

pdfgrep -H -n -i 'a' ~/Experiments/1.pdf 
/home/beep1560/Experiments/1.pdf:1:    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
...

Grep finished with 64 matches found at Thu Nov 12 20:59:07

The problem

The problem is present when visiting a file that contain the results of pdfgrep. Executing M-g p (previous-error) and M-g n (next-error) show the following message in the minibuffer even when the buffer that shows the stored results of pdfgrep is *pdfgrep*.

Moved past last grep hit
Moved back before first grep hit

Additional context

next-error and previous-error do work when they are executed in the buffer that is immediately opened after executing M-x pdfgrep.

next-error and previous-error also work when visiting a file that contain results of M-x grep. I confirmed by doing the following:

  • Execute grep (i.e. M-x grep) in arbitrary files and save the results in a file with name results.
  • Close the buffer that shows the grep results.
  • Open the file results
  • Execute M-x next-error (i.e. press M-g n) and M-x previous-error (i.e. press M-g p). This caused the cursor to open the file and move the cursor to the line which contained the matching pattern.

The question

Is there any way to make the functions next-error and previous-error work (that is, open the PDF at the page that contain the selected result and don't show a error message in the minibuffer) when visiting a file that shows the results of executing pdfgrep?

rodrigomorales1 avatar Nov 13 '20 02:11 rodrigomorales1