Skip to content

Commit a4ca0a1

Browse files
Do not assume that the buffer is `pdfgrep-buffer-name'
If the pdfgrep result is loaded from a file the locus buffer name is not `pdfgrep-buffer-name'. This should help with #3. Signed-off-by: Jeremy Compostella <[email protected]>
1 parent 1576fc9 commit a4ca0a1

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

pdfgrep.el

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,29 @@ the PDFGrep job before it finishes, type \\[kill-compilation]."
8383
(compilation-start command-args 'grep-mode
8484
(lambda (_x) pdfgrep-buffer-name)))
8585

86-
(defun pdfgrep-current-page-and-match ()
86+
(defun pdfgrep-current-page-and-match (buffer)
8787
"Return the current match page number and match string."
88-
(with-current-buffer pdfgrep-buffer-name
88+
(with-current-buffer buffer
8989
(cons (cadr (compilation--message->loc (compilation-next-error 0)))
9090
(let* ((cur (buffer-substring (line-beginning-position)
9191
(line-end-position)))
9292
(start (text-property-any 0 (length cur) 'font-lock-face
9393
'match cur)))
9494
(substring cur start (next-property-change start cur))))))
9595

96-
(defun pdfgrep-goto-locus (_msg _mk _end-mk)
96+
(defun pdfgrep-goto-locus (msg _mk _end-mk)
9797
"Jump to a match corresponding.
98-
_MSG, _MK and _END-MK parameters are ignored. This function is
98+
MSG, _MK and _END-MK parameters are ignored. This function is
9999
used to advice `compilation-goto-locus'."
100-
(when (and (eq major-mode 'doc-view-mode)
101-
(eq doc-view-doc-type 'pdf))
102-
(doc-view-goto-page (car (pdfgrep-current-page-and-match))))
103-
(when (eq major-mode 'pdf-view-mode)
104-
(let ((meta (pdfgrep-current-page-and-match)))
105-
(pdf-view-goto-page (car meta))
106-
(when (cdr meta)
107-
(pdf-isearch-hl-matches nil (pdf-isearch-search-page (cdr meta)) t)))))
100+
(let ((buffer (marker-buffer msg)))
101+
(when (and (eq major-mode 'doc-view-mode)
102+
(eq doc-view-doc-type 'pdf))
103+
(doc-view-goto-page (car (pdfgrep-current-page-and-match buffer))))
104+
(when (eq major-mode 'pdf-view-mode)
105+
(let ((meta (pdfgrep-current-page-and-match buffer)))
106+
(pdf-view-goto-page (car meta))
107+
(when (cdr meta)
108+
(pdf-isearch-hl-matches nil (pdf-isearch-search-page (cdr meta)) t))))))
108109

109110
(define-minor-mode pdfgrep-mode
110111
"Toggle PDFGrep mode.

0 commit comments

Comments
 (0)