Function: pdf-info-search-regexp

pdf-info-search-regexp is a natively compiled function defined in pdf-info.el.

Signature

(pdf-info-search-regexp PCRE &optional PAGES NO-ERROR FILE-OR-BUFFER)

Documentation

Search for a PCRE on PAGES of document FILE-OR-BUFFER.

See pdf-info-normalize-page-range for valid PAGES formats and pdf-info-search-string for its return value.

Uses the flags in pdf-info-regexp-flags, which see. If case-fold-search is non-nil, the caseless flag is added.

If NO-ERROR is non-nil, catch errors due to invalid regexps and return nil. If it is the symbol invalid-regexp, then re-signal this kind of error as a invalid-regexp error.

Source Code

;; Defined in /nix/store/63h5z2vmzn0mfavcxi2idi23g5xcgkbl-emacs-packages-deps/share/emacs/site-lisp/elpa/pdf-tools-20260102.1101/pdf-info.el
(defun pdf-info-search-regexp (pcre &optional pages
                                    no-error
                                    file-or-buffer)
  "Search for a PCRE on PAGES of document FILE-OR-BUFFER.

See `pdf-info-normalize-page-range' for valid PAGES formats and
`pdf-info-search-string' for its return value.

Uses the flags in `pdf-info-regexp-flags', which see.  If
`case-fold-search' is non-nil, the caseless flag is added.

If NO-ERROR is non-nil, catch errors due to invalid regexps and
return nil.  If it is the symbol `invalid-regexp', then re-signal
this kind of error as a `invalid-regexp' error."

  (cl-labels ((orflags (flags alist)
                (cl-reduce
                 (lambda (v flag)
                   (let ((n
                          (cdr (assq flag alist))))
                     (if n (logior n v) v)))
                 (cons 0 flags))))
    (let ((pages (pdf-info-normalize-page-range pages)))
      (condition-case err
          (pdf-info-query
           'search-regexp
           (pdf-info--normalize-file-or-buffer file-or-buffer)
           (car pages)
           (cdr pages)
           pcre
           (orflags `(,(if case-fold-search
                           'caseless)
                      ,@pdf-info-regexp-flags)
                    (pdf-info-regexp-compile-flags))
           (orflags pdf-info-regexp-flags
                    (pdf-info-regexp-match-flags)))
        (error
         (let ((re
                (concat "\\`epdfinfo: *Invalid *regexp: *"
                        ;; glib error
                        "\\(?:Error while compiling regular expression"
                        " *%s *\\)?\\(.*\\)")))
           (if (or (null no-error)
                   (not (string-match
                         (format re (regexp-quote pcre))
                         (cadr err))))
               (signal (car err) (cdr err))
             (if (eq no-error 'invalid-regexp)
                 (signal 'invalid-regexp
                         (list (match-string 1 (cadr err))))))))))))