Subject: bug#37436: Acknowledgement (27.0.50; Function proposal doc-view-open-file)

From: Jean Louis <[email-masked]>
Date: Tue, 17 Sep 2019 09:04:00 +0200

I have made this function now for me. But such could be improved for
GNU Emacs so that PDF, DJVU and other doc view file could be opened
straight from Emacs Lisp and at the specific page number for specific
query, even query number could be implemented.

(defun doc-view-open-file (file &optional page-number query match)
  "Opens PDF file in GNU Emacs at specific page number or at
specific match"
  (let* ((allowed-extensions '("pdf" "djvu" "dvi"))
	 (file-ext (file-name-extension file))
	 (match (if match match 0)))
    (when (and (file-exists-p file)
	       (seq-contains allowed-extensions file-ext 'equalp))
      (setq doc-view--current-search-matches nil)
      (let ((created (create-file-buffer file))
	    (buffer (get-file-buffer file)))
	(switch-to-buffer created)
	(set-visited-file-name file )
	(insert file)
	(doc-view-mode)
	(when page-number
	  (doc-view-goto-page page-number))
	(when query
	  (let ((txt (expand-file-name "doc.txt"
				       (doc-view--current-cache-dir))))
	    (if (file-readable-p txt)
		(progn
		  (setq doc-view--current-search-matches
			(doc-view-search-internal query txt))
		  (doc-view-search-next-match match)))))))))