0

I want to be asked what string %s I want [0] pdfgrep to search for? While M-x pdfgrep mysearchString works, I'm somehow missing something on wrapping it up as sole function?

(require 'pdfgrep)
(pdfgrep-mode)
(defun myPdfSearch ()
  (interactive)
  (pdfgrep -H -n -i -r %s /home/pdf/))

Symbol’s value as variable is void: -H

[0] https://github.com/jeremy-compostella/pdfgrep
jjk
  • 734
  • 4
  • 18

1 Answers1

2

The pdfgrep function that you call from lisp is not the pdfgrep program that you invoke from the command line, so you have to format the arguments as the function expects. Try:

(defun myPdfSearch (s)
  (interactive "sSearch string: ")
  (pdfgrep (format "pdfgrep -H -n -i -r -e \"%s\" /home/pdf/*.pdf" s)))
)

This is the equivalent of the command line invocation

pdfgrep -H -n -i -r -e "<string>" /home/pdf/*.pdf

It's a good idea to use -e to signal that the next argument is the expression to search for and to quote that expression to protect spaces and metacharacters from tripping up the shell invocation.

AFAICT, pdfgrep requires files as arguments, not directories, so you have to use the glob pattern to pick up all the PDF files in the specified directory.

I also had to load the pdfgrep library and evaluate (pdfgrep-mode) before I could use the above.

NickD
  • 29,717
  • 3
  • 27
  • 44