GNU bug report logs - #37436
27.0.50; Function proposal doc-view-open-file

Previous Next

Package: emacs;

Reported by: Jean Louis <bugs <at> gnu.support>

Date: Tue, 17 Sep 2019 06:32:02 UTC

Severity: wishlist

Tags: moreinfo

Found in version 27.0.50

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Jean Louis <bugs <at> gnu.support>
To: 37436 <at> debbugs.gnu.org
Subject: bug#37436: Acknowledgement (27.0.50; Function proposal doc-view-open-file)
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)))))))))





This bug report was last modified 4 years and 83 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.